当前位置: 首页>>代码示例>>Python>>正文


Python RDFS.subClassOf方法代码示例

本文整理汇总了Python中rdflib.RDFS.subClassOf方法的典型用法代码示例。如果您正苦于以下问题:Python RDFS.subClassOf方法的具体用法?Python RDFS.subClassOf怎么用?Python RDFS.subClassOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rdflib.RDFS的用法示例。


在下文中一共展示了RDFS.subClassOf方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: read_sub_class_of

# 需要导入模块: from rdflib import RDFS [as 别名]
# 或者: from rdflib.RDFS import subClassOf [as 别名]
def read_sub_class_of():
    sub_class_of = {}
    g = Graph()
    g.parse("dbpedia_2016-04.nt", format="nt")
    for s, o in g.subject_objects(RDFS.subClassOf):
        str_s = str(s)
        str_o = str(o)
        if str_s.startswith('http://dbpedia.org/ontology/') and str_o.startswith('http://dbpedia.org/ontology/'):
            sub_class_of[str_s] = str_o
    return sub_class_of 
开发者ID:sven-h,项目名称:webisalod,代码行数:12,代码来源:13_analyse_results.py

示例2: getSubClasses

# 需要导入模块: from rdflib import RDFS [as 别名]
# 或者: from rdflib.RDFS import subClassOf [as 别名]
def getSubClasses(self, cls):
        return self.ontology.transitive_subjects(RDFS.subClassOf, cls) 
开发者ID:conversence,项目名称:idealoom,代码行数:4,代码来源:inference.py

示例3: getSuperClasses

# 需要导入模块: from rdflib import RDFS [as 别名]
# 或者: from rdflib.RDFS import subClassOf [as 别名]
def getSuperClasses(self, cls):
        return self.ontology.transitive_objects(cls, RDFS.subClassOf) 
开发者ID:conversence,项目名称:idealoom,代码行数:4,代码来源:inference.py

示例4: enrichOntology

# 需要导入模块: from rdflib import RDFS [as 别名]
# 或者: from rdflib.RDFS import subClassOf [as 别名]
def enrichOntology(self):
        graph = self.rich_ontology = GraphOverlay(self.ontology)
        self.addTransitiveClosure(graph, RDFS.subPropertyOf)
        self.addTransitiveClosure(graph, RDFS.subClassOf)
        self.addInstanceStatements(graph, RDFS.Class, RDFS.subClassOf)
        self.addInstanceStatements(graph, RDF.Property, RDFS.subPropertyOf)
        return graph 
开发者ID:conversence,项目名称:idealoom,代码行数:9,代码来源:inference.py

示例5: calc_inference

# 需要导入模块: from rdflib import RDFS [as 别名]
# 或者: from rdflib.RDFS import subClassOf [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) 
开发者ID:conversence,项目名称:idealoom,代码行数:29,代码来源:inference.py

示例6: getDirectSubClasses

# 需要导入模块: from rdflib import RDFS [as 别名]
# 或者: from rdflib.RDFS import subClassOf [as 别名]
def getDirectSubClasses(self, cls):
        return self.base_ontology.subjects(RDFS.subClassOf, cls) 
开发者ID:conversence,项目名称:idealoom,代码行数:4,代码来源:inference.py

示例7: rdfs2dot

# 需要导入模块: from rdflib import RDFS [as 别名]
# 或者: from rdflib.RDFS import subClassOf [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") 
开发者ID:GiovanniBalestrieri,项目名称:Meiji,代码行数:62,代码来源:rdfs2dot.py


注:本文中的rdflib.RDFS.subClassOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。