我正在使用rdflib在Python中为城市系统定义一个本体。我定义了class urbanSystem和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))现在,我想将一个城市添加到我的本体中,例如Paris。
label = URIRef(myOntology["Paris"])Paris是一个名为Paris的urbanSystem,最好的说法是什么
这就是我要做的。
g.add( (label, RDF.type, myOntology.urbanSystem) )
g.add( (label, myOntology.name, Literal['Paris']) )发布于 2020-06-15 02:19:28
将名称定义为类,然后将其用作对象属性。你需要
g.add((name, RDF.type, OWL.ObjectProperty))否则看上去没问题
https://stackoverflow.com/questions/46449970
复制相似问题