Reputation: 2949
I have created a simple ontology as shown below with 4 classes, 1 objectTypeProperty and 2 DatatypeProperties. Now I want to create different individuals of same ontology. By Individual, I mean a row of data shown in below table
. I am trying to insert these individuals in the ontology with Jena directly.
Till now, I have read the ontology in Jena, but how should I insert all these individuals. Do I need to use any type of loop or there is specific provision in Jena to insert repetitive information.
Note: I have asked similar type of question before at http://answers.semanticweb.com/questions/31641/use-an-ontology-to-store-csv-data-into-rdf-form. I got the answer, but I want to know without using alignment ApI, can I do it purely using Jena.
Note: It seems that answers.semanticweb.com is down currently.
Upvotes: 2
Views: 486
Reputation: 21
Since I can't post a comment, I'll do it here...
Haroon, about the question at answers.semanticweb.com, I just followed with Alignment API because you said you needed to find the mappings between the CSV columns and the concepts. Using only Jena, you can't do it, because as far as I know, Jena doesn't give you any method or any kind of support for alignment or semantic annotations. In fact, you can do this without Alignment API too, by using some other library like second string (one of my comments there), or any other that allows you to run string comparison (or structural or semantic...).
If you don't need to calculate the alignment during runtime, I mean, if you have it set manually, you can use Jena to create the individuals. Besides using SPARQL as pointed in the first answer, you could load the ontology into a Jena model and create the individuals using Jena methods. If your get a OntClass, there's a method 'createIndividual' that allows you to create an Individual of that type.
If your ontology is too large, you can get part of it, or just create the resources you need and append it to your model later. You could do this by using Jena methods, or creating the SPARQL Update by code as Joshua Taylor said.
If you take the code example in the other answer and exclude Alignment API part, you have this Jena implementation (the official documentation is pretty easy to understand too). Just keep the mapping at some storage (file, database, whatever) and use it to map the columns to concepts.
Once you created the individuals in the Jena model, they will be part of your ontology, but only to the version you have in memory, so, you need to save it back to where it came from: some file or SPARQL endpoint with SPARQL Update support.
Hope this can enlighten you for the solution!
Upvotes: 2
Reputation: 85853
It's probably easiest to insert multiple triples using SPARQL. It'd essentially be
prefix : <...>
insert data {
:individual1 :place :p1 ; :date "110114" ; temperature 13 .
:individual2 :place :p2 ; :date "120114" ; temperature 14 .
:individual3 :place :p3 ; :date "130114" ; temperature 15 .
}
That's convenient if you already know the data you need to insert. If you don't, or you're reading it from some other file, it might be easier to construct it through code.
Upvotes: 3