본문으로 건너뛰기

3.8. Semantic Reasoner

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

NOTE: It is not a standalone application, rather it is a project which can be used as a component in Semantic Labeling Tool.

3.8.1. Overview

Semantic Reasoner is a Java Maven project which can be imported and executed in compatible java IDE such as Eclipse and IntelliJ. Following are the dependencies required for deployment.

3.8.1.1. Dependencies

  • Minimum version of Java Required: 1.5.

  • Maven Dependencies: These are listed under <dependencies> tab in “pom.xml”, in main project directory.

    • apache-jena-libs (version: 3.9.0)
    • owlapi-distribution (version: 3.4.9.2-ansell)
    • pellet-owlapiv3 (version: 2.3.3)
    • json-simple (version 1.1.1)
    • gson (version 2.8.6)
    • lombok (version 1.16.6)
    • commons-lang3 (version 3.0)
    • hibernate-core (version 5.5.8.Final)
  • 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: API base URI, prefix URI and SWRL prefix.

3.8.1.2. APIConfiguration

  • The file is located at project/src/main/java/semantics/cityhub/keti/APIConfiguration.java, which can also be found in SWRL Rule API.
    • The parameters are described as follows:
PropertySampleDescription
API_BASE_URIapi/axiom-generator/v1Parameter to set API base URL. This is required for the SWRL Labeling Tool. It can be changed based on specific preferences
PREFIX_URIhttp://www.city-hub.kr/swrl/2021/1Default prefix URI to be used in defining SWRL concepts. It can be changed based on specific preferences.
SWRL_PREFIXhttp://swrl.stanford.edu/ontologies/3.3/swrla.owlDefault SWRL prefix to be used for SWRL concept definitions.

3.8.1.3. Important File Directories

  • Following are the important directories for Semantic Validator.
    • Project java code files : project/src/main/java/semantics/cityhub/keti
    • Java code to define SWRL Entity Models: project/src/main/java/semantics/cityhub/keti/model
    • Reasoner java code files: project/src/main/java/semantics/cityhub/keti/reasoner
    • Additional Utility code files: project/src/main/java/semantics/cityhub/keti/utils
    • External Jar files : project/lib
    • Maven Dependencies : project/pom.xml

3.8.2. Deployment Steps

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

3.8.2.1. Download Project

Download the project from github and choose "semanticReasoner2021"

3.8.2.2. Import Project in IDE

  • In Eclipse, Go to File>Import>Maven>Existing Maven Projects
  • Locate the downloaded project and import.

3.8.2.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.8.2.4. Application Deployment

The class SemanticReasoner.java can be used to get SWRL Rules components in JSON format, from the API, from which it generates SWRL Rules as an Ontology Model and stores it in the database (which is MySQL for this implementation). Furthermore, upon receiving the un-labeled dataset in csv format, the application retrieves the stored SWRL rule from the database and then generates labels by applying the SWRL on the csv data using inference engine. SemanticReasoner.java has three main functions: composeModel(Map<String, Object> json_modelValues ), composeModel(SWRLRuleEntity rule_Entity), performInferencing().

  • Constructor: SemanticReasoner(): Initializes the OntologyModeler object, which is used to generate SWRL rules as Ontology Model.
  • composeModel(Map<String, Object> json_modelValues ): This composes OntologyModel from JSON payload send by the API Controller. The created model will be stored by the OntologyModeler. Therefore, instance of this class can be used to retrieve the OntologyModel if required.
  • composeModel(SWRLRuleEntity rule_Entity): This function is used to Compose OntologyModel from SWRLRuleEntity object which represents the Entity in the SQL dataset.
  • performInferencing(): This funciton will perform the inferencing task on the data input through the BufferedReader object (CSV format). The fucntion will return the CSVHandler object to export the response in CSV format by the API.
  • exportRuleEntity() : This fucntion is used to export Ontology Model to SWRLRuleEntity object which is then used to save in the database.
  • getOntologyModel() : This function is used to retrieve the Ontology Model from OntologyModeler class instance.

NOTE: The usage of this project can also be realized from the SWRL Rule API, where this project is deployed as a component.

3.8.3. Usages

Semantic Reasoner module is the core component of Semantic Labeling tool, which is responsible for composing the Ontology as well as performing inference to generate the labels for the machine learning dataset.

3.8.3.1. Manages

Semantic Reasoner is Maven Java Project. Following are the prerequisites for utilizing this component.

  • Java Runtime Environment (JRE/JDK)

  • IDE for Editing and execution (Eclipse, IntelliJ, etc)

Other required dependencies are specified in the pom.xml file. In addition two external libraries (JAR) which are used, are included in the “lib” folder. These two libraries have also been specified in pom.xml.

The main functionalities have been defined in the package “semantics.cityhub.keti.reasoner”. In that package the class “SemanticReasoner.java” is the main executable class. Although it has been defined as a main executable class, it does not perform any functionalities upon execution. This is because this project has been considered as an internal component of “Semantic Labeling API”.

3.8.3.1.1. Utilization of SemanticReasoner.java

SemanticReasoner.java defines five main functions to be utilized. Two of them are overridden methods with name “composeModel”. They are responsible of composing the OWL Ontology model based on rule data. One method accepts the rule data in JSON format and parses it as type “java.util.Map”. Figure 5 shows the example input rule data. Here the “id” is to uniquely identify the rule data “dataProperties” is the list of OWL Data Properties used in the rule. “variables” is the list of Variables defined in the rule, and “rule” defines the rule string.

The second method accepts the rule data as the object of “SWRLRuleEntity.java”, defined in the package “semantics.cityhub.keti.model”. This class has same data attributes, but all of them have the data type “Clob”. In case of list, the list elements are stored as comma (,) separated elements in the string value. There is nothing to return as the methods stores the composed model in-memory.

After composing the OWL Ontology Model, Inferencing can be performed on the dataset using “performInferencing” method, which takes “java.io.BufferedReader” as input which will be the considered input in “text/CSV” format. Figure 6 shows the example dataset based on the example rule defined in figure 5. In this example, the data contains only single column. The first row defined the independent variable, which is equivalent to OWL Data Property defined in the rule. Second row defines the datatype and rest of the rows define the data values.

The returned object by “performInferencing” method, is of type “CSVHandler.java” defined in “semantics.cityhub.keti.utils”. This object can be used to write the CSV output using method “writeDatasetToCSV”. This methods takes “java.io.Writer” as input and prints the data. Figure 7 shows the example output in “text/CSV” format.

The other two methods are “exportRuleEntity” and “getOntologyModel”. Both methods return the rule data, however, “exportRuleEntity” returns the data as object of “SWRLRuleEntity.java” and “getOntologyModel” returns the data as the object of “OntologyModel.java” class, which is defined in “semantics.cityhub.keti.reasoner”. This class stores the rule data as “org.semanticweb.owlapi.model.OWLOntology” on which semantic inference can be applied.

3.8.3.1.2. Using SemanticReasoner.java as a Wrapper class

The “SemanticReasoner.java” can be used as a Wrapper class to execute the Reasoner functionalities. In this case the function calls defined in “SemanticReasoner.java”, can be then be executed as per requirement and configuration as well as user application’s preference. In this way, this program can work as a component of an application covering Reasoner functionalities for a larger scope of application domain.