Java API - ge-semtk/semtk GitHub Wiki

SemTK Java API

The sparqlGraphLibrary jar contains the SemTK core code, including Java clients to call SemTK REST Services.

The jar will be named like this: sparqlGraphLibrary-X.X.X-SNAPSHOT.jar, and may be found:

  1. in a Maven Central Release, or
  2. as a snapshot jar on Sonatype (see below), or
  3. in a built SemTK distribution under sparqlGraphLibrary/target/.

The most commonly used features of the SemTK Java API can be seen in the demo described below.

Accessing from Sonatype

To use a snapshot jar from Sonatype, find sparqlGraphLibrary jars on sonatype Nexus Repo Manager, or perform a more general search of semtk jars on sonatype. Copy the desired dependency from the Maven tab into your pom.xml. The Sonatype repos can be placed into your pom.xml as shown here (alternatively, in your .m2/settings.xml).

Inside of <distributionManagement>

<snapshotRepository>
    <id>sonatype</id>
    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>

Elsewhere:

<!-- Get our semtk dependencies directly from OSSRH snapshots -->
  <repositories>
    <repository>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <id>ossrh</id>
      <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </repository>
  </repositories>

Javadocs

Javadocs for the SemTK Java API are here

SemTK "Standalone Executables"

SemTK also includes some utility functions that can be run as standalone applications from the command line.

The standalone executables jar (referred to as STANDALONE_EXECUTABLES_JAR below) may be found:

  • as a GitHub Release artifact (e.g. semtk-opensource-v2.3.0-20201202-standaloneExecutables.jar), or
  • in any built distribution of SemTK, as standaloneExecutables/target/standaloneExecutables-jar-with-dependencies.jar
  • download the latest standaloneExecutables-*-jar-with-dependencies.jar from sonatype

Below are some of the available standalone executable features:

Demo of SemTK Java API

The most commonly used features of the SemTK Java API are demonstrated in JavaApiDemo.java, and may be run using this command:

java -cp STANDALONE_EXECUTABLES_JAR com.ge.research.semtk.demo.JavaApiDemo fuseki http://localhost:3030/DATASET

Load OWL or TTL files to the semantic store

The BulkLoader utility loads OWL or TTL files to the semantic store. This is typically used for loading bulk data (e.g. exports). It connects to the semantic store directly, without the use of SemTK services.

java -cp STANDALONE_EXECUTABLES_JAR com.ge.research.semtk.standaloneExecutables.BulkLoader -c sparqlConnection.json -e m0 owlFile.owl -u user -p password

Save nodegroup store to local disk

The RetrieveFromStore utility pulls nodegroups from the nodegroup store and stores them (as json files) to local disk.

java -cp STANDALONE_EXECUTABLES_JAR com.ge.research.semtk.standaloneExecutables.RetrieveFromStore http://server:12056 "regex" nodegroupDir

It is safest to clear nodegroupDir first, but this is not enforced nor strictly necessary.

The parameters are as follows:

  • contact the nodegroup store on http://server:12056
  • download any nodegroups whose id matches "regex"
  • download the nodegroups into nodegroupDir. Note there will be nodegroupDir/store_data.csv and a .json file for each nodegroup.

Load nodegroups to store from local disk

The StoreNodeGroup utility loads to the nodegroup store from local disk.

java -cp STANDALONE_EXECUTABLES_JAR com.ge.research.semtk.standaloneExecutables.StoreNodeGroup http://server:12056 nodegroupDir/store_data.csv
java -cp STANDALONE_EXECUTABLES_JAR com.ge.research.semtk.standaloneExecutables.StoreNodeGroup http://server:12056 nodegroupDir/store_data.csv /path/to/SPARQLConnection.json

The parameters are as follows:

  • contact the nodegroup store on http://server:12056
  • upload nodegroups specified in nodegroupDir/store_data.csv using their .json files specified therein
  • optionally override SPARQL connection (if provided as 3rd parameter)
  • overwrite any existing entries in the nodegroup store
⚠️ **GitHub.com Fallback** ⚠️