Anno4j - Idiomatic Persistence and Querying for the W3C Annotation Data Model

12
Idiomatic Persistence and Querying for the W3C Web Annotation Data Model Emanuel Berndl, Kai Schlegel, Andreas Eisenkolb, Harald Kosch Chair of Distributed Information Systems University of Passau

Transcript of Anno4j - Idiomatic Persistence and Querying for the W3C Annotation Data Model

Page 1: Anno4j - Idiomatic Persistence and Querying for the W3C Annotation Data Model

Idiomatic Persistence and Querying for the W3C Web Annotation Data ModelEmanuel Berndl, Kai Schlegel, Andreas Eisenkolb, Harald KoschChair of Distributed Information SystemsUniversity of Passau

Page 2: Anno4j - Idiomatic Persistence and Querying for the W3C Annotation Data Model

Add metadata to online assets, but how?• Metadata on multimedia useful in many different ways• Further describe something• Support semantic search• Bridging the semantic gap, …

Page 3: Anno4j - Idiomatic Persistence and Querying for the W3C Annotation Data Model

Web Annotations – Web Annotation Data Model• Web Annotations: “product” of the Web Annotation Data

Model1 WADM, a W3C standard• “Annotations are typically used to convey information about

a resource or associations between resources. Simple examples include a comment or a tag on a single web page or image, or a blog post about a news article.”

• WADM Standard defines an RDF framework to design shareable and expressive annotations

1https://www.w3.org/TR/annotation-model/

Page 4: Anno4j - Idiomatic Persistence and Querying for the W3C Annotation Data Model

WADM – An Example

Page 5: Anno4j - Idiomatic Persistence and Querying for the W3C Annotation Data Model

Anno4j• Programmatic access to reading and writing Web

Annotations from and to SPARQL-endpoints• Useable “without” RDF or SPARQL experience• Hibernate-like mapping between RDF objects and Java

Objects• Extensible design• Usable with any SPARQL 1.1 endpoint• Apache License 2.0 github.com/anno4j/anno4j

• Core library (smaller tweaks implemented): OpenRDF Alibaba1 (former Elmo codebase)

• Features:

Persistence Querying

Graph context Transactions Extensions/Plugins

1https://bitbucket.org/openrdf/alibaba

Page 6: Anno4j - Idiomatic Persistence and Querying for the W3C Annotation Data Model

WADM – An Example

Page 7: Anno4j - Idiomatic Persistence and Querying for the W3C Annotation Data Model

Persistence – Custom Model@Iri(http://www.example.com/

schema#AnimalBody)public interface AnimalBody extends Body {

@Iri(RDF.VALUE)String getAnimal();@Iri(RDF.VALUE)void setAnimal(String animal);@Iri(EX.CONFIDENCE)Double getConfidence();@Iri(EX.CONFIDENCE)void setConfidence(Double

confidence);}

Creating a Java class (with respective example values) leads to the following RDF triples:

<urn:body> a ex:AnimalBody ;rdf:value “panda” ;ex:confidence 0.95 .

Page 8: Anno4j - Idiomatic Persistence and Querying for the W3C Annotation Data Model

Persistence – Anno4j Workflow// Setup Anno4j instanceAnno4j anno4j = new Anno4j();anno4j.setRepository(new SPARQLRepository(“http://www.mydomain.com/sparql”));anno4j.setIdGenerator(new MyIDGenerator());

// Create the AnnotationAnnotation anno = anno4j.createObject(Annotation.class);anno.setMotivatedBy( ... );anno.setSerializedAt( ... );

// Create and attach the BodyAnimalBody body = anno4j.createObject(AnimalBody.class);body.setAnimal(“panda”);body.setConfidence(0.95);anno.setBody(body);

Page 9: Anno4j - Idiomatic Persistence and Querying for the W3C Annotation Data Model

Querying• Queries via Anno4j are done using the path-based query

language LDPath1

• Query for information on an RDF graph• More convenient to non-RDF experts• Transformed to an equivalent SPARQL 1.1 query

• Fluent interface supported for querying

LDPath examples• Path Traversal: oa:hasBody/rdf:value• Reverse Path: ^oa:hasTarget• Types: ex:predicate[is-a

ex:AnimalBody]• Datatypes:

ex:doubleValue[^^xsd:double]• Languages: ex:langValue[@en]• Grouping & Unions: (ex:pred1/ex:pred2) |

ex:pred3 1http://marmotta.apache.org/ldpath/

Page 10: Anno4j - Idiomatic Persistence and Querying for the W3C Annotation Data Model

Querying – Example

// Setup QueryServiceQueryService qs = anno4j.createQueryService();qs.addPrefix(“ex”, “http://www.example.com/schema#”)

.addCriteria(“oa:hasBody[is-a ex:AnimalBody]”)

.addCriteria(“oa:hasBody/rdf:value”, “panda”)

.addCriteria(“oa:hasBody/ex:confidence”, 0.8, Comparison.GTE);

// Query for AnnotationsList<Annotation> result = qs.execute(Annotation.class);

Page 11: Anno4j - Idiomatic Persistence and Querying for the W3C Annotation Data Model

Additional Features• LDPath criteria(s) directly mapped to equivalent SPARQL 1.1 query• Extensions/Plugins• Support custom LDPath function + query logic

• Transactions (beta)• Transactional behavior can be used with the triplestore• Set of actions: commit or rollback• Basic behavior: Auto-commit

• Graph Contexts / Subgraphs• Lazy evaluation for faster and more efficient querying

Page 12: Anno4j - Idiomatic Persistence and Querying for the W3C Annotation Data Model

Summary

• Anno4j is in use in the MICO project (Media in Context): WADM adaption

• Future steps include the implementation of the Web Annotation Protocol WAP1 in Anno4j, adding a web facet to the library

1https://www.w3.org/TR/annotation-protocol/