Example #1
0
def neo4j_upload_wrapper(
    inputs: List[str],
    input_format: str,
    input_compression: str,
    uri: str,
    username: str,
    password: str,
    stream: bool,
    node_filters: Tuple[str, str],
    edge_filters: Tuple[str, str],
):
    """
    Upload a set of nodes/edges to a Neo4j database.
    \f

    Parameters
    ----------
    inputs: List[str]
        A list of files that contains nodes/edges
    input_format: str
        The input format
    input_compression: str
        The input compression type
    uri: str
        The full HTTP address for Neo4j database
    username: str
        Username for authentication
    password: str
        Password for authentication
    stream: bool
        Whether to parse input as a stream
    node_filters: Tuple[str, str]
        Node filters
    edge_filters: Tuple[str, str]
        Edge filters

    """
    try:
        neo4j_upload(
            inputs,
            input_format,
            input_compression,
            uri,
            username,
            password,
            stream,
            node_filters,
            edge_filters,
        )
        exit(0)
    except Exception as nue:
        get_logger().error(f"kgx.neo4j_upload error: {str(nue)}")
        exit(1)
Example #2
0
def test_neo4j_download(clean_slate):
    """
    Test download from Neo4j.
    """
    inputs = [
        os.path.join(RESOURCE_DIR, 'graph_nodes.tsv'),
        os.path.join(RESOURCE_DIR, 'graph_edges.tsv'),
    ]
    output = os.path.join(TARGET_DIR, 'neo_download')
    # upload
    t1 = neo4j_upload(
        inputs=inputs,
        input_format='tsv',
        input_compression=None,
        uri=DEFAULT_NEO4J_URL,
        username=DEFAULT_NEO4J_USERNAME,
        password=DEFAULT_NEO4J_PASSWORD,
        stream=False,
    )
    t2 = neo4j_download(
        uri=DEFAULT_NEO4J_URL,
        username=DEFAULT_NEO4J_USERNAME,
        password=DEFAULT_NEO4J_PASSWORD,
        output=output,
        output_format='tsv',
        output_compression=None,
        stream=False,
    )
    assert os.path.exists(f"{output}_nodes.tsv")
    assert os.path.exists(f"{output}_edges.tsv")
    assert t1.store.graph.number_of_nodes() == t2.store.graph.number_of_nodes()
    assert t1.store.graph.number_of_edges() == t2.store.graph.number_of_edges()
Example #3
0
def test_neo4j_download(clean_database):
    """
    Test download from Neo4j.
    """
    inputs = [
        os.path.join(RESOURCE_DIR, "graph_nodes.tsv"),
        os.path.join(RESOURCE_DIR, "graph_edges.tsv"),
    ]
    output = os.path.join(TARGET_DIR, "neo_download")
    # upload
    t1 = neo4j_upload(
        inputs=inputs,
        input_format="tsv",
        input_compression=None,
        uri=DEFAULT_NEO4J_URL,
        username=DEFAULT_NEO4J_USERNAME,
        password=DEFAULT_NEO4J_PASSWORD,
        stream=False,
    )
    t2 = neo4j_download(
        uri=DEFAULT_NEO4J_URL,
        username=DEFAULT_NEO4J_USERNAME,
        password=DEFAULT_NEO4J_PASSWORD,
        output=output,
        output_format="",
        output_compression=None,
        stream=False,
    )
    assert os.path.exists(f"{output}_nodes.tsv")
Example #4
0
def test_neo4j_upload(clean_slate):
    """
    Test upload to Neo4j.
    """
    inputs = [
        os.path.join(RESOURCE_DIR, 'graph_nodes.tsv'),
        os.path.join(RESOURCE_DIR, 'graph_edges.tsv'),
    ]
    # upload
    t = neo4j_upload(
        inputs,
        'tsv',
        None,
        uri=DEFAULT_NEO4J_URL,
        username=DEFAULT_NEO4J_USERNAME,
        password=DEFAULT_NEO4J_PASSWORD,
        stream=False,
    )
    assert t.store.graph.number_of_nodes() == 512
    assert t.store.graph.number_of_edges() == 532