4

I am defining an ontology for Urban system using rdflib in Python. I defined the class urbanSystem and the subClass name.

import rdflib
from rdflib.graph import Graph, ConjunctiveGraph
from rdflib import Graph, URIRef, BNode, Literal
from rdflib import Namespace
from rdflib.namespace import OWL, RDF, RDFS, FOAF
myOntology =  Namespace("http://www.semanticweb.org/myOntology#")
g.bind("myOntology", myOntology)

# Create the graph 
g = Graph()
# Create the node to add to the Graph
urbanSystem = URIRef(myOntology["urbanSystem"])

# Add the OWL data to the graph
g.add((urbanSystem, RDF.type, OWL.Class))
g.add((urbanSystem, RDFS.subClassOf, OWL.Thing))

name = URIRef(myOntology["name"])
g.add((name, RDF.type, OWL.Class))
g.add((name, RDFS.subClassOf, urbanSystem))

Now I want to add a city to my ontology, for instance Paris.

label = URIRef(myOntology["Paris"])

what is the best way to say Paris is an urbanSystem and with name Paris

This is what I am doing.

g.add( (label, RDF.type, myOntology.urbanSystem) )
g.add( (label, myOntology.name, Literal['Paris']) )
emax
  • 6,965
  • 19
  • 74
  • 141
  • It seems you are still confusing OWL ontology with its RDF serialization… Also, there exist standard approachs to converting relational or tabular data to CSV. However, if you like rdflib, then probably you could try [this tool](https://github.com/RDFLib/rdflib/blob/master/rdflib/tools/csv2rdf.py). – Stanislav Kralin Sep 28 '17 at 10:07
  • @StanislavKralin what are the tools you are mentioning? Thank you for your comments. – emax Sep 28 '17 at 10:48
  • I mean rather approaches than tools... Look at https://www.w3.org/TR/csv2rdf/ and http://rml.io/. – Stanislav Kralin Sep 28 '17 at 12:24
  • What kind of editor/platform you use to do that? Moreover, what is my main error in the ontology definition over there? – emax Sep 28 '17 at 14:54
  • To be honest, I'm not bothering about CSV2RDF or RML implementations. Usually, I load CSV into relational database and then generate RDF via R2RML using ontop. Anyway, there should be tools that relieve you from writing CSV-RDF transformation by hand (e. g. [already mentioned](https://github.com/RDFLib/rdflib/blob/master/rdflib/tools/csv2rdf.py) one)... From the top of my desktop: one would load Excel spreadsheet into Protégé using the Cellfie plugin and then serialize an ontology into RDF. Or one would use OntoRefine that comes with GraphDB. – Stanislav Kralin Sep 28 '17 at 15:11
  • Thank you. I can create a PostgreSQL or MySQL database with the data I have. I just used `.csv` as an exmaple. I am new in the ontology world. Most of data I am facing with however are in tabular format. The transition from tabular data to RDF is still difficult to understand for me. – emax Sep 28 '17 at 15:21
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/155529/discussion-between-emax-and-stanislav-kralin). – emax Sep 28 '17 at 15:29

1 Answers1

0

You define name as a Class,but then use it as an Object Property. You need

g.add((name, RDF.type, OWL.ObjectProperty))

Otherwise looks OK

Alex J.
  • 187
  • 6