Update entity_graph.py
Browse files- entity_graph.py +11 -48
entity_graph.py
CHANGED
|
@@ -1,48 +1,11 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
for d in documents:
|
| 14 |
-
agency = d["agency"]
|
| 15 |
-
if agency not in seen:
|
| 16 |
-
nodes.append({"id": agency, "label": agency, "type": "agency"})
|
| 17 |
-
seen.add(agency)
|
| 18 |
-
|
| 19 |
-
for ent in extract_entities(d["text"]):
|
| 20 |
-
if ent not in seen:
|
| 21 |
-
nodes.append({"id": ent, "label": ent, "type": "entity"})
|
| 22 |
-
seen.add(ent)
|
| 23 |
-
links.append({"source": agency, "target": ent})
|
| 24 |
-
|
| 25 |
-
return {"nodes": nodes, "links": links}
|
| 26 |
-
|
| 27 |
-
def render_d3(graph):
|
| 28 |
-
return f"""
|
| 29 |
-
<div id="graph"></div>
|
| 30 |
-
<script src="https://d3js.org/d3.v7.min.js"></script>
|
| 31 |
-
<script>
|
| 32 |
-
const data = {json.dumps(graph)};
|
| 33 |
-
const w=600,h=400;
|
| 34 |
-
const svg=d3.select("#graph").append("svg").attr("width",w).attr("height",h);
|
| 35 |
-
const sim=d3.forceSimulation(data.nodes)
|
| 36 |
-
.force("link",d3.forceLink(data.links).id(d=>d.id))
|
| 37 |
-
.force("charge",d3.forceManyBody().strength(-200))
|
| 38 |
-
.force("center",d3.forceCenter(w/2,h/2));
|
| 39 |
-
const link=svg.selectAll("line").data(data.links).enter().append("line").attr("stroke","#999");
|
| 40 |
-
const node=svg.selectAll("circle").data(data.nodes).enter().append("circle")
|
| 41 |
-
.attr("r",6).attr("fill","#4f46e5");
|
| 42 |
-
sim.on("tick",()=>{
|
| 43 |
-
link.attr("x1",d=>d.source.x).attr("y1",d=>d.source.y)
|
| 44 |
-
.attr("x2",d=>d.target.x).attr("y2",d=>d.target.y);
|
| 45 |
-
node.attr("cx",d=>d.x).attr("cy",d=>d.y);
|
| 46 |
-
});
|
| 47 |
-
</script>
|
| 48 |
-
"""
|
|
|
|
| 1 |
+
FOIA_REQUESTS = []
|
| 2 |
+
|
| 3 |
+
def add_foia_request(agency, subject, status):
|
| 4 |
+
req = {
|
| 5 |
+
"id": len(FOIA_REQUESTS),
|
| 6 |
+
"agency": agency,
|
| 7 |
+
"subject": subject,
|
| 8 |
+
"status": status
|
| 9 |
+
}
|
| 10 |
+
FOIA_REQUESTS.append(req)
|
| 11 |
+
return FOIA_REQUESTS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|