Spaces:
Sleeping
Sleeping
Muhan Gao
commited on
Commit
·
7720dc2
1
Parent(s):
844c063
Add citation-based sorting functionality
Browse files- Add sort_items_by_citations function for papers and clusters
- Support sorting by Total Citations and Total Influential Citations
- Default to descending order (highest first)
- Clean, minimal UI with single dropdown selector
- Improve user experience for exploring high-impact content
app.py
CHANGED
@@ -1082,6 +1082,53 @@ def display_cluster(item, path):
|
|
1082 |
# 创建一个分隔线
|
1083 |
st.markdown("<hr style='margin: 0.5rem 0; border-color: #eee;'>", unsafe_allow_html=True)
|
1084 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1085 |
def main():
|
1086 |
st.set_page_config(
|
1087 |
layout="wide",
|
@@ -1236,6 +1283,25 @@ def main():
|
|
1236 |
</div>
|
1237 |
""", unsafe_allow_html=True)
|
1238 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1239 |
# Back navigation button
|
1240 |
if st.session_state.path:
|
1241 |
if st.button('← Back', key='back_button'):
|
|
|
1082 |
# 创建一个分隔线
|
1083 |
st.markdown("<hr style='margin: 0.5rem 0; border-color: #eee;'>", unsafe_allow_html=True)
|
1084 |
|
1085 |
+
def sort_items_by_citations(items, sort_by="citation_count", reverse=True):
|
1086 |
+
"""
|
1087 |
+
Sort papers or clusters by citation metrics
|
1088 |
+
|
1089 |
+
Args:
|
1090 |
+
items: List of (item, path) tuples
|
1091 |
+
sort_by: "citation_count", "influential_citation_count", "avg_citations", "avg_influential_citations"
|
1092 |
+
reverse: True for descending (highest first), False for ascending
|
1093 |
+
|
1094 |
+
Returns:
|
1095 |
+
Sorted list of (item, path) tuples
|
1096 |
+
"""
|
1097 |
+
def get_sort_key(item_tuple):
|
1098 |
+
item, path = item_tuple
|
1099 |
+
|
1100 |
+
# For papers - get citation data from semantic_scholar
|
1101 |
+
if "paper_id" in item:
|
1102 |
+
semantic_scholar = item.get('semantic_scholar', {})
|
1103 |
+
if sort_by == "citation_count":
|
1104 |
+
return semantic_scholar.get('citationCount', 0)
|
1105 |
+
elif sort_by == "influential_citation_count":
|
1106 |
+
return semantic_scholar.get('influentialCitationCount', 0)
|
1107 |
+
else:
|
1108 |
+
# For papers, citation_count and avg_citations are the same
|
1109 |
+
return semantic_scholar.get('citationCount', 0)
|
1110 |
+
|
1111 |
+
# For clusters - calculate citation metrics
|
1112 |
+
else:
|
1113 |
+
metrics = calculate_citation_metrics(item)
|
1114 |
+
if sort_by == "citation_count":
|
1115 |
+
return metrics['total_citations']
|
1116 |
+
elif sort_by == "influential_citation_count":
|
1117 |
+
return metrics['total_influential_citations']
|
1118 |
+
elif sort_by == "avg_citations":
|
1119 |
+
return metrics['avg_citations']
|
1120 |
+
elif sort_by == "avg_influential_citations":
|
1121 |
+
return metrics['avg_influential_citations']
|
1122 |
+
else:
|
1123 |
+
return metrics['total_citations']
|
1124 |
+
|
1125 |
+
try:
|
1126 |
+
return sorted(items, key=get_sort_key, reverse=reverse)
|
1127 |
+
except Exception as e:
|
1128 |
+
# If sorting fails, return original list
|
1129 |
+
print(f"Sorting failed: {e}")
|
1130 |
+
return items
|
1131 |
+
|
1132 |
def main():
|
1133 |
st.set_page_config(
|
1134 |
layout="wide",
|
|
|
1283 |
</div>
|
1284 |
""", unsafe_allow_html=True)
|
1285 |
|
1286 |
+
# Add simple sorting options if we have items to display
|
1287 |
+
if current_clusters:
|
1288 |
+
# Simplified sort options - only Total Citations and Total Influential Citations
|
1289 |
+
sort_options = {
|
1290 |
+
"Total Citations": "citation_count",
|
1291 |
+
"Total Influential Citations": "influential_citation_count"
|
1292 |
+
}
|
1293 |
+
|
1294 |
+
selected_sort = st.selectbox(
|
1295 |
+
"📊 Sort by:",
|
1296 |
+
options=list(sort_options.keys()),
|
1297 |
+
index=0,
|
1298 |
+
key="sort_selector"
|
1299 |
+
)
|
1300 |
+
|
1301 |
+
# Apply sorting - always use descending order (highest first)
|
1302 |
+
sort_key = sort_options[selected_sort]
|
1303 |
+
current_clusters = sort_items_by_citations(current_clusters, sort_key, reverse=True)
|
1304 |
+
|
1305 |
# Back navigation button
|
1306 |
if st.session_state.path:
|
1307 |
if st.button('← Back', key='back_button'):
|