Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding ability to generate node/edge count reports #135

Open
glass-ships opened this issue May 3, 2024 · 0 comments
Open

Consider adding ability to generate node/edge count reports #135

glass-ships opened this issue May 3, 2024 · 0 comments

Comments

@glass-ships
Copy link
Collaborator

We could use duckdb for this.

An example, as used in the cookiecutter-monarch-ingest:

from pathlib import Path

import duckdb

nodes_file = "output/{{ cookiecutter.__ingest_name }}_nodes.tsv"
edges_file = "output/{{ cookiecutter.__ingest_name }}_edges.tsv"


# Nodes
if Path(nodes_file).exists():
    query = f"""
    SELECT category, split_part(id, ':', 1) as prefix, count(*)
    FROM '{nodes_file}'
    GROUP BY all
    ORDER BY all
    """
    duckdb.sql(f"copy ({query}) to 'output/{{ cookiecutter.__ingest_name }}_nodes_report.tsv' (header, delimiter '\t')")

# Edges
if Path(edges_file).exists():
    query = f"""
    SELECT category, split_part(subject, ':', 1) as subject_prefix, predicate,
    split_part(object, ':', 1) as object_prefix, count(*)
    FROM '{edges_file}'
    GROUP BY all
    ORDER BY all
    """
    duckdb.sql(f"copy ({query}) to 'output/{{ cookiecutter.__ingest_name }}_edges_report.tsv' (header, delimiter '\t')")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant