Ejemplo n.º 1
0
def merge_wrapper(merge_config: str, source: List, destination: List,
                  processes: int):
    """
    Load nodes and edges from files and KGs, as defined in a config YAML, and merge them into a single graph.
    The merged graph can then be written to a local/remote Neo4j instance OR be serialized into a file.
    \f

    .. note::
        Everything here is driven by the ``merge-config`` YAML.

    Parameters
    ----------
    merge_config: str
        Merge config YAML
    source: List
        A list of source to load from the YAML
    destination: List
        A list of destination to write to, as defined in the YAML
    processes: int
        Number of processes to use

    """
    try:
        merge(merge_config, source, destination, processes)
        exit(0)
    except Exception as me:
        get_logger().error(f"kgx.merge error: {str(me)}")
        exit(1)
Ejemplo n.º 2
0
def test_merge2():
    """
    Transform selected source from test merge YAML and
    write selected destinations.
    """
    merge_config = os.path.join(RESOURCE_DIR, 'test-merge.yaml')
    merge(merge_config=merge_config, destination=['merged-graph-json'])
    assert os.path.join(TARGET_DIR, 'merged-graph.json')
Ejemplo n.º 3
0
def test_merge1():
    """
    Transform from test merge YAML.
    """
    merge_config = os.path.join(RESOURCE_DIR, 'test-merge.yaml')
    merge(merge_config=merge_config)
    assert os.path.join(TARGET_DIR, 'merged-graph_nodes.tsv')
    assert os.path.join(TARGET_DIR, 'merged-graph_edges.tsv')
    assert os.path.join(TARGET_DIR, 'merged-graph.json')
Ejemplo n.º 4
0
def load_and_merge(yaml_file: str, processes: int = 1) -> nx.MultiDiGraph:
    """Load and merge sources defined in the config YAML.

    Args:
        yaml_file: A string pointing to a KGX compatible config YAML.
        processes: Number of processes to use.

    Returns:
        networkx.MultiDiGraph: The merged graph.

    """
    merged_graph = merge(yaml_file, processes=processes)
    return merged_graph