learn / test_time_scaling /knowledge_level_test.py
unfair11212's picture
Upload folder using huggingface_hub
a80f6e6 verified
# from nltk.corpus import wordnet as wn
# # 你想查询的数学术语列表
# math_terms = ["ideal"]
# for term in math_terms:
# print(f"\nTerm: {term}")
# synsets = wn.synsets(term, pos=wn.NOUN)
# if not synsets:
# print(" No synsets found.")
# for syn in synsets:
# print(f" Synset: {syn.name()}, Definition: {syn.definition()}, Depth: {syn.min_depth()}")
from SPARQLWrapper import SPARQLWrapper, JSON
import requests
def get_superclasses(entity_id):
sparql = SPARQLWrapper("https://query.wikidata.org/sparql")
query = f"""
SELECT ?super ?superLabel WHERE {{
wd:{entity_id} wdt:P279* ?super .
SERVICE wikibase:label {{ bd:serviceParam wikibase:language "en". }}
}}
"""
sparql.setQuery(query)
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
return [(r["super"]["value"], r["superLabel"]["value"]) for r in results["results"]["bindings"]]
def get_wikidata_id(term):
url = f"https://www.wikidata.org/w/api.php"
params = {
'action': 'wbsearchentities',
'language': 'en',
'format': 'json',
'search': term
}
response = requests.get(url, params=params)
return response.json()['search'][0]['id']
def print_superclasses_for_term(term):
entity_id = get_wikidata_id(term)
print(f"{term} -> Wikidata ID: {entity_id}")
results = get_superclasses(entity_id)
print(f"Superclasses for {term}:")
for uri, label in results:
print(label)
# 示例:查询"Entropy"的super classes
# print_superclasses_for_term("Entropy")
for term in ["group","Entropy", "Matrix", "Integration"]:
print_superclasses_for_term(term)
print("-" * 30)