RDFLib:如何在Python中创建本体?

问题描述 投票:3回答:1

我正在使用rdflib中的Python定义城市系统的本体。我定义了class urbanSystemsubClass 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最好是urbanSystem并命名为Paris的最佳方式是

这就是我在做什么。

g.add( (label, RDF.type, myOntology.urbanSystem) )
g.add( (label, myOntology.name, Literal['Paris']) )
python rdf ontology rdfs
1个回答
0
投票

您将name定义为类,然后将其用作对象属性。您需要

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

否则看起来还可以

© www.soinside.com 2019 - 2024. All rights reserved.