Programmatically add some instances to an existing ontology

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Programmatically add some instances to an existing ontology

Reza Moradi rad
Hi everyone
Please tell me how i can add some instances to an existing ontology programmatically (for an specific class) ?
Also i need to save new version of ontology in local disc.
I can guess how, but i'm not sure.
 
this code for saving:
manager.saveOntology(ontology, IRI.create(UriString));

All the best,
--
By : Reza Moradi Rad


_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically add some instances to an existing ontology

Olivier Dameron
Hello,

On 10/03/2010 04:16 PM, Reza Moradi rad wrote:
> Please tell me how i can add some instances to an existing ontology
> programmatically (for an specific class) ?

The following two lines create a "Brother" class and an instance
OWLNamedClass brotherClass = owlModel.createOWLNamedClass("Brother");
OWLIndividual individual = brotherClass.createOWLIndividual("Hans");

You may want to give a look at
http://protegewiki.stanford.edu/wiki/ProtegeOWL_API_Programmers_Guide
and more specifically at
http://protegewiki.stanford.edu/wiki/ProtegeOWL_API_Basics#Creating_Named_Classes_and_Individuals

I hope this helps
olivier
_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically add some instances to an existing ontology

Timothy Redmond
In reply to this post by Reza Moradi rad
On 10/03/2010 07:16 AM, Reza Moradi rad wrote:
Hi everyone
Please tell me how i can add some instances to an existing ontology programmatically (for an specific class) ?
Also i need to save new version of ontology in local disc.
I can guess how, but i'm not sure.

One issue with this question is it is not clear what OWL api you are using.  Olivier gave a very good answer assuming that you are using the Protege 3 OWL api.  This would be a natural inference based on the chosen mailing list.  But you then say:
 
this code for saving:
manager.saveOntology(ontology, IRI.create(UriString));

This suggests that you are talking about the Manchester OWL api.  For that I would recommend the documentation at owlapi.sourceforge.net.  This includes programming examples for several different scenarios.  In this api, you don't really create individuals.  You create statements about individuals.  The closest thing to what you want would be to add declarations of named individuals to the ontology.  You would do that with something like (this is definitely pseudo-code - not compileable):

OWLDatafactory factory = manager.getOWLDataFactory();
OWLNamedIndividual i = factory.getOWLNamedIndividual(IRI.create(...));
OWLAxiom declaration = factory.getOWLDeclaration(i);
manager.addAxiom(ontology,declaration);
  

This is verbose code but it has the advantage that it clear how it relates to the OWL 2 specification which cannot be said for the Protege 3 OWL api.

this code for saving:
manager.saveOntology(ontology, IRI.create(UriString));

Yes.  And there are several other variants for writing to a stream, a reader, setting the format of the output (OWL/XML, RDF/XML, functional syntax), etc.

-Timothy


All the best,
--
By : Reza Moradi Rad

_______________________________________________ protege-owl mailing list [hidden email] https://mailman.stanford.edu/mailman/listinfo/protege-owl Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03


_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03