コード例 #1
0
ファイル: test_rdf_utils.py プロジェクト: deepakunni3/kgx
def test_infer_category(query):
    """
    Test inferring of biolink category for a given IRI.
    """
    graph = Graph()
    graph.parse(os.path.join(RESOURCE_DIR, "goslim_generic.owl"))
    [c] = infer_category(query[0], graph)
    assert c == query[1]
コード例 #2
0
ファイル: rdf_transformer.py プロジェクト: vemonet/kgx
    def load_node_attributes(self, rdfgraph: rdflib.Graph) -> None:
        """
        This method loads the properties of nodes into networkx.MultiDiGraph
        As there can be many values for a single key, all properties are lists by default.

        This method assumes that ``RdfTransformer.load_edges()`` has been called, and that all nodes
        have had their IRI as an attribute.

        Parameters
        ----------
        rdfgraph: rdflib.Graph
            Graph containing nodes and edges

        """
        logging.info(
            "Loading node attributes from rdflib.Graph into networkx.MultiDiGraph"
        )
        with click.progressbar(self.graph.nodes(data=True),
                               label='Progress') as bar:
            for n, data in bar:
                print(n, data)
                if 'id' not in data:
                    data['id'] = n
                if 'iri' in data:
                    uriref = URIRef(data['iri'])
                else:
                    provided_by = self.graph_metadata.get('provided_by')
                    logging.warning(
                        "No 'iri' property for {} provided by {}".format(
                            n, provided_by))
                    continue

                for s, p, o in rdfgraph.triples((uriref, None, None)):
                    if p in property_mapping:
                        # predicate corresponds to a property on subject
                        if not (isinstance(s, rdflib.term.BNode)
                                and isinstance(o, rdflib.term.BNode)):
                            # neither subject nor object is a BNode
                            if isinstance(o, rdflib.term.Literal):
                                o = o.value
                            self.add_node_attribute(uriref, key=p, value=o)
                    elif isinstance(o, rdflib.term.Literal):
                        # object is a Literal
                        # i.e. predicate corresponds to a property on subject
                        self.add_node_attribute(uriref, key=p, value=o.value)

                categories = infer_category(uriref, rdfgraph)
                logging.debug("Inferred '{}' as category for node '{}'".format(
                    categories, uriref))
                for category in categories:
                    self.add_node_attribute(uriref,
                                            key='category',
                                            value=category)
コード例 #3
0
def test_infer_category(query):
    graph = Graph()
    graph.parse(os.path.join(resource_dir, 'goslim_generic.owl'))
    [c] = infer_category(query[0], graph)
    assert c == query[1]