Closed WolfgangFahl closed 7 months ago
Usage Example
# Import the WikidataSearch class
from wikidata_search import WikidataSearch
# Create an instance of WikidataSearch
# Optionally, you can specify the language and timeout (in seconds).
wikidata_search = WikidataSearch(language="en", timeout=5.0)
# Use the search method to look for a term, for example, "Python"
search_results = wikidata_search.search("Python", limit=5)
# Print the search results
print("Search Results:")
for result in search_results:
print(f"ID: {result['id']}, Label: {result['label']}, Description: {result.get('description', 'No description')}")
# Use the searchOptions method to get a nicely formatted list of options
options = wikidata_search.searchOptions("Python", limit=5)
# Print the formatted options
print("\nFormatted Options:")
for qid, label, desc in options:
print(f"QID: {qid}, Label: {label}, Description: {desc}")
Test Example:
1:academic con(en):9
[
[
"Q2020153",
"academic conference",
"conference for researchers to present and discuss their work"
],
[
"Q47258130",
"scientific conference series",
"series of scientific conferences (e.g., yearly) with the same name and topic"
],
https://www.mediawiki.org/wiki/Wikibase/API/ describes the full API including the search
https://www.wikidata.org/w/api.php?action=help&modules=wbsearchentities shows the API for the entity search
Example: https://www.wikidata.org/w/api.php?action=wbsearchentities&search=Einstein&language=en&limit=2&uselang=de
see also https://github.com/samuelmeuli/wikibase-api