Intro

Welcome to the Core APIs User Guide, contained is an in-depth set of instructions to fully set up, configure, and trigger the product so you can start your Knowledge Graph exploration. The Core APIs is a collection of tools providing the ability to easily perform complex queries, analysis, and traversal against any Knowledge Graph, for use by any developer even with no prior Knowledge Graph experience. It can even be used for building user interfaces or as a basis for integration with other services in your architecture. The Core APIs is a lightweight, platform-agnostic tool with support for all common Knowledge Graphs using W3C Semantic Web Standards SPARQL 1.1 query language.

 


Contents

 

 


 

Configuring the Core APIs

The Core APIs has been designed to be entirely configurable through the use of Environment Variables. How to declare these environment variables will differ slightly depending on how you choose to run the product, which will be covered in the subsequent sections. As for the configuration variables themselves, they are all straight forward and easy to understand.

Knowledge Graph Configuration

The first configuration options are concerning the Knowledge Graph you wish to query and traverse.

  • The Triplestore Endpoint <TRIPLESTORE_ENDPOINT> is the endpoint for your Triple Store that you want the Core APIs to connect to.

  • The Triplestore Type <TRIPLESTORE_TYPE> is the type of your Triple Store. The Core APIs support for all common Knowledge Graphs, some graphs will support the default sparql type (e.g. AllegroGraph), however certain graphs require specific type declaration, these include neptune, rdfox, graphdb, stardog, and blazegraph.

  • If your triplestore has authentication, the Triplestore Username <TRIPLESTORE_USERNAME> is the username for your Triple Store. This option may be left blank if authentication is not required.

  • As with the username, the Triplestore Password <TRIPLESTORE_PASSWORD> is the password for your Triple Store. This can also be left blank if authentication is not required.

Core APIs Configuration

These next configuration options are involved with the running of the Core APIs itself.

  • The Core APIs Username <CORE_API_USER> and Password <CORE_API_PASSWORD> are credentials you can provide to make the product require authentication when being triggered.

 


 

Running the Core APIs

The Core APIs, similar to the Lenses of Data Lens, is designed and built to be versatile, allowing them to be set up and ran on a number of environments, including in cloud or on-premise. This is achieved through the use of Docker Containers. In addition to this, we now have full support for the Amazon Web Services Marketplace, where you can directly subscribe to and run your Core APIs container from.

Running via AWS Marketplace

As previously mentioned, we now have full support for the Amazon Web Services Marketplace, this being the most straight forward way to get started with the Core APIs. Using our CloudFormation Templates linked to the provided Quick Create Stack, you can deploy a one-click solution to run the product.

This Quick Create Stack will start up an ECS Cluster with all the required permissions and networking, with the Core APIs running within as a task. All that is required is that you provide the configuration variables as described in the previous section, then once complete, click on the Create Stack button.

 

Running via a Docker Image on AWS

In addition to the preconfigured stack created by the CloudFormation template, you also have the ability to run the Core APIs in your own new or existing AWS environment.

  1. To do this first ensure you have an AWS ECS Cluster running, please ensure that it is in the same VPC as your Knowledge Graph if it is also running in AWS.

  2. Next, you must create a Task Definition containing the Core APIs container image.

    1. This is done by selecting the Create New Task Definition button selecting a Launch Type Compatibility of either FARGATE or EC2.

    2. Next, provide the task with a name and create an IAM Task Role that grants permission for your container to call RegisterUsage, as defined in the following code. You must supply this IAM role in the Task Role parameter of the Amazon ECS task or Amazon EKS pod definition.

      1 2 3 4 5 6 7 8 9 10 11 12 { "Version": "2012-10-17", "Statement": [ { "Action": [ "aws-marketplace:RegisterUsage" ], "Effect": "Allow", "Resource": "*" } ] }

       

    3. Then add the container, this is where you specify the Docker Container image location, along with exposed ports and environment variables. To retrieve the image URI, select the View Container Image Details link on the Core API’s Marketplace Product Launch page. For the port mappings, provide the values of 8080 for both host and container ports, then for the environment variables, provide them as explained in the configuration section about and as shown in the image below. In addition, it is recommended you enable logging by checking the Auto-configure CloudWatch Logs box.

       

    4. Now that the Task Definition has been created, you may start the new task from within your ECS cluster.

 

Running via a Local On-Prem Docker Image

If you wish to run the Core APIs locally on-prem, first please ensure you have Docker installed, and contact us for access to the image and a production license. Then simply by running a command with the following structure, docker will start the container and run the Core APIs from your downloaded image.

For UNIX based machines (macOS and Linux):

1 2 3 4 5 6 7 8 9 10 11 docker run \ --env TRIPLESTORE_ENDPOINT=https://database-1.abcdefghijkl.us-east-1.neptune.amazonaws.com:8182 \ --env TRIPLESTORE_TYPE=neptune \ --env TRIPLESTORE_USERNAME=user \ --env TRIPLESTORE_PASSWORD=pass \ --env CORE_API_USER=$API_USER \ --env CORE_API_PASSWORD=$API_PASS \ --env CORE_API_LOGGER_REGEX=/usr/local/tomcat/logs/*.* \ --env CORE_API_LOGGER_TEST_FILEPATH=/usr/local/tomcat/logs/catalina.out \ -p 8080:8080 \ core-apis

For Windows

1 2 3 4 5 6 7 8 9 10 11 docker run ^ --env TRIPLESTORE_ENDPOINT=https://database-1.abcdefghijkl.us-east-1.neptune.amazonaws.com:8182 ^ --env TRIPLESTORE_TYPE=neptune ^ --env TRIPLESTORE_USERNAME=user ^ --env TRIPLESTORE_PASSWORD=pass ^ --env CORE_API_USER=%API_USER% ^ --env CORE_API_PASSWORD=%API_PASS% ^ --env CORE_API_LOGGER_REGEX=/usr/local/tomcat/logs/*.* ^ --env CORE_API_LOGGER_TEST_FILEPATH=/usr/local/tomcat/logs/catalina.out ^ -p 8080:8080 ^ core-apis

The above examples demonstrate how to override configuration options using environment variables in your Core APIs Container. Lines 6 and 7 show the use of passing in an environment variable saved to the machine, this can be helpful if you do not want credentials in the terminal history. Whereas lines 2-5 simply show string values being passed into the container. Given the Core APIs is ran on port 8080, line 10 exposes and binds that port of the host machine so that the APIs can be triggered. Lines 8 and 9 are additional configuration options for logging that can be set to be the same as above. And finally, line 9 is the name and version of the Docker image you wish to run.

For more information of running Docker Images, see the official Docs.

 


 

Calling the Core APIs

The Core APIs is a collection of tools providing the ability to easily perform complex queries, analysis, and traversal against any Knowledge Graph. These tools are split up into separate APIs within the Core APIs, all of which can be triggered via an exposed endpoint and by providing the necessary query parameters and authentication headers.

Retrieving the address of your stack varies depending on how you setup the Core APIs. If spun up using the CloudFormation template on AWS Marketplace, then the address can be found in the Outputs tab of the CloudFormation Stacks Console. If spun up manually in AWS ECS, then you can access the ip address via Core APIs Task running within the Cluster, ensure to include the port 8080. And if spun up locally, then the http://localhost:8080 address can be used.

To test your target address as well as the health of your Core APIs stack, you can called a GET request on <core-apis-address>/register-usage/actuator/health.

To use the Core APIs, the components are as follows:

 

Collection API

The Collection API allows a user to retrieve a list of any class type from your Knowledge Graph, also with support for powerful filtering. 

URL

/collection

Params

type (URI - required)

joinPredicate (URI - optional) - joinPredicate can be any SPARQL predicate (e.g. ^(ex:pred_1/ex:pred_2*) )

joinValue (URI - optional)

limit (INTEGER - optional)

If URL parameters are URI's, remember to escape in case of special characters, e.g.http://beta.bl.uk#Collection -> http%3A%2F%2Fbeta.bl.uk%23Collection

Supported Verbs

GET

Authorisation

Basic Auth with username and password as specified in the Core APIs environment variables

Accept Headers

application/ld+json (recommended)

application/json

text/turtle

Sample Request

List British Library Collections

Request

1 GET http://localhost:8080/collection?type=http://beta.bl.uk%23Collection

Response

200 OK 

application/json

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 [   {     "type": "http://beta.bl.uk#Collection",     "resource": "http://beta.bl.uk/thing/0c4a4f1a-2ff2-41bb-9ad3-5c6729b08b1f",     "label": "Fiebig Collection"   },   {     "type": "http://beta.bl.uk#Collection",     "resource": "http://beta.bl.uk/thing/a7a74cb3-3eb2-4075-84ae-2bb9fec820e8",     "label": "India Office Records"   },   {     "type": "http://beta.bl.uk#Collection",     "resource": "http://beta.bl.uk/thing/6a565099-9b62-455f-8210-757d4dfceb87",     "label": "Asia, Pacific and Africa Collections"   } ]

 

Resource API

The Resource API allows a user to retrieve every edge and value connected to a specific node in your Knowledge Graph.

URL

/resource

Params

resource

or

resources - Instead of resource, it is possible to pass the parameter resources, to be interpreted as a comma-separated list of resources. In this case the returned json will include properties grouped by resource.

Supported Verbs

GET

Authorisation

Basic Auth with username and password as specified in the Core APIs environment variables

Accept Headers

application/ld+json (recommended)

application/json

text/turtle

Sample Request

Get information about the British Library item "Garden and zenana, Calcutta"

Request

1 GET http://localhost:8080/resource?resource=http://beta.bl.uk/thing/6b32c66b-1c67-437e-b1d8-a6f379d81879

Response

200 OK 

application/json

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 {   "http://beta.bl.uk#ddcNumber": [     "954"   ],   "http://beta.bl.uk#keywords": [     "Anglo-Indian architecture, hand-coloured prints, private houses, salt prints, zenanas"   ],   "http://beta.bl.uk#desc": [     "View looking across the garden towards the European-style house. The zenana, or women&#39;s living quarters, is contained in the single-storey pavilion in the foreground."   ],   "http://beta.bl.uk#title": [     "Garden and zenana, Calcutta"   ],   "http://beta.bl.uk#subtitle": [     "A hand-coloured print from the Fiebig Collection: Views of Calcutta and Surrounding Districts, taken by Frederick Fiebig in 1851."   ],   "http://beta.bl.uk#bl_uri": [     "http://www.bl.uk/onlinegallery/onlineex/apac/photocoll/n/019pho0000247s4u00045000.html"   ],   "http://beta.bl.uk#depDBP": [     "http://dbpedia.org/page/Zenana"   ],   "http://beta.bl.uk#ddcClass": [     "954 General history of Asia; South Asia; India"   ],   "http://beta.bl.uk#blPub": [     "The British Library"   ],   "http://beta.bl.uk#uid": [     "019PHO0000247S4U00045000"   ],   "http://www.w3.org/2000/01/rdf-schema#label": [     "Garden and zenana, Calcutta"   ],   "http://beta.bl.uk#genre": [     "Photograph"   ],   "http://www.w3.org/1999/02/22-rdf-syntax-ns#type": [     "http://www.w3.org/2002/07/owl#Thing",     "http://beta.bl.uk#Item"   ] }

 

Path API

The Path API allows a user to find the shortest path between two nodes in your Knowledge Graph, either directly or via a specified third node.

Title

Get the shortest path between two nodes

URL

/path

Params

startNode (String - required)

endNode (String - required)

Supported Verbs

GET

Authorisation

Basic Auth with username and password as specified in the Core APIs environment variables

Accept Headers

application/ld+json (recommended)

application/json

text/turtle

Sample Request

Show the shortest paths between the two nodes <urn:7> and <urn:5>.

Request

1 GET http://localhost:8080/path?startNode=urn:7&endNode=urn:5

Response

200 OK

application/json

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 [     [         {             "subject": {                 "label": null,                 "typeURI": null,                 "uri": "urn:7"             },             "predicate": {                 "label": null,                 "typeURI": null,                 "uri": "urn:I"             },             "object": {                 "label": null,                 "typeURI": null,                 "uri": "urn:9"             }         },         {             "subject": {                 "label": null,                 "typeURI": null,                 "uri": "urn:9"             },             "predicate": {                 "label": null,                 "typeURI": null,                 "uri": "urn:J"             },             "object": {                 "label": null,                 "typeURI": null,                 "uri": "urn:8"             }         },         {             "subject": {                 "label": null,                 "typeURI": null,                 "uri": "urn:8"             },             "predicate": {                 "label": null,                 "typeURI": null,                 "uri": "urn:Linv"             },             "object": {                 "label": null,                 "typeURI": null,                 "uri": "urn:5"             }         }     ] ]

 

Title

Get shortest paths between two nodes via a given third node

URL

/path/via

Params

startNode (String - required)

endNode (String - required)

via (String - required)

Supported Verbs

GET

Authorisation

Basic Auth with username and password as specified in the Core APIs environment variables

Accept Headers

application/ld+json (recommended)

application/json

text/turtle

Sample Request

Show the shortest paths between the two nodes <urn:7> and <urn:5> which pass through a third node <urn:3>.

Request

1 GET http://localhost:8080/path/via?startNode=urn:7&endNode=urn:5&via=urn:3

Response

200 OK

application/json

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 [     [         {             "subject": {                 "label": null,                 "typeURI": null,                 "uri": "urn:7"             },             "predicate": {                 "label": null,                 "typeURI": null,                 "uri": "urn:Einv"             },             "object": {                 "label": null,                 "typeURI": null,                 "uri": "urn:3"             }         },         {             "subject": {                 "label": null,                 "typeURI": null,                 "uri": "urn:3"             },             "predicate": {                 "label": null,                 "typeURI": null,                 "uri": "urn:D"             },             "object": {                 "label": null,                 "typeURI": null,                 "uri": "urn:6"             }         },         {             "subject": {                 "label": null,                 "typeURI": null,                 "uri": "urn:6"             },             "predicate": {                 "label": null,                 "typeURI": null,                 "uri": "urn:G"             },             "object": {                 "label": null,                 "typeURI": null,                 "uri": "urn:8"             }         },         {             "subject": {                 "label": null,                 "typeURI": null,                 "uri": "urn:8"             },             "predicate": {                 "label": null,                 "typeURI": null,                 "uri": "urn:Linv"             },             "object": {                 "label": null,                 "typeURI": null,                 "uri": "urn:5"             }         }     ],     [         {             "subject": {                 "label": null,                 "typeURI": null,                 "uri": "urn:7"             },             "predicate": {                 "label": null,                 "typeURI": null,                 "uri": "urn:Einv"             },             "object": {                 "label": null,                 "typeURI": null,                 "uri": "urn:3"             }         },         {             "subject": {                 "label": null,                 "typeURI": null,                 "uri": "urn:3"             },             "predicate": {                 "label": null,                 "typeURI": null,                 "uri": "urn:Binv"             },             "object": {                 "label": null,                 "typeURI": null,                 "uri": "urn:1"             }         },         {             "subject": {                 "label": null,                 "typeURI": null,                 "uri": "urn:1"             },             "predicate": {                 "label": null,                 "typeURI": null,                 "uri": "urn:A"             },             "object": {                 "label": null,                 "typeURI": null,                 "uri": "urn:2"             }         },         {             "subject": {                 "label": null,                 "typeURI": null,                 "uri": "urn:2"             },             "predicate": {                 "label": null,                 "typeURI": null,                 "uri": "urn:C"             },             "object": {                 "label": null,                 "typeURI": null,                 "uri": "urn:5"             }         }     ] ]



Suggest API

The Suggest API allows the user to find nodes by their label within your Knowledge Graph, also with support for powerful type filtering.

URL

/suggest

Params

query (String - required)

filter (String - optional)

Supported Verbs

GET

Authorisation

Basic Auth with username and password as specified in the Core APIs environment variables

Accept Headers

application/ld+json (recommended)

application/json

text/turtle

Sample Request

List organisations with labels beginning with "sky"

Request

1 GET http://localhost:8080/suggest?query=sky&filter=http://dowjones/ont/organisation

Response

200 OK 

application/json

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 [   {     "type": "http://dowjones/ont/organisation",     "resource": "http://dowjones/resource/0c4a4f1a-2ff2-41bb-9ad3-5c6729b08b1f",     "label": "Sky Climber Inc"   },   {     "type": "http://dowjones/ont/organisation",     "resource": "http://dowjones/resource/a7a74cb3-3eb2-4075-84ae-2bb9fec820e8",     "label": "Sky Dancer Inc"   },   {     "type": "http://dowjones/ont/organisation",     "resource": "http://dowjones/resource/6a565099-9b62-455f-8210-757d4dfceb87",     "label": "Sky Dynamics Corp"   } ]