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


Python RDFS.domain方法代码示例

本文整理汇总了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) 
开发者ID:Lambda-3,项目名称:aide,代码行数:12,代码来源:query_proposals.py

示例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) 
开发者ID:conversence,项目名称:idealoom,代码行数:29,代码来源:inference.py

示例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") 
开发者ID:GiovanniBalestrieri,项目名称:Meiji,代码行数:62,代码来源:rdfs2dot.py


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