Download entity_graph.py from GodsDevProject/FOIA_Declassified_Document_Search: direct link, hf CLI and curl.
- Browser
- Download file 586 Bytes
-
https://huggingface.co/spaces/GodsDevProject/FOIA_Declassified_Document_Search/resolve/main/entity_graph.py
- Command line
-
hf download hf://spaces/GodsDevProject/FOIA_Declassified_Document_Search/entity_graph.py
-
curl -L -o entity_graph.py https://huggingface.co/spaces/GodsDevProject/FOIA_Declassified_Document_Search/resolve/main/entity_graph.py
586 Bytes
| import networkx as nx | |
| from typing import List, Dict | |
| def build_entity_graph(docs: List[Dict]) -> Dict: | |
| G = nx.Graph() | |
| for d in docs: | |
| agency = d.get("agency", "Unknown") | |
| G.add_node(agency, group="agency") | |
| for token in d.get("content", "").split(): | |
| if token.isupper() and len(token) > 2: | |
| G.add_node(token, group="entity") | |
| G.add_edge(agency, token) | |
| return { | |
| "nodes": [{"id": n, "group": G.nodes[n]["group"]} for n in G.nodes], | |
| "links": [{"source": u, "target": v} for u, v in G.edges] | |
| } |