Sesame is an open source framework for storage, inferencing and querying of RDF data
check out this repository cd customrulereasoner/trunk && mvn install the it depends, how you're used to create your repositories
console: put the customrulereasoner.jar into the according lib folder and use the following template:# # Sesame configuration template for a native RDF repository with # RDF Schema and Custom inferencing # @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>. @prefix rep: <http://www.openrdf.org/config/repository#>. @prefix sr: <http://www.openrdf.org/config/repository/sail#>. @prefix sail: <http://www.openrdf.org/config/sail#>. @prefix ns: <http://www.openrdf.org/config/sail/native#>. @prefix custom: <http://www.openrdf.org/config/sail/custom#>. @prefix ms: <http://www.openrdf.org/config/sail/memory#>. [] a rep:Repository ; rep:repositoryID "xpd-154-sesamenative" ; rdfs:label "CustomRuleReasoner-NATIVE" ; rep:repositoryImpl [ rep:repositoryType "openrdf:SailRepository" ; sr:sailImpl [ sail:sailType "openrdf:CustomRuleReasoner" ; sail:delegate [ sail:sailType "openrdf:NativeStore" ; ns:tripleIndexes "spoc" ] ] ]. write some rules (see below for examples) into a file and import the file into the ruledef context, approximately like so:repcon.add(FileUtils.openInputStream(new File("/templates/rules-skos.ttl")), "", RDFFormat.TURTLE, new Resource[] { CustomRuleReasonerSchema.RULEDEF_CONTEXT } ); now just use the repository, easiest:LocalRepositoryManger LRM = new LocalRepositoryManager(new File("path/to/sesameroot/")); LRM.initialize(); Repository rep = LRM.getRepository("mycustom"); ... you may run into the following problems:
class not found: make sure the jar is in place unsupported sail type: make sure the factories are loaded
if problem occures in console: edit Console.java source code and enter the following line somewhere in the constructor or like this: SailRegistry.getInstance().add(new CustomRuleReasonerFactory()); if problem occurs in webapp or so, best is to write this line into a webappcontextlistener if problem occurs in sesame-workbench (write a webappcontextlistener) and add to sesame-workbench's web.xml
import java.util.Collection; import org.mycompany.common.vocabulary.CWA; import org.openrdf.elmo.annotations.rdf; @rdf(CWA.NAMESPACE + "auth") public class Author { @rdf(CWA.NAMESPACE + "auth/id") private int id; @rdf(CWA.NAMESPACE + "auth/name") private String name; @rdf(CWA.NAMESPACE + "auth/publications") private Collection<Publication> publications; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Collection<Publication> getPublications() { return publications; } public void setPublications(Collection<Publication> publications) { this.publications = publications; } }
import org.mycompany.common.vocabulary.CWA; import org.openrdf.elmo.annotations.rdf; @rdf(CWA.NAMESPACE + "pub") public class Publication { private int id; private String title; @rdf(CWA.NAMESPACE + "pub/id") public int getId() { return id; } public void setId(int id) { this.id = id; } @rdf(CWA.NAMESPACE + "pub/title") public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } }
import java.io.FileOutputStream; import java.io.IOException; import java.util.Arrays; import java.util.Collection; import org.openrdf.elmo.ElmoModule; import org.openrdf.elmo.sesame.SesameManager; import org.openrdf.elmo.sesame.SesameManagerFactory; import org.openrdf.model.Resource; import org.openrdf.repository.Repository; import org.openrdf.repository.RepositoryConnection; import org.openrdf.repository.RepositoryException; import org.openrdf.rio.RDFHandlerException; import org.openrdf.rio.rdfxml.RDFXMLWriter; public class Tester { public void testElmo(Repository repository) throws RepositoryException, RDFHandlerException, IOException { ElmoModule module = new ElmoModule(); module.addConcept(Author.class); module.addConcept(Publication.class); SesameManagerFactory factory = new SesameManagerFactory(module, repository); SesameManager manager = factory.createElmoManager(); Publication publication1 = new Publication(); publication1.setId(1); publication1.setTitle("cool"); Publication publication2 = new Publication(); publication2.setId(2); publication2.setTitle("super"); Author author = new Author(); author.setId(5); author.setName("It's me!"); author.setPublications(Arrays.asList(publication1, publication2)); manager.persist(author); final FileOutputStream fos = new FileOutputStream("elmo.rdf"); final RDFXMLWriter rdfWriter = new RDFXMLWriter(fos); final RepositoryConnection connection = repository.getConnection(); try { connection.export(rdfWriter, new Resource[0]); } finally { connection.close(); } fos.close(); }
<?xml version="1.0" encoding="UTF-8"?> <rdf:RDF <rdf:Description rdf:nodeID="node14htv5c78x1"> <rdf:type rdf:resource="http://www.nbic.nl/cwa/auth"/> <id xmlns="http://www.nbic.nl/cwa/auth/" rdf:datatype="http://www.w3.org/2001/XMLSchema#int">5</id> <name xmlns="http://www.nbic.nl/cwa/auth/">It's me!</name> <publications xmlns="http://www.nbic.nl/cwa/auth/" rdf:nodeID="node14htv5c78x2"/> </rdf:Description> <rdf:Description rdf:nodeID="node14htv5c78x2"> <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Container"/> <rdf:_1 rdf:nodeID="node14htv5c78x3"/> <rdf:_2 rdf:nodeID="node14htv5c78x4"/> </rdf:Description> <rdf:Description rdf:nodeID="node14htv5c78x3"> <rdf:type rdf:resource="http://www.nbic.nl/cwa/pub"/> <id xmlns="http://www.nbic.nl/cwa/pub/" rdf:datatype="http://www.w3.org/2001/XMLSchema#int">1</id> <title xmlns="http://www.nbic.nl/cwa/pub/">cool</title> </rdf:Description> <rdf:Description rdf:nodeID="node14htv5c78x4"> <rdf:type rdf:resource="http://www.nbic.nl/cwa/pub"/> <id xmlns="http://www.nbic.nl/cwa/pub/" rdf:datatype="http://www.w3.org/2001/XMLSchema#int">2</id> <title xmlns="http://www.nbic.nl/cwa/pub/">super</title> </rdf:Description> </rdf:RDF>