Sesame Tools

Marmotta comes with a set of generic tools that extend Sesame OpenRDF API.

RDF Patch

The module marmotta-util-rdfpatch allows to create and apply rdf-patches to a Sesame Repository or RepositoryConnection.

// Prepare
RepositoryConnection connection = repository.getConnection();
String patch = "...";

// Apply a patch to the repository
RdfPatchUtil.applyPatch(connection, patch);

Sesame RIO

Apache Marmotta comes with RIO modules for ical, rss and vcard.


Hamcrest Matchers

The Sesame Hamcrest Matchers allows easy integration of repository tests into JUnit.

Repository repo = getReopsitory();
// operate on the repo
//   - add/delete statements, etc...

// Test
RepositoryConnection con = repo.getConnection();
Assert.assertThat("subject is not a skos:Concept", con, 
    SesameMatchers.hasStatement(subject, RDF.TYPE, SKOS.Concept, context));

There are convenience wrappers that directly operate on a Repository (RepositoryMatcher) or even serialized RDF formats (RdfStringMatcher).


Sesame Façading

Sesame Façading allows using annotated Java interfaces (façades) to access an underlying Sesame repository, similar to JPA.

To use the Sesame Façading, include the following artifact in your Maven build file in your Marmotta module:


Then, in your Java code you may need to define your model, for instance define a skos:Concept:

public interface ConceptFacade extends Facade {
    public String getIdentifier();
    public void setIdentifier(String name); 
    @RDF({Namespace.SKOS.prefLabel, Namespace.RDFS.label})
    public String getPrefLabel();
    public void setPrefLabel(String location);

    public Set<String> getAltLabels();
    public void setAltLabels(Set<String> location);
    public void addAltLabel(String label);

    public String getDefinition();
    public void setDefinition(String location);
    public void setBroaders(Set<Resource> broader);
    public Set<Resource> getBroaders();
    public void addBroader(Resource broader);
    public void setNarrowers(Set<Resource> narrower);
    public Set<Resource> getNarrowers();
    public void addNarrower(Resource narrower);


So the necessary code to use this, for instance for lookup by identifier, would be something like:

Resource concept = null;
URI context = null;
// a valid uri
String skosURI = "http://host/to/marmotta/resource/concept1";
String contextURI = "http://host/to/marmotta/context/default";
RepositoryConnection conn = ... // obtain a connection
try {
    // obtain the Facading helper 
    Facading facading = FacadingFactory.createFacading(conn);

    // create or use an resource uri of a skos:Concept
    concept = conn.getValueFactory().createURI(skosURI);
    context = conn.getValueFactory().createURI(contextURI);
    // create a facade of the skos:Concept by providing the resource, 
    // the requested type and (optional) the context
    ConceptFacade facade = facading.createFacade(concept, ConceptFacade.class, context);
    // manage the resource via getter/setter methods
    fadade.setPrefLabel("new label");
    facade.addAltLabel("new alternate label");
    // at this point, the resource "http://host/to/marmotta/resource/concept1" 
    // - is created if not yet present
    // - has type
    // - has a triple: rfds:label "new label"
    // - has a triple: skos:prefLabel "new label"
    // - has a triple: skos:altLabel "new alternate label"
    // return the resource uri of the facade, e.g. the concept resource's uri
    return resource.getDelegate();
} finally {