Beispiel #1
0
def neo4j_download_wrapper(
    uri: str,
    username: str,
    password: str,
    output: str,
    output_format: str,
    output_compression: str,
    stream: bool,
    node_filters: Tuple,
    edge_filters: Tuple,
):
    """
    Download nodes and edges from Neo4j database.
    \f

    Parameters
    ----------
    uri: str
        Neo4j URI. For example, https://localhost:7474
    username: str
        Username for authentication
    password: str
        Password for authentication
    output: str
        Where to write the output (stdout, by default)
    output_format: str
        The output type (``tsv``, by default)
    output_compression: str
        The output compression type
    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_download(
            uri,
            username,
            password,
            output,
            output_format,
            output_compression,
            stream,
            node_filters,
            edge_filters,
        )
        exit(0)
    except Exception as nde:
        get_logger().error(f"kgx.neo4j_download error: {str(nde)}")
        exit(1)
Beispiel #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()
Beispiel #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")