I am using rdflib, protege and python for creating ontology and accessing information from this ontology. so far so good as I can use SPARQL queries using rdflib under python to fetch the data. however now I need to insert the data such individuals i.e. instances along with object and data properties into ontology. Please note I can do this using protege but I am not sure how to implement this using rdflib. For example I have a class name activity and I wish to create an instance of this class using RDF library and wish to associate an object property for example HasA to this newly created instance of the activity. I am wondering how to do this using python.
Asked
Active
Viewed 1,648 times
1
-
you load the ontology into a graph, add RDF triples and write the graph back to disk. That's it – UninformedUser Jun 12 '19 at 20:18
-
Thanks can you hint any coding example for this please – Nhqazi Jun 12 '19 at 20:36
-
Everything is in the docs, or not? Loading/Saving is a chapter: https://rdflib.readthedocs.io/en/stable/intro_to_parsing.html and adding triples is also a chapter: https://rdflib.readthedocs.io/en/stable/intro_to_creating_rdf.html so, I don't understand where you have problems? Are you not using documentations? – UninformedUser Jun 13 '19 at 05:11
-
Actually I had a look to these links,but I m confused as my ontology is in owl file .I understand I can open it using g.parse ,however the problem is then how can add instance.to give you clear picture ,I have a class activity having object property with other class person .now if I wish to add two instances of activity and person then how to do this – Nhqazi Jun 13 '19 at 07:24
-
1as I said, just add the RDF triples. An OWL ontology is nothing more than a set of RDF triples. and `rdflib` is made for RDF and SPARQL first. An "instance of" triple is just `
a – UninformedUser Jun 13 '19 at 07:39` -
clearly, for OWL and Python one would prefer using `owlready2` over `rdflib`, but that's another topic. You decided to use `rdflib`, thus, work on RDF level – UninformedUser Jun 13 '19 at 07:39
-
thanks, I am open to using any lib either rdflib or owlready2, however not sure if owlready2 support the adding data to the owl. any link or tutorial that think could be useful is appreciated. – Nhqazi Jun 13 '19 at 11:56
-
why should any API for OWL not allowing to add data? That's the whole use-case of those API, load, edit, search,save. owlready2 documentation is also online. If not, do what I suggested to do in rdflib. Both ways work simple and the examples are online the the docs. – UninformedUser Jun 13 '19 at 13:01