Sesame Triple Store

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:
    1. class not found: make sure the jar is in place
    2. 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

Jakobitsch Juergen, tschyrgie@yahoo.com, www.turnguard.com

  • API to access SPARQL endpoint is here.

Maillist

RDMBS store

  • As to RDBMS store configuration notice, RDBMS store can be configured as monolithic and as vertical schema that stores statements in a per-predicate table. In last case the queries like SELECT A, B FROM {_:node14fopd6qfx2065} A {B} become very inefficient, because all tables should be joined to get the result. Setting maxTripleTables property will switch on monolithic schema, if you set it to 2, it will put the first predicate used into it own table and everything else into a shared table, 3 will cause the first two predicates to have their own table. Generally, you want either 1 or 0 (infinity).
  • “sequenced” property: when set to false the system will use 64bits for URI, BNode, and Literal internal IDs. This results in the statement table being twice as big and requires much more memory to work with. However, it reduces some of the intermediate operations. Best to leave this setting alone.
  • “indexed” property creates or drops additional indexes to balance between load ↔ retrieval efficiency.
  • HashManager is used to generate 64-bit hashes out of literals. The hash value is converted into a 32bit sequential number to save space. To use the 64bit values directly set RdbmsStore#setSequenced(false) before initializing an empty database (no existing tables)2).
  • Writes to the different tables are executed in different threads. That is why is there a need to have a “flusher” thread for each manager. Separate threads prevent dead locks between separate transactions. Some operations are global (assigning a value to an ID for example). These should not be executed within an isolated transaction, but shared to prevent conflicts.
  • All the values (URI, Literal, BNodes) are stored in the database and shared for all connections. However, to prevent this table from growing out of control, it must be pruned (particularly when the RDF store is cleared). When these value tables are pruned their version is incremented to indicate that any in-memory values will need to be restored in the database if they were looked up using as earlier version of the table. The version number (RdbmsValue) does not need to be persisted as it is only used to keep the in-memory values in-sync with recent changes to the database.

The details about Native store

  • Native store performance can be influenced by defining the sequence of indices to use (e.g. nativeStore.setTripleIndexes(“spoc,posc”))

The details about Elmo engine

  • Create a beans Author which has a collection of Publications:

    Author.java

    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;
        }
    }

    Publication.java

    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;
        }
    }
  • Now use the following code to persist instance of Author object:

    Tester.java

    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();
        }
  • The output follows. Notice that Elmo instantiates the collection using RDF Container:

    elmo.rdf

    <?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>
2) See the complete discussion in maillist
programming/semantic_web/sesame.txt · Last modified: 2010/02/14 23:14 by dmitry
 
 
Recent changes RSS feed Driven by DokuWiki