search_property
Find Wikidata property IDs by entering descriptive queries to identify specific data attributes in the knowledge base.
Instructions
Search for a Wikidata property ID by its query.
Args:
query (str): The query to search for. The query should be unambiguous enough to uniquely identify the property.
Returns:
str: The Wikidata property ID corresponding to the given query."
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes |
Implementation Reference
- src/server.py:52-52 (registration)Registers the 'search_property' tool using the @server.tool() decorator.@server.tool()
- src/server.py:53-63 (handler)The handler function for the 'search_property' tool. It calls the shared search_wikidata helper with is_entity=False to find property IDs.async def search_property(query: str) -> str: """ Search for a Wikidata property ID by its query. Args: query (str): The query to search for. The query should be unambiguous enough to uniquely identify the property. Returns: str: The Wikidata property ID corresponding to the given query." """ return await search_wikidata(query, is_entity=False)
- src/server.py:13-35 (helper)Helper function that performs the Wikidata search API call, used by both search_entity and search_property tools.async def search_wikidata(query: str, is_entity: bool = True) -> str: """ Search for a Wikidata item or property ID by its query. """ params = { "action": "query", "list": "search", "srsearch": query, "srnamespace": 0 if is_entity else 120, "srlimit": 1, # TODO: add a parameter to limit the number of results? "srqiprofile": "classic_noboostlinks" if is_entity else "classic", "srwhat": "text", "format": "json", } async with httpx.AsyncClient() as client: response = await client.get(WIKIDATA_URL, headers=HEADER, params=params) response.raise_for_status() try: title = response.json()["query"]["search"][0]["title"] title = title.split(":")[-1] return title except KeyError: return "No results found. Consider changing the search term."