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


Python RDFS.subClassOf方法代码示例

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


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

示例1: hpo_to_tree

# 需要导入模块: from rdflib.namespace import RDFS [as 别名]
# 或者: from rdflib.namespace.RDFS import subClassOf [as 别名]
def hpo_to_tree(cls, hpo_terms, hpo_graph, tree, path):
    tree_path = copy.copy(path)
    tree_path.append(cls)
    curie_util = CurieUtil(curie_map.get())
    if cls not in hpo_terms:
        hpo_terms[cls] = {
            'label': hpo_graph.label(URIRef(curie_util.get_uri(cls)))
        }
        parents = hpo_graph.objects(URIRef(curie_util.get_uri(cls)), RDFS.subClassOf)
        hpo_terms[cls]['parents'] = len(list(parents))

        lay_person = get_lay_person(cls, hpo_graph)
        hpo_terms[cls]["lay_person"] = lay_person

    # Traverse the tree to get to the input class
    position = tree[tree_path[0]]
    for term in tree_path[1:]:
        position = position[term]

    for sub_class in hpo_graph.subjects(RDFS.subClassOf, URIRef(curie_util.get_uri(tree_path[-1]))):
        curie = curie_util.get_curie(sub_class).replace("OBO:HP_", "HP:")
        position[curie] = {}
        hpo_to_tree(curie, hpo_terms, hpo_graph, tree, tree_path) 
开发者ID:monarch-initiative,项目名称:dipper,代码行数:25,代码来源:treeify-hpo.py

示例2: rdfgraph_to_ontol

# 需要导入模块: from rdflib.namespace import RDFS [as 别名]
# 或者: from rdflib.namespace.RDFS import subClassOf [as 别名]
def rdfgraph_to_ontol(rg):
    """
    Return an Ontology object from an rdflib graph object

    Status: Incomplete
    """
    digraph = networkx.MultiDiGraph()
    from rdflib.namespace import RDF
    label_map = {}
    for c in rg.subjects(RDF.type, OWL.Class):
        cid = contract_uri_wrap(c)
        logger.info("C={}".format(cid))
        for lit in rg.objects(c, RDFS.label):
            label_map[cid] = lit.value
            digraph.add_node(cid, label=lit.value)
        for s in rg.objects(c, RDFS.subClassOf):
            # todo - blank nodes
            sid = contract_uri_wrap(s)
            digraph.add_edge(sid, cid, pred='subClassOf')

    logger.info("G={}".format(digraph))
    payload = {
        'graph': digraph,
        #'xref_graph': xref_graph,
        #'graphdoc': obographdoc,
        #'logical_definitions': logical_definitions
    }
            
    ont = Ontology(handle='wd', payload=payload)
    return ont 
开发者ID:biolink,项目名称:ontobio,代码行数:32,代码来源:rdflib_bridge.py

示例3: update_load_vocabulary

# 需要导入模块: from rdflib.namespace import RDFS [as 别名]
# 或者: from rdflib.namespace.RDFS import subClassOf [as 别名]
def update_load_vocabulary(self, vocab_file_uri, vocab_uri=False):
        """ Loads, parses, and stores a vocabulary or ontology
        Saves labels for entities referenced in the vocabulary, also saves
        hierarchical relationships for these entities in the database
        for use in formulating Solr index """
        output = {}
        if vocab_uri is not False:
            self.vocabulary_uri = vocab_uri
        self.load_parse_vocabulary(vocab_file_uri)
        output['labels'] = self.save_entity_labels()
        output['subClasses'] = self.save_hierarchy('rdfs:subClassOf')
        output['subProperties'] = self.save_hierarchy('rdfs:subPropertyOf')
        output['hasIcons'] = self.save_icons()
        output['sorting'] = self.save_sort()
        return output 
开发者ID:ekansa,项目名称:open-context-py,代码行数:17,代码来源:models.py

示例4: save_icons

# 需要导入模块: from rdflib.namespace import RDFS [as 别名]
# 或者: from rdflib.namespace.RDFS import subClassOf [as 别名]
def save_icons(self, predicate_uri='oc-gen:hasIcon'):
        """ Saves icons in the general Open Context namespace """
        data = False
        if(self.graph is not False and self.vocabulary_uri is not False):
            data = []
            if(self.replace_old):
                # delete old relations from this vocabulary using this predicate
                LinkAnnotation.objects.filter(source_id=self.vocabulary_uri,
                                              predicate_uri=predicate_uri).delete()
            if(predicate_uri == 'oc-gen:hasIcon'):
                # for subClassOf predicates
                full_pred_uri = URImanagement.convert_prefix_to_full_uri(predicate_uri)
                icon_pred = URIRef(full_pred_uri)
                for s, p, o in self.graph.triples((None,
                                                   icon_pred,
                                                   None)):
                    subject_uri = s.__str__()  # get the URI of the subject as a string
                    object_uri = o.__str__()  # get the URI of the object as a string
                    act_t = {'s': subject_uri,
                             'o': object_uri}
                    if(subject_uri != object_uri):
                        data.append(act_t)
            if(len(data) > 0):
                for act_t in data:
                    newr = LinkAnnotation()
                    # make the subject a prefixed URI if common
                    newr.subject = URImanagement.prefix_common_uri(act_t['s'])
                    newr.subject_type = 'uri'
                    newr.project_uuid = '0'
                    newr.source_id = self.vocabulary_uri
                    newr.predicate_uri = predicate_uri
                    newr.object_uri = act_t['o']
                    newr.save()
        return data 
开发者ID:ekansa,项目名称:open-context-py,代码行数:36,代码来源:models.py

示例5: infer_category

# 需要导入模块: from rdflib.namespace import RDFS [as 别名]
# 或者: from rdflib.namespace.RDFS import subClassOf [as 别名]
def infer_category(iri: URIRef, rdfgraph:rdflib.Graph) -> List[str]:
    """
    Infer category for a given iri by traversing rdfgraph.

    Parameters
    ----------
    iri: rdflib.term.URIRef
        IRI
    rdfgraph: rdflib.Graph
        A graph to traverse

    Returns
    -------
    List[str]
        A list of category corresponding to the given IRI

    """
    category = None
    subj = None
    closure = list(rdfgraph.transitive_objects(iri, URIRef(RDFS.subClassOf)))
    category = [top_level_terms[x] for x in closure if x in top_level_terms.keys()]
    if category:
        logging.debug("Inferred category as {} based on transitive closure over 'subClassOf' relation".format(category))
    else:
        subj = closure[-1]
        if subj == iri:
            return category
        subject_curie = contract(subj)
        if '_' in subject_curie:
            fixed_curie = subject_curie.split(':', 1)[1].split('_', 1)[1]
            logging.warning("Malformed CURIE {} will be fixed to {}".format(subject_curie, fixed_curie))
            subject_curie = fixed_curie
        cls = get_curie_lookup_service()
        category = get_category_via_superclass(cls.ontology_graph, subject_curie)
    return category 
开发者ID:NCATS-Tangerine,项目名称:kgx,代码行数:37,代码来源:rdf_utils.py

示例6: test_rdfs_classes

# 需要导入模块: from rdflib.namespace import RDFS [as 别名]
# 或者: from rdflib.namespace.RDFS import subClassOf [as 别名]
def test_rdfs_classes():
    rdf = Graph()
    a, b, c, x = BNode(), BNode(), BNode(), BNode()

    rdf.add((a, RDFS.subClassOf, b))
    rdf.add((b, RDFS.subClassOf, c))
    rdf.add((x, RDF.type, a))

    skosify.infer.rdfs_classes(rdf)

    assert (x, RDF.type, b) in rdf
    assert (x, RDF.type, c) in rdf 
开发者ID:NatLibFi,项目名称:Skosify,代码行数:14,代码来源:test_infer.py

示例7: save_hierarchy

# 需要导入模块: from rdflib.namespace import RDFS [as 别名]
# 或者: from rdflib.namespace.RDFS import subClassOf [as 别名]
def save_hierarchy(self, predicate_uri='rdfs:subClassOf'):
        """ Saves hierarchic relations from a vocabulary,
        defaulting to subClassOf predicates """
        data = False
        if(self.graph is not False and self.vocabulary_uri is not False):
            data = []
            if(self.replace_old):
                # delete old relations from this vocabulary using this predicate
                LinkAnnotation.objects.filter(source_id=self.vocabulary_uri,
                                              predicate_uri=predicate_uri).delete()
            if(predicate_uri == 'rdfs:subClassOf'):
                # for subClassOf predicates
                for s, p, o in self.graph.triples((None,
                                                   RDFS.subClassOf,
                                                   None)):
                    subject_uri = s.__str__()  # get the URI of the subject as a string
                    object_uri = o.__str__()  # get the URI of the object as a string
                    act_t = {'s': subject_uri,
                             'o': object_uri}
                    if(subject_uri != object_uri):
                        data.append(act_t)
            elif(predicate_uri == 'rdfs:subPropertyOf'):
                # for subPropertyOf predicates
                for s, p, o in self.graph.triples((None,
                                                   RDFS.subPropertyOf,
                                                   None)):
                    subject_uri = s.__str__()  # get the URI of the subject as a string
                    object_uri = o.__str__()  # get the URI of the object as a string
                    act_t = {'s': subject_uri,
                             'o': object_uri}
                    if(subject_uri != object_uri):
                        data.append(act_t)
            if(len(data) > 0):
                for act_t in data:
                    newr = LinkAnnotation()
                    # make the subject a prefixed URI if common
                    newr.subject = URImanagement.prefix_common_uri(act_t['s'])
                    newr.subject_type = 'uri'
                    newr.project_uuid = '0'
                    newr.source_id = self.vocabulary_uri
                    newr.predicate_uri = predicate_uri
                    newr.object_uri = act_t['o']
                    newr.save()
        return data 
开发者ID:ekansa,项目名称:open-context-py,代码行数:46,代码来源:models.py

示例8: load_networkx_graph

# 需要导入模块: from rdflib.namespace import RDFS [as 别名]
# 或者: from rdflib.namespace.RDFS import subClassOf [as 别名]
def load_networkx_graph(self, rdfgraph: rdflib.Graph = None, predicates: Set[URIRef] = None, **kwargs) -> None:
        """
        Walk through the rdflib.Graph and load all required triples into networkx.MultiDiGraph

        By default this method loads the following predicates,
            - ``RDFS.subClassOf``
            - ``OWL.sameAs``
            - ``OWL.equivalentClass``
            - ``is_about`` (IAO:0000136)
            - ``has_subsequence`` (RO:0002524)
            - ``is_subsequence_of`` (RO:0002525)

        This behavior can be overridden by providing a list of rdflib.URIRef that ought to be loaded
        via the ``predicates`` parameter.

        Parameters
        ----------
        rdfgraph: rdflib.Graph
            Graph containing nodes and edges
        predicates: list
            A list of rdflib.URIRef representing predicates to be loaded
        kwargs: dict
            Any additional arguments

        """
        if predicates is None:
            predicates = set()
            predicates = predicates.union(self.OWL_PREDICATES, [self.is_about, self.is_subsequence_of, self.has_subsequence])

        triples = rdfgraph.triples((None, None, None))
        logging.info("Loading from rdflib.Graph to networkx.MultiDiGraph")
        with click.progressbar(list(triples), label='Progress') as bar:
            for s, p, o in bar:
                if (p == self.is_about) and (p in predicates):
                    logging.debug("Loading is_about predicate")
                    # if predicate is 'is_about' then treat object as publication
                    self.add_node_attribute(o, key=s, value='publications')
                elif (p == self.is_subsequence_of) and (p in predicates):
                    logging.debug("Loading is_subsequence_of predicate")
                    # if predicate is 'is_subsequence_of'
                    self.add_edge(s, o, self.is_subsequence_of)
                elif (p == self.has_subsequence) and (p in predicates):
                    logging.debug("Loading has_subsequence predicate")
                    # if predicate is 'has_subsequence', interpret the inverse relation 'is_subsequence_of'
                    self.add_edge(o, s, self.is_subsequence_of)
                elif any(p.lower() == x.lower() for x in predicates):
                    logging.debug("Loading {} predicate".format(p))
                    self.add_edge(s, o, p) 
开发者ID:NCATS-Tangerine,项目名称:kgx,代码行数:50,代码来源:rdf_transformer.py


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