Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>While I agree with <a href="https://stackoverflow.com/questions/19537789/adding-more-individuals-to-existing-rdf-ontology/19538411?noredirect=1#comment29000899_19538411">RobV's point</a> that, in general, this is difficult to do if you're working in OWL (as opposed to plain RDF), you <em>can</em> do this if your OWL ontology is serialized as RDF which is then serialized in N-Triples. The following code (with comments) shows how you can do this.</p> <p>The idea here is that if you're only adding new content and if you use a format that puts one RDF triple per line, then you can simply append the new triples to the content without any trouble. The first model that I've shown is like your ontology model on disk. Here I've only created it to show that the class declaration in the ontology uses one triple, <code>Region a owl:Class</code>. Region is identified by an IRI, though, and as long as you know its IRI, you don't need the whole ontology just to refer to the resource. In a <em>new</em> model, you can create an individual that of type Region, and you can simply append the triples of that model to the file on disk.</p> <pre class="lang-java prettyprint-override"><code>import com.hp.hpl.jena.ontology.Individual; import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.rdf.model.ModelFactory; public class IncrementalOWLUpdates { public static void main(String[] args) { final String NS = "http://example.org/"; // This is like the model on disk, and contains the class declaration // that you wouldn't want to write out each time. System.out.println( "=== content of ontology on disk ===" ); final OntModel model = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM ); final OntClass Region = model.createClass( NS+"Region" ); model.write( System.out, "N-Triples" ); // This is the new model that you would build to contain the new triples // that you want to add to the original model. Note that it _doesn't_ // contain the class declaration, but only the new triples about the // new individual. If you open the original ontology file and append this // output, you've updated the ontology without reading it all into memory. System.out.println( "=== new content to append ===" ); final OntModel update = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM ); final Individual newHampshire = update.createIndividual( NS+"NewHampshire", Region ); newHampshire.addLabel( "New Hampshire", "en" ); update.write( System.out, "N-Triples" ); } } </code></pre> <pre class="lang-none prettyprint-override"><code>=== content of ontology on disk === &lt;http://example.org/Region&gt; &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#type&gt; &lt;http://www.w3.org/2002/07/owl#Class&gt; . === new content to append === &lt;http://example.org/NewHampshire&gt; &lt;http://www.w3.org/2000/01/rdf-schema#label&gt; "New Hampshire"@en . &lt;http://example.org/NewHampshire&gt; &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#type&gt; &lt;http://example.org/Region&gt; . </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload