Beispiel #1
0
def ground(
    graph: BELGraph,
    remove_ungrounded: bool = True,
    skip_namespaces: Optional[Collection[str]] = None,
) -> BELGraph:
    """Ground all entities in a BEL graph."""
    j = to_nodelink(graph)
    ground_nodelink(j, skip_namespaces=skip_namespaces)
    graph = from_nodelink(j)

    remove_unused_annotation_metadata(graph)

    if remove_ungrounded:
        ungrounded_nodes = {
            node
            for node in get_ungrounded_nodes(graph) if
            not isinstance(node, BaseConcept) or node.namespace not in NO_NAMES
        }
        graph.remove_nodes_from(ungrounded_nodes)
        graph.namespace_url.clear()
        graph.namespace_pattern.clear()
        graph.namespace_pattern.update(
            {namespace: '.*'
             for namespace in get_namespaces(graph)})

        graph.annotation_url.clear()
        graph.annotation_pattern.clear()
        graph.annotation_list.clear()
        graph.annotation_pattern.update(
            {annotation: '.*'
             for annotation in get_annotations(graph)})

    return graph
Beispiel #2
0
    def test_convert_json(self, mock_get):
        with self.runner.isolated_filesystem():
            test_json = os.path.abspath('test.json')

            args = [
                'convert', '--path', test_bel_thorough, '--json', test_json,
                '--connection', self.connection, '--allow-nested'
            ]

            result = self.runner.invoke(cli.main, args)
            self.assertEqual(0, result.exit_code, msg=result.exc_info)

            with open(test_json) as f:
                self.bel_thorough_reconstituted(from_nodelink(json.load(f)))