javasesameopenrdf

How to describe classes and properties using RDFS in Java


I am quite new to Java Sesame. I am following this tutorial: http://openrdf.callimachus.net/sesame/2.7/docs/users.docbook?view . I know how to create statements and add them into the Sesame repository. At the moment, I am trying to describe classes and properties for the statements I am going to add. For example, I am having the ones below:

:Book rdf:type rdfs:Class .
:bookTitle rdf:type rdf:Property .
:bookTitle rdfs:domain :Book .
:bookTitle rdfs:range rdfs:Literal .
:MyBook rdf:type :Book .
:MyBook :bookTitle "Open RDF" .

As shown, Book is defined as a Class. bookTitle is defined as a Property. My question is: How can I do this in Java Openrdf using org.openrdf.model.vocabulary.RDFS. To clarify the point, Here is another example:

con.add(alice, RDF.TYPE, person);

alice is a type of person. How can I define person as a class using org.openrdf.model.vocabulary.RDFS. Your assistance would be very much appreciated.


Solution

  • You'd do this in exactly the same way as you're describing alice as a person. Like this:

     con.add(person, RDF.TYPE, RDFS.CLASS);
    

    Similarly for the other things you want to add (assuming you've created a URI for bookTitle):

    con.add(bookTitle, RDF.TYPE, RDF.PROPERTY);
    con.add(bookTitle, RDFS.DOMAIN, book);
    

    etc.

    I should point out that although it is of course possible to create your schema or ontology in this fashion, it might be easier to instead create a file containing your ontology (e.g. in Turtle or N-Triples syntax), and then simply upload that file to your Sesame repository.