The LAPPS Exchange Data Structures are a small set of Java classes (Groovy classes actually) that provide the data model for the JSON-LD data exchanged by services on the LAPPS grid.
To use this package you need to add following dependency to the project's pom.xml file:
<dependency>
<groupId>org.lappsgrid</groupId>
<artifactId>serialization</artifactId>
<version>2.4.0</version>
</dependency>
The org.lappsgrid.serialization.Serializer
class provides static methods for converting
between the LEDS objects and their JSON representations.
Container container = new Container()
...
String json = Serializer.toJson(container)
...
Container anotherContainer = Serializer.parse(json, Container.class)
There are three main classes that make up LEDS:
- Annotation Used to store information about a single annotation
class Annotation {
String type
Long start
Long end
Map features
Map metadata
}
- View Used to store the annotations for a single view of the document.
class View {
List<Annotation> annotations
Map metadata
}
- Container Used to store the original data (text, audio, etc) plus all annotations produces by all processing services.
class Container {
String text
String language
List<View> views
Map metadata
}
Container objects define a @context in the JSON document itself. To refer to the remote @context at http://vocab.lappsgrid.org/context-1.0.0.jsonld create a Container and pass false as the only parameter.
Container containerWithLocalContext = new Container();
Container containerWithRemoteContext = new Container(false);
When working with a local @context the entries in the @context are stored in a hash map that can be manipulated at runtime:
Container container = new Container(); // Creates a container with a local @context object.
Map context = container.getContext();
context.put("myToken", "http://example.com/token");
Almost every LEDS object contains a hash map for storing metadata. In general applications are free to store whatever metadata they need in these maps. The only required metadata is the contains map in the Views.
The contains map contains information about the annotations available in that view. The contains map looks like
"metadata" : {
"contains" : {
"Token" : {
"producer" : "http://service.that.produces.the.tokens",
"type" : "tokenization:custom"
}
}
},
To simplify the process of creating the contains map the View class provides a addContains(String label, String producer, String type) method. For example the above JSON can be generated with:
Container container = new Container(false);
View view = new View()
view.addContains("Token", "http://service.that.produces.the.tokens", "tokenization:custom");
container.getViews().add(view)
Annotation a = new Annotation();
a.setType("token");
a.setStart(0);
a.setEnd(5);
a.getFeatures().put("pos", "UH")
View view = new View();
view.getMetadata().put("pass", "1");
view.getAnnotation().add(a);
Container container = new Container();
container.setText("Hello world");
container.setLanguage("en");
container.getViews().add(view);
String json = Serializer.toPrettyJson(container);
System.out.println(json);
...
Container container = Serializer.parse(json, Container.class)
Annotation a = new Annotation(type:'token', start:0, end:5)
a.features['pos'] = 'UH'
View view = new View()
view.metadata['pass'] = 1
view.annotations.add(a)
Container container = new Container(text:'Hello world')
container.views.add(view)
String json = Serializer.toPrettyJson(container)
...
Container container = Serializer.parse(json, Container)