INLEXIO commited on
Commit
00e008b
·
verified ·
1 Parent(s): 132ef2e

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +15 -3
src/streamlit_app.py CHANGED
@@ -615,11 +615,23 @@ if st.session_state.works:
615
  # Create clickable topic links if enabled
616
  if link_topics and top_topics:
617
  topic_list = [t for t, _ in profile['topics'].most_common(5)]
618
- # Create OpenAlex search links for each topic
619
  linked_topics = []
620
  for topic in topic_list:
621
- topic_encoded = topic.replace(' ', '+')
622
- link = f'<a href="https://openalex.org/topics?search={topic_encoded}" target="_blank">{topic}</a>'
 
 
 
 
 
 
 
 
 
 
 
 
623
  linked_topics.append(link)
624
  top_topics_display = ', '.join(linked_topics)
625
  else:
 
615
  # Create clickable topic links if enabled
616
  if link_topics and top_topics:
617
  topic_list = [t for t, _ in profile['topics'].most_common(5)]
618
+ # Create OpenAlex works filter links using stored topic IDs
619
  linked_topics = []
620
  for topic in topic_list:
621
+ # Get the topic ID if we have it
622
+ topic_id = profile['topic_ids'].get(topic, '')
623
+ if topic_id:
624
+ # Extract just the ID (e.g., "T12345" from full URL or already formatted)
625
+ if '/' in topic_id:
626
+ topic_id = topic_id.split('/')[-1]
627
+ # Convert to lowercase for the filter (e.g., T10316 -> t10316)
628
+ topic_id_lower = topic_id.lower()
629
+ # Link to works filtered by this topic
630
+ link = f'<a href="https://openalex.org/works?filter=primary_topic.id:{topic_id_lower}" target="_blank">{topic}</a>'
631
+ else:
632
+ # Fallback to search if no ID available
633
+ topic_encoded = topic.replace(' ', '+')
634
+ link = f'<a href="https://openalex.org/topics?search={topic_encoded}" target="_blank">{topic}</a>'
635
  linked_topics.append(link)
636
  top_topics_display = ', '.join(linked_topics)
637
  else: