Java SDK

Skip to end of metadata
Go to start of metadata
Table of Contents
Source code & JavaDoc
The source code and the JavaDoc for the Java SDK are available from the S4 GitHub

Installation Instructions

Maven integration

Include the following lines in your Maven pom.xml

<dependencies>
	<dependency>
		<groupId>com.ontotext.s4</groupId>
		<artifactId>s4-client</artifactId>
		<version>1.2.1</version>
	</dependency>
	...
</dependencies>

Apache Ant Ivy

Include the following lines in your build.xml file

<dependencies>
	<dependency org="com.ontotext.s4" name="s4-client" rev="1.2.1" />
	...
</dependencies>

Gradle

Include the following lines in your build.gradle file

dependencies {
    compile 'com.ontotext.s4:s4-client:1.2.1'
}

Direct Download

Source Code

API keys

As described in the API documentation page, access to all S4 REST services require API key/secret pair, which can be generated from the S4 Management Console.

Workflow

Text Annotation

The following example demonstrates how to initialise a Twitter processing pipeline and analyse a simple document.

You can find the S4 client classes and interfaces in the com.ontotext.s4.* packages and sub-packages.

Step 1: Find the TwitIE pipeline via the ServicesCatalog:

Step 2: Instantiate a S4AnnotationClient used for communicating with the S4 processing service and specify your API key details:

Alternatively, you can get the pipeline's endpoint URL directly and create the S4AnnotationClient instance with it:

Step 3: Process the sample file content:

Step 4: Retrieve all annotations of a given type:

Step 5: Get the annotation values and perform further processing, analysis or visualisation:

Text and Images Annotation

This example demonstrates the combination of text analysis with the News processing pipeline and images annotation. The input data for the example is remotely available news article on the Web.

The relevant SDK Java classes and interfaces are contained in the com.ontotext.s4.* packages and sub-packages.

Step 1: Find the News service descriptor via the ServicesCatalog:

Step 2: Instantiate a S4AnnotationClient used for communication with the S4 processing service and specify your API key details:

Alternatively, you can get the pipeline's endpoint URL directly and create the S4AnnotationClient instance with it:

Step 3: Process the remote article:

Step 4: Retrieve all textual annotations of a given type:

Step 5: Retrieve the discovered images and their annotations:

Step 6: Read the text annotation information and print it in the current output stream:

Step 7: Now print the images annotations (tags and categories)

Here is a simplified fragment of the output in the console:

Text Classification

These instructions demonstrate the initialization and usage of the News Classification pipeline client to process a simple document. The workflow is similar to the one described in the preceding sections and for completeness some of the sections are identical.

The necessary classes and interfaces are located under the com.ontotext.s4.* packages.

Step 1: Instantiate a S4ClassificationClient used for communicating with the S4 processing service and specify your API key details:

Alternatively, you can get the pipeline's endpoint URL directly and create the S4ClassificationClient instance with it.

Step 2: Send a sample file content for classification:

Step 3: Retrieve the classification information and print it in the console:

An example output of the last code snippet is:

Multithreaded use of the SDK

The following example demonstrates how to use our Java SDK with multiple threads. The source code for this example is available here.

Input parameters for this program are:

  • Number Of threads to use.
  • Input directory. Directory with all text files we want to annotated.
  • Output directory. Directory where we want to save annotated files.
  • Service where we want to annotate documents.
  • Mime Type and Response format of the requests.
  • API key and API secret

First the program creates thread-safe queue. Then the program starts one thread to list all the files into input directory.
On the rest of the treads we start the annotating job.
Annotating thread pools a file from queue, send it to the S4 service, save the result into a file inside the output directory and again goes to the queue for the next file.
If queue is empty and the thread which list files is dead the annotating thread will kill itself. After all annotating threads are killed program will finish.

JavaDoc

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.