2

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.

Mod
  • 5,091
  • 7
  • 28
  • 47

1 Answers1

0

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.

Jeen Broekstra
  • 21,642
  • 4
  • 51
  • 73
  • Thank you very much for your help. Please correct me if I am mistaken. I am trying to do the schema or the ontology and create my statement based on it. Is that right? One more thing, please. Would you recommend me to create an ontology in a file and upload that file in Sesame and then create the statements like the alice example? Since I do not know how to do it in this way, I will do it in the way you helped me with. Do you think it would be OK? – Mod Feb 09 '14 at 19:55
  • You don't _need_ to create the schema first if that's what you're asking - it's perfectly fine to define `alice` as a `person` without first defining that `person` is a class. As for what you should create in a file vs directly via the API, it depends on your use case, but generally speaking, data that is relatively stable ( = your ontology) is easier to load from file, while data that changes a lot is easier to directly create/manipulate via the API. – Jeen Broekstra Feb 09 '14 at 19:59
  • Please one more question. I am thinking now to create a file and do the ontology for it. In that file, should everything be there including the statements as well? – Mod Feb 09 '14 at 20:15