src/pybel/grounding.py
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
Ground all entities in a BEL graph.
Ground all entities in a BEL graph.
Ground all entities in a BEL graph .
def ground(
    graph: BELGraph,
    remove_ungrounded: bool = True,
    skip_namespaces: Optional[Collection[str]] = None,
) -> BELGraph:
    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
def ground ( graph : BELGraph , remove_ungrounded : bool = True , skip_namespaces : Optional [ Collection [ str ] ] = None , ) -> BELGraph : 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
Ground all entities in a BEL graph.
Ground all entities in a BEL graph .
"""Ground all entities in a BEL graph."""
graph
BELGraph
remove_ungrounded
bool
skip_namespaces
Optional[Collection[str]]