-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_queries.py
More file actions
38 lines (28 loc) · 1.06 KB
/
Copy pathrun_queries.py
File metadata and controls
38 lines (28 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import json
INDEX_FILE = "index.json"
def load_index():
with open(INDEX_FILE, "r", encoding="utf-8") as f:
return json.load(f)
def run_query(term, index):
term = term.lower()
return set(index["index"].get(term, {}).keys())
def main():
data = load_index()
# Queries
sustainability_docs = run_query("sustainability", data)
waste_docs = run_query("waste", data)
# Stats
both_docs = sustainability_docs.intersection(waste_docs)
my_collection = sustainability_docs.union(waste_docs)
# Report
print("\n===== QUERY RESULTS =====")
print(f"Sustainability docs: {len(sustainability_docs)}")
print(f"Waste docs: {len(waste_docs)}")
print(f"Documents in BOTH: {len(both_docs)}")
# Save My-collection
with open("my_collection.json", "w", encoding="utf-8") as f:
json.dump(list(my_collection), f, indent=2)
print("\nMy-collection saved to my_collection.json")
print(f"Total documents in My-collection: {len(my_collection)}")
if __name__ == "__main__":
main()