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']) )