Skip to content

adds custom topic selection #6

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions arxiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,27 @@ def cmd_query (
max_items:
optional - maximum items requested per API call
"""



trends = Trends(kg_path=kg_path)

if query not in trends.topics:
new_topic = f'''derw:topic_{query.replace(" ", "_")} a derw:Topic ;
skos:broader <https://derwen.ai/d/computer_science> ;
skos:closeMatch lcsh:sh2002004605,
<https://networkx.org/documentation/stable/reference/algorithms/index.html> ;
skos:definition ""@en ;
skos:prefLabel "{query}"@en .\n'''

#append new topic to ttl file
with open(kg_path, "a") as f:
f.write(new_topic)
f.close()

#reload the ttl file
trends = Trends(kg_path=kg_path)

# search parameters
page_items = 100

Expand All @@ -358,8 +377,6 @@ def cmd_query (

for date, node in tqdm(hit_iter, desc="Hits"):
trends.kg.add(node, trends.kg.get_ns("derw").fromQuery, trends.topics[query])
# TODO: what if query new?
#print(query, date, node)

# persist the metadata
trends.save_kg()
Expand Down Expand Up @@ -472,7 +489,7 @@ def cmd_analyze (
def cmd_visualize (
csv_file: str = "arxiv.csv",
png_file: str = "arxiv.png",
start_date: str = "2020-01-01",
start_date: str = "2010-01-01",
) -> None:
"""
Visualize the article trends.
Expand Down