22 lines
618 B
Python
22 lines
618 B
Python
|
# %%
|
||
|
import requests
|
||
|
|
||
|
def get_related_terms(term, language="en", limit=10):
|
||
|
url = f"http://api.conceptnet.io/c/{language}/{term}"
|
||
|
response = requests.get(url).json()
|
||
|
|
||
|
# Extract related terms
|
||
|
related_terms = []
|
||
|
for edge in response.get("edges", []):
|
||
|
related = edge.get("end", {}).get("label", None)
|
||
|
if related and related.lower() != term.lower():
|
||
|
related_terms.append(related)
|
||
|
if len(related_terms) >= limit:
|
||
|
break
|
||
|
return related_terms
|
||
|
|
||
|
# Example
|
||
|
related_terms = get_related_terms("windows_server")
|
||
|
print("Related Terms:", related_terms)
|
||
|
# %%
|