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


Python RDFS.range方法代码示例

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


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

示例1: get_sparql

# 需要导入模块: from rdflib import RDFS [as 别名]
# 或者: from rdflib.RDFS import range [as 别名]
def get_sparql(self):
        """
        Formats the query proposal as part of a sparql where clause.
        :return: String representation as sparql where clause part.
        """
        result = []
        subj_name = "?s" if not self.single else self.entity
        try:
            lit_name = "?{}{}".format(self.property.rsplit("/", 1)[1], self.range.rsplit("XMLSchema#")[1].capitalize())
        except IndexError:
            lit_name = "?{}".format(self.property.rsplit("/", 1)[-1])
        if self.explicit_class:
            result.append({
                "subject": subj_name,
                "predicate": "a",
                "object": self.cls
            })
        result.append({
            "subject": subj_name,
            "predicate": self.property.toPython(),
            "object": lit_name
        })
        return result 
开发者ID:Lambda-3,项目名称:aide,代码行数:25,代码来源:query_proposals.py

示例2: __init__

# 需要导入模块: from rdflib import RDFS [as 别名]
# 或者: from rdflib.RDFS import range [as 别名]
def __init__(self, cls, property, range, single=False, entity=None):
        self.cls = cls
        self.explicit_class = not "genClass" in cls.toPython()
        self.single = single if single else False
        if self.single:
            self.entity = entity
        if not self.explicit_class:
            self.extractor = re.findall("_(.*)", self.cls.rsplit("genClass", 1)[-1])[0]
        self.property = property
        self.range = range 
开发者ID:Lambda-3,项目名称:aide,代码行数:12,代码来源:query_proposals.py

示例3: format_for_indra

# 需要导入模块: from rdflib import RDFS [as 别名]
# 或者: from rdflib.RDFS import range [as 别名]
def format_for_indra(self, include_extractor=True):
        """
        Formats the query proposal for ranking with indra.
        :param include_extractor: Whether to include the source of the triple proposed.
        :return: String representation.
        """
        formatted_cls = self.cls.rsplit("/", 1)[-1]
        if not self.explicit_class:
            formatted_cls = formatted_cls.split("genClass")[-1].strip()
            if not include_extractor:
                formatted_cls = formatted_cls[1:].split("_")[-1]

        formatted_prop = self.property.rsplit("/", 1)[-1].strip()

        return to_space("{0} {1}".format(formatted_cls, formatted_prop))
    #
    # def __repr__(self):
    #     return repr(self.format_for_sparql())
    #
    # def format_for_sparql(self):
    #     """
    #     Formats the query proposal as sparql.
    #     :return: String representation as sparql where clause part.
    #     """
    #     result = []
    #     lit_name = "?{}".format(self.range.rsplit("XMLSchema#")[1])
    #     if self.explicit_class:
    #         result.append("?s a {}".format(self.cls))
    #     result.append("?s {prop} {lit}".format(prop=self.property, lit=lit_name))
    #     return result 
开发者ID:Lambda-3,项目名称:aide,代码行数:32,代码来源:query_proposals.py

示例4: range

# 需要导入模块: from rdflib import RDFS [as 别名]
# 或者: from rdflib.RDFS import range [as 别名]
def range(self):
        return rdflib.RDFS.Literal 
开发者ID:GiovanniBalestrieri,项目名称:Meiji,代码行数:4,代码来源:csv2rdf.py

示例5: calc_inference

# 需要导入模块: from rdflib import RDFS [as 别名]
# 或者: from rdflib.RDFS import range [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: rdfs2dot

# 需要导入模块: from rdflib import RDFS [as 别名]
# 或者: from rdflib.RDFS import range [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.range方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。