Marmotta comes with a set of generic tools that extend Sesame OpenRDF API.
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);
<dependency> <groupId>org.apache.marmotta</groupId> <artifactId>marmotta-rio-ical</artifactId> <version>3.3.0</version> </dependency>
Apache Marmotta comes with RIO modules for ical, rss and vcard.
<dependency> <groupId>org.apache.marmotta</groupId> <artifactId>marmotta-rio-ical</artifactId> <version>3.3.0</version> </dependency> <dependency> <groupId>org.apache.marmotta</groupId> <artifactId>marmotta-rio-rss</artifactId> <version>3.3.0</version> </dependency> <dependency> <groupId>org.apache.marmotta</groupId> <artifactId>marmotta-rio-vcard</artifactId> <version>3.3.0</version> </dependency>
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).
<dependency> <groupId>org.apache.marmotta</groupId> <artifactId>marmotta-sesame-matchers</artifactId> <version>3.3.0</version> </dependency>
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:
<dependency> <groupId>org.apache.marmotta</groupId> <artifactId>marmotta-util-facading</artifactId> <version>3.3.0</version> </dependency>
Then, in your Java code you may need to define your model, for instance define a skos:Concept:
@RDFType(Namespace.SKOS.Concept) public interface ConceptFacade extends Facade { @RDF({Namespace.DCTERMS.identifier}) public String getIdentifier(); public void setIdentifier(String name); @RDF({Namespace.SKOS.prefLabel, Namespace.RDFS.label}) public String getPrefLabel(); public void setPrefLabel(String location); @RDF(Namespace.SKOS.altLabel) public Set<String> getAltLabels(); public void setAltLabels(Set<String> location); public void addAltLabel(String label); @RDF(Namespace.SKOS.definition) public String getDefinition(); public void setDefinition(String location); @RDF(Namespace.SKOS.broader) public void setBroaders(Set<Resource> broader); public Set<Resource> getBroaders(); public void addBroader(Resource broader); @RDF(Namespace.SKOS.narrower) 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 { conn.begin(); // 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 http://www.w3.org/2004/02/skos/core#Concept // - 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 { conn.commit(); conn.close(); }