Anno4j is a Java library that creates a ORM (Object-RDF-Mapping) in order to create and query RDF by writing Java POJOs. More specifically, it allows to create Web Annotations (from the W3C Web Annotation Data Model) by predefining necessary classes and interfaces. Own RDF models can easily be integrated, as the library is designed in an extensive fashion. Comprehensive querying is implemented by the use of the path-based query language LDPath.
It builds upon the Alibaba library and brings a set of convenience features, such as subgraphing, transactions, and plugin extensibility.
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Anno4j - Idiomatic Persistence and Querying for the W3C Annotation Data Model
1. 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
2. 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, …
3. 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/
7. 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 .
8. Persistence –
Anno4j Workflow
// Setup Anno4j instance
Anno4j anno4j = new Anno4j();
anno4j.setRepository(new
SPARQLRepository(“http://www.mydomain.com/sparql”));
anno4j.setIdGenerator(new MyIDGenerator());
// Create the Annotation
Annotation anno = anno4j.createObject(Annotation.class);
anno.setMotivatedBy( ... );
anno.setSerializedAt( ... );
// Create and attach the Body
AnimalBody body = anno4j
.createObject(AnimalBody.class);
body.setAnimal(“panda”);
body.setConfidence(0.95);
anno.setBody(body);
9. 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/
10. Querying – Example
// Setup QueryService
QueryService 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 Annotations
List<Annotation> result = qs.execute(Annotation.class);
11. 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
12. 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/
Notes de l'éditeur
Vorbild HibernateIdiomatic – The strength of one language is used in your own familiar (programming) language