本文整理汇总了Python中rdflib.RDFS.domain方法的典型用法代码示例。如果您正苦于以下问题:Python RDFS.domain方法的具体用法?Python RDFS.domain怎么用?Python RDFS.domain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdflib.RDFS
的用法示例。
在下文中一共展示了RDFS.domain方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_domains_of_property
# 需要导入模块: from rdflib import RDFS [as 别名]
# 或者: from rdflib.RDFS import domain [as 别名]
def get_domains_of_property(property):
"""
Gets the domain classes of a given property.
:param property: Property to get the domains for.
:return: domain classes of given property.
"""
if not _qp:
__init()
return _qp.get_domains_of_property(property)
示例2: calc_inference
# 需要导入模块: from rdflib import RDFS [as 别名]
# 或者: from rdflib.RDFS import domain [as 别名]
def calc_inference(self, graph):
first = changes = True
while first or changes:
if first or changes:
# {?P @has owl:inverseOf ?I. ?S ?P ?O} => {?O ?I ?S}.
changes = self.add_inverses(graph)
if first or changes:
# {?P @has rdfs:subPropertyOf ?R. ?S ?P ?O} => {?S ?R ?O}.
# {?P @has owl:subPropertyOf ?R. ?S ?P ?O} => {?S ?R ?O}.
changes = self.add_inheritance(graph, RDF.Property, RDFS.subPropertyOf)
first = False
# loop because inheritance could add inverses.
# {?P @has rdfs:domain ?C. ?S ?P ?O} => {?S a ?C}.
for (p, _, c) in self.ontology.triples((None, RDFS.domain, None)):
rs = {s for (s, _, o) in graph.triples((None, p, None))}
for r in rs:
t = (r, RDF.type, c)
if t not in graph:
graph.add(t)
# {?P @has rdfs:range ?C. ?S ?P ?O} => {?O a ?C}.
for (p, _, c) in self.ontology.triples((None, RDFS.range, None)):
rs = {o for (s, _, o) in graph.triples((None, p, None))}
for r in rs:
t = (r, RDF.type, c)
if t not in graph:
graph.add(t)
self.add_inheritance(graph, RDFS.Class, RDFS.subClassOf)
示例3: rdfs2dot
# 需要导入模块: from rdflib import RDFS [as 别名]
# 或者: from rdflib.RDFS import domain [as 别名]
def rdfs2dot(g, stream, opts={}):
"""
Convert the RDFS schema in a graph
writes the dot output to the stream
"""
fields = collections.defaultdict(set)
nodes = {}
def node(x):
if x not in nodes:
nodes[x] = "node%d" % len(nodes)
return nodes[x]
def label(x, g):
l = g.value(x, RDFS.label)
if l is None:
try:
l = g.namespace_manager.compute_qname(x)[2]
except:
pass # bnodes and some weird URIs cannot be split
return l
stream.write(u"digraph { \n node [ fontname=\"DejaVu Sans\" ] ; \n")
for x in g.subjects(RDF.type, RDFS.Class):
n = node(x)
for x, y in g.subject_objects(RDFS.subClassOf):
x = node(x)
y = node(y)
stream.write(u"\t%s -> %s [ color=%s ] ;\n" % (y, x, ISACOLOR))
for x in g.subjects(RDF.type, RDF.Property):
for a, b in itertools.product(
g.objects(x, RDFS.domain), g.objects(x, RDFS.range)):
if b in XSDTERMS or b == RDFS.Literal:
l = label(b, g)
if b == RDFS.Literal:
l = "literal"
fields[node(a)].add((label(x, g), l))
else:
# if a in nodes and b in nodes:
stream.write(
"\t%s -> %s [ color=%s, label=\"%s\" ];\n" % (
node(a), node(b), EDGECOLOR, label(x, g)))
for u, n in nodes.items():
stream.write(u"# %s %s\n" % (u, n))
f = [u"<tr><td align='left'>%s</td><td>%s</td></tr>" %
x for x in sorted(fields[n])]
opstr = u"%s [ shape=none, color=%s label=< <table color='#666666'" + \
u" cellborder=\"0\" cellspacing='0' border=\"1\"><tr>" + \
u"<td colspan=\"2\" bgcolor='grey'><B>%s</B></td>" + \
u"</tr>%s</table> > ] \n"
stream.write(opstr % (n, NODECOLOR, label(u, g), u"".join(f)))
stream.write("}\n")