본문으로 건너뛰기

3.5. Semantic API

This document describes the method and setting information for deploying Semantic API.

3.5.1. Overview

Semantic REST API, as a solution to improve accessibility between semantic and non-semantic environments. To achieve easier interpretation, eight basic functionalities along with their respective resource description has been defined for the retrieval and traversal of semantic data.

The “APIConfiguration.java” class contains one variable called “PREFIX_URI”, which defines the namespace URI to be used for defining all the concepts in the OWL Ontology model. This can be changed according to preference.

3.5.2. API Description

Following is the list of API functionalities and their brief description.

Table 1. API Functions

#NameDescription
1.Graph ListGet the list of graphs URI. Every set of graph data is stored in graphs, having unique graph URI. The ontologies are also stored as graphs in the TDB. This Request will get the list of those graphs URIs.
2.Entity ListGet the list of entity URIs where an entity can be one of following type: {Class, ObjectProperty, DataProperty, NamedIndividual, …}
3.Entity InfoGet the info of the given entity URI {Class, NamedIndividual, Object Property, Data Property}. i.e. Provide details of its type and properties {domains, ranges, subsumption, comment, …. }
4.Class -HierarchyGet the Class hierarchy of Class/Individual up to “n-level”, from child class to parent class.
5.Graph InfoGet the set of all triples of given graph URI.
6.Individual ListGet the URI list of all the Individuals of the given type.

Table 2 describes the Request parameters for each API call.

Table 3-11 define the resource types. Here multiplicity defines the multiplicity of “values” of their properties. So, usually the properties having “List” can have the greater than 1 multiplicity.

Table 3. Resource description for sem:graphList

propertydatatypemultiplicityDescription
prefixListsem:prefixListSimple or sem:prefixListNormal0..nList of prefixes for the URIs / IRIs used in the resource. Format type can be suggested by the prefixFormat query parameter (allowed values: simple, normal)
graphListURI0…nList of graph URIs, starting with {prefix}, followed by : followed by graphID.

Table 4. Resource description for sem:entityList

propertydatatypemultiplicityDescription
prefixListsem:prefixListSimple or sem:prefixListNormal0..nList of prefixes for the URIs / IRIs used in the resource. Format type can be suggested by the prefixFormat query parameter (allowed values: simple, normal)
entityListURI0…nList of entity URIs, starting with {prefix}, followed by : followed by entityID.

Table 5. Resource description for sem:entityInfo

propertydatatypemultiplicityDescription
prefixListsem:prefixListSimple or sem:prefixListNormal0..nList of prefixes for the URIs / IRIs used in the resource. Format type can be suggested by the prefixFormat query parameter (allowed values: simple, normal)
entityDescriptionsem:tripleInfoSimple or sem:tripleInfoNormal0…nThe value of this property will be the list of triples. Format type can be suggested by the descriptionFormat request parameter (allowed values: simple, normal)

Table 6. Resrouce description for sem:graphInfo

propertydatatypemultiplicityDescription
prefixListsem:prefixListSimple or sem:prefixListNormal0..nList of prefixes for the URIs / IRIs used in the resource. Format type can be suggested by the prefixFormat query parameter (allowed values: simple, normal)
graphDescriptionsem:tripleInfoNormal0…nThe value of this property will be the list of triples. Format type can be suggested by the descriptionFormat request parameter (allowed values: simple, normal)

Table 7. Resource description for sem:individualList

propertydatatypemultiplicityDescription
prefixListsem:prefixListSimple or sem:prefixListNormal0..nList of prefixes for the URIs / IRIs used in the resource. Format type can be suggested by the prefixFormat request parameter (allowed values: simple, normal)
individualListURI0…nList of individual URIs, starting with {prefix}, followed by : followed by individualID.

Table 8. Resource description for sem:prefixListSimple

propertydatatypemultiplicityDescription
{prefix}URI1value for this property shall be the namespace IRI

Table 9. Resource description for sem:prefixListNormal

propertydatatypemultiplicityDescription
prefixstring1value for this property shall prefix name
namespaceIRIURI1value for this property shall be the namespace IRI

Table 10. Resource description for sem:tripleInfoSimple

propertydatatypemultiplicityDescription
{predicate}URI or plain literal or typed literal1…nvalue for this property shall be a list of objects, defining different triples, having same subject and predicate.

Table 11. Resource description for sem:tripleInfoNormal

propertydatatypemultiplicityDescription
subjectURI1value for this property shall subject of the triple. Value will start with {prefix}, followed by : followed by entityID.
predicateURI1value for this property shall be the predicated or the triple Value will start with {prefix}, followed by : followed by entityID.
objectURI or plain literal or typed literal1Value for this property shall object of the triple. In case of URI, value will start with {prefix}, followed by : followed by entityID.

3.5.3. API Usage Examples

Following tables 12-26 show the examples for each API call as well as their corresponding example responses. Table 29 shows the prefixes and their namespaces defined statically in the API. Currently, the API does not have the mechanism for managing prefixes, which is the scope for future work.

Table 12. Request example for API function 1. Graph List

Request
GEThttp://www.city-hub.kr/semantics/v1/graphs?graphType=ontology&keyword=parking,air-quality&limit=10&prefixFormat=simple

Table 13. Response example for API function 1. Graph List with resource sem:prefixListSimple

Table 14. Response example for API function 1. Graph List with resource sem:prefixListNormal

Table 15. Request example for API function 2. Entity List

Request
GEThttp://www.city-hub.kr/semantics/v1/entities?keyword=parkinglot,parkingspot,longitude&entityType=owl:NamedIndividual,parking:ParkingLot,parking:ParkingSpot,owl:DatatypeProperty&limit=10

Table 16. Response example for API function 2. Entity List

Table 17. Request example for API function 3. Entity Info with responseType=normal

Request
GEThttp://www.city-hub.kr/semantics/v1/entities/parking:ParkingLot_yt_lot_1&limit=100&rseponseType=normal

Table 18. Response example for API function 3. Entity Info with resource sem:tripleInfoNormal

Table 19. Request example for API function 3. Entity Info with responseType=simple

Request
GEThttp://www.city-hub.kr/semantics/v1/entities/parking:ParkingLot_yt_lot_1&limit=100&rseponseType=simple

Table 20. Response example for API function 3. Entity Info with resource sem:tripleInfoSimple

Table 21. Request example for API function 4. Class Hierarchy

Request
GEThttp://www.city-hub.kr/semantics/v1/classhierarchy/parking:ParkingLot&limit=100

Table 22. Response example for API function 4. Class Hierarchy

Table 23. Request example for API function 5. Graph Info

Request
GEThttp://www.city-hub.kr/semantics/v1/graphs/parking:parkinglot_yt_lot_1?limit=100

Table 24. Response example for API function 5. Graph Info

Table 25. Request example for API function 6. Individual List

Request
GEThttp://www.city-hub.kr/semantics/v1/individuals http://www.city-hub.kr/semantics/v1/individuals?classId=parking:Parkinglot, parking:ParkingSpot&limit=10

Table 26. Response example for API function 6. Individual List

Table 27. Predefined (static) prefix list in API

Prefix (short form)Prefix (full form)
commonhttp://www.city-hub.kr/ontologies/2019/1/common
parkinghttp://www.city-hub.kr/ontologies/2019/1/parking
weatherhttp://www.city-hub.kr/ontologies/2019/1/weather
air-qualityhttp://www.city-hub.kr/ontologies/2019/1/air-quality
timehttp://www.w3.org/2006/time
sarefhttps://w3id.org/saref
rdfhttp://www.w3.org/1999/02/22-rdf-syntax-ns
rdfshttp://www.w3.org/2000/01/rdf-schema
owlhttp://www.w3.org/2002/07/owl
xsdhttp://www.w3.org/2001/XMLSchema
xmlhttp://www.w3.org/XML/1998/namespace

3.5.4 Pre-Installation

Semantic API is a Java Maven project, developed using Java Spring Boot. The project can be imported and executed in compatible java IDE such as Eclipse and IntelliJ. Following are the dependencies required for deployment.

3.5.4.1 Dependencies

  • Minimum version of Java Required: 1.5.
  • Maven Dependencies: These are listed under <dependencies> tab in “pom.xml”, in main project directory.
    • spring-boot-starter-web (version 1.4.1)
    • jakarta.xml.bind-api (version 2.3.2)
    • jaxb-runtime (version 2.3.2)
    • apache-jena-libs (version: 3.9.0)
    • owlapi-distribution (version 5.1.16)
    • json-simple (version 1.1.1)
    • gson (version 2.8.6)
  • External Jar Files: These files are not available in maven repository and may need to add in the build path manually. These can be found in project/lib/
    • virt_jena3.jar
    • virtjdbc4.jar
  • Connection with Virtuoso Triple Store: Three parameters are required to connect to the virtuoso: host URL, user name and password.
  • It is required that the triple store is already populated with ontologies (vocabularies), so that Semantic API can handle certain Requests, such as GET Class Hierarchy, appropriately.
  • There are static number of prefixes defined in the API (can be found in PrefixRepository.java class). Any newly defined prefix should be added appropriately.

3.5.4.2 ServerConfiguration

  • The file is located at project/src/java/com/cityhub/semantic/ServerConfiguration.java, where following parameters can be configured:
PropertySampleDescription
API_BASE_URLsemantic/api/v1Parameter to set Semantic API's base URL. This can be changed based on preference
TDB_BASE_URLjdbc:virtuoso://localhost:1111Parameter to set host URL. This default value is set for localhost. However it can be changed based on the specific ip address of the deployed TDB
TDB_USERdbaDefault user name for virtuoso TDB. However, different user can be provided if created in virtuoso with appropriate permissions.
TDB_PASSdbaDefault user password for virtuoso TDB. However, different user information can be provided if created in virtuoso with appropriate permissions.
ACP_BASE_URL<must be defined>This is the URL for the server handling Access Control Policy functions. There is no default value. It must be provided for proper Access Control Functionality.

3.5.4.3 Important File Directories

  • Following are the important directories for Semantic Validator.
    • Project java code files : project/src/java/com/cityhub/semantic/
    • External Jar files : project/lib
    • Maven Dependencies : project/pom.xml

3.5.5 Deployment Steps

NOTE: the installation instructions are based on Eclipse IDE in Windows, so it may vary for different IDEs and platforms.

3.5.5.1 Download Project

Download the project from github and choose "semantic REST API"

3.5.5.2 Import Project in IDE

  • In Eclipse, Go to File>Import>Maven>Existing Maven Projects

  • Locate the downloaded project and import.

3.5.5.3 Add external Jar dependencies

  • The external jars to be added are located in the project at project/lib. If they are not already added, then must be added manually.
  • In Eclipse, right click on project folder, go to Build Path > Configure Build Path > Java Build Path. Then go under the Libraries tab, which shows the current jars added to the build path.
  • On the right side click “Add External Jars”.
  • Locate the lib directory and select the files inside.
  • Click “Apply and Close”

3.5.5.4 Application Deployment

NOTE: The TDB and ACP Server must be running prior to the execution of this Application.

After all the required dependencies have been installed, the application can be executed using ServerApplication.java class located at project/src/java/com/cityhub/semantic/ServerApplication.java:

  • Right click on ServerApplication.java, select "Run As", select either "Java Application" or "Spring Boot App".
  • Upon execution, standard Spring Boot execution can be seen on the Eclipse Console.
  • After the information is displayed: "...Started ServerApplication in 2.886 seconds ...", the console will stop displaying further information and the API is online to provide RESTful services.