WebLab Model Annotator

From WebLab Wiki
Jump to: navigation, search

This page sums up the usage of the WebLab Annotators that have been first released with WebLab Core 1.2.

The main goal of annotator is to ease the manipulation of simple RDF annotation on WebLab Resources (see a comparison between Annotator and Helpers). They provide some features:

  • to add and set annotation in a specific language (or without language support)
  • to manage typed values (instead of strings)
  • to manipulate easily non arbitrary number of values on a single property
  • to annotate WebLab Resources with properties defined in external ontologies

Annotators provided within WebLab Core:

Common Annotators Features

Language support

There is no language specified in an annotator by default.

  • startSpecifyLanguage(String lang)

Force the annotators to only read or write statements defined with the language lang.

  • endSpecifyLanguage()

Disable the limitation on the language.

Writing mode

  • setAppendMode(boolean append)

True by default, annotators use the append mode to add several annotations on the same property. If false, it will override already existing annotations.

  • isAppendMode()

return the current mode of writing (append mode is true by default).

Typed values

Managing typed values

The Java Value class behave as a typed value and a list of typed values at the same time.

External properties support

  • startInnerAnnotator(URI subject)
  • endInnerAnnotator()

RDF and RDFS Annotator

It provides two annotators supporting the following properties:

Dublin Core Annotators

It provides a DublinCoreAnnotator with the properties defined in http://purl.org/dc/elements/1.1/ and a DCTermsAnnotator with the properties defined in http://purl.org/dc/terms.

WebLab Annotators

Using our provided tool OWL2Annotator.java, we generated annotators from WebLab processing and WebLab retrieval ontologies.

Standard Use

Using our provided tool OWL2Annotator.java, the annotator WGeonamesAnnotator has been generated automatically from this little_geonames.owl.

	Text text = ResourceFactory.createResource("idfact", "myDoc", Text.class);
	// We can use several Annotator on a Resource at the same time
	WProcessingAnnotator wpa = new WProcessingAnnotator(text);
	WGeonamesAnnotator geoa = new WGeonamesAnnotator(text);
	// We create URI
	URI	segmentURI = new URI("weblab://idfact/mySegment");
	URI	londonGeonamesURI = new URI("http://sws.geonames.org/2643743/");
	// Create a geographic entity in the document from an external ontology
	// We set RDFS labels
	// We set the language support in Official Aramaic ISO format
	// We write label in the Official Aramaic language 
	geoa.writeLabel("ܠܘܢܕܘܢ ");
	// Wet the language support in French ISO format
	// We write label in the French language
	geoa.writeLabel("La ville de Londres");
	// We set the overwrite mode to reset the french label
	// We overwrite a label 
	// We set back the append mode of the annotator 
	// We remove language specification 
	// we write a label without language attribute
	// We set geonames specific latitude/longitude properties
	// Create add segment on the Text
	LinearSegment segment = new LinearSegment();
	// Create a semantic link between the segment and the geographical entity

Once serialized, the resulting document in XML will be:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<resource xsi:type="wl:text" uri="weblab://idfact/myDoc" xmlns:wl="http://weblab.ow2.org/core/1.2/model#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <annotation uri="weblab://idfact/myDoc#a0">
            <rdf:RDF xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
                   xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"  xmlns:wlp="http://weblab.ow2.org/core/1.2/ontology/processing#">
                <rdf:Description about="http://sws.geonames.org/2643743/">
                    <rdfs:label xml:lang="arc">ܠܘܢܕܘܢ </rdfs:label>
                    <rdfs:label xml:lang="fr">Londres</rdfs:label>
                <rdf:Description about="weblab://idfact/mySegment">
                    <wlp:refersTo rdf:resource="http://sws.geonames.org/2643743/"/>
    <segment xsi:type="wl:linearSegment" uri="weblab://idfact/mySegment" start="0" end="6" />

Annotator generation from an ontology

We provide a script to automatically generate an Annotator from any ontology. This script will list all the properties (dataproperties and objectproperties) from your ontology (in owl or rdf format) and will generate the corresponding Annotator. This generation will check the range part of a property and it will try to map it with an existing Java type. Thus a rdf property which range is a date will become a java.util.Date Object in the Annotator.

The script is available at the following address: OWL2Annotator.java

  • To run the script on your OWL ontology; You have to put the path of your ontology in parameter.
  • To run the script on your RDF ontology; You have to put the path of your ontology in parameter AND an URI corresponding to the namespace of your ontology.