Spaces:
Sleeping
Sleeping
import requests | |
import logging | |
from wikibaseintegrator import WikibaseIntegrator, datatypes, wbi_helpers | |
from wikibaseintegrator.wbi_config import config | |
from wikibaseintegrator.wbi_exceptions import MWApiError | |
wikibase_api_url = 'https://fashionwiki.wikibase.cloud/w/api.php' | |
config = { | |
"SPARQL_ENDPOINT_URL": "https://fashionwiki.wikibase.cloud/query/sparql", | |
'USER_AGENT': 'YourBotName/1.0 (https://yourwebsite.org/bot-info)', | |
'WIKIBASE_URL': wikibase_api_url, | |
} | |
# List of valid language codes (can be expanded) | |
VALID_LANGUAGE_CODES = ['en'] | |
def get_property_id_by_label(property_label, api_url): | |
""" | |
Resolve the property label to its corresponding property ID from Wikibase. | |
Args: | |
property_label (str): The label of the property to search. | |
api_url (str): The API URL of the target Wikibase or Wikidata. | |
Returns: | |
str: The property ID if found, otherwise None. | |
""" | |
url = f'{api_url}/w/api.php?action=wbsearchentities&search={property_label}&language=en&type=property&format=json' | |
response = requests.get(url) | |
if response.status_code == 200: | |
search_results = response.json() | |
if 'search' in search_results and search_results['search']: | |
# Return the first matching property ID | |
return search_results['search'][0]['id'] | |
else: | |
logging.info(f"No property found for label: {property_label}") | |
return None | |
else: | |
logging.error(f"Failed to search for property by label in the target Wikibase. HTTP Status Code: {response.status_code}") | |
return None | |
wikibase_properties_id = {"instance of": get_property_id_by_label("instance of", wikibase_api_url), | |
"reference URL": get_property_id_by_label("reference URL", wikibase_api_url), | |
"start time": get_property_id_by_label("start time", wikibase_api_url), | |
"end time": get_property_id_by_label("end time", wikibase_api_url), | |
"occupation title": get_property_id_by_label("occupation title", wikibase_api_url), | |
"educated at": get_property_id_by_label("educated at", wikibase_api_url), | |
"employer": get_property_id_by_label("employer", wikibase_api_url), | |
"work location": get_property_id_by_label("work location", wikibase_api_url), | |
"award received": get_property_id_by_label("award received", wikibase_api_url), | |
"point in time": get_property_id_by_label("point in time", wikibase_api_url), | |
"exact match": get_property_id_by_label("exact match", wikibase_api_url), | |
"date of birth": get_property_id_by_label("date of birth", wikibase_api_url), | |
"place of birth": get_property_id_by_label("place of birth", wikibase_api_url), | |
"date of death": get_property_id_by_label("date of death", wikibase_api_url), | |
"country of citizenship": get_property_id_by_label("country of citizenship", wikibase_api_url), | |
"occupation": get_property_id_by_label("occupation", wikibase_api_url), | |
"sex or gender": get_property_id_by_label("sex or gender", wikibase_api_url), | |
"official website": get_property_id_by_label("official website", wikibase_api_url), | |
"perfumes": get_property_id_by_label("perfumes", wikibase_api_url), | |
"who wears it": get_property_id_by_label("who wears it", wikibase_api_url), | |
"inception": get_property_id_by_label("inception", wikibase_api_url), | |
"headquarters location": get_property_id_by_label("headquarters location", wikibase_api_url), | |
"parent organization": get_property_id_by_label("parent organization", wikibase_api_url), | |
"founded by": get_property_id_by_label("founded by", wikibase_api_url), | |
"owned by": get_property_id_by_label("owned by", wikibase_api_url), | |
"industry": get_property_id_by_label("industry", wikibase_api_url), | |
"country": get_property_id_by_label("country", wikibase_api_url), | |
"total revenue": get_property_id_by_label("total revenue", wikibase_api_url), | |
"designer employed": get_property_id_by_label("designer employed", wikibase_api_url), | |
"country of origin": get_property_id_by_label("country of origin", wikibase_api_url), | |
"fashion collection": get_property_id_by_label("fashion collection", wikibase_api_url), | |
"fashion season": get_property_id_by_label("fashion season", wikibase_api_url), | |
"fashion show location": get_property_id_by_label("fashion show location", wikibase_api_url), | |
"description of fashion collection": get_property_id_by_label("description of fashion collection", wikibase_api_url), | |
"image of fashion collection": get_property_id_by_label("image of fashion collection", wikibase_api_url), | |
"editor of fashion collection description": get_property_id_by_label("editor of fashion collection description", wikibase_api_url), | |
"date of fashion collection": get_property_id_by_label("date of fashion collection", wikibase_api_url), | |
"fashion show category": get_property_id_by_label("fashion show category", wikibase_api_url), | |
"fashion house X fashion collection": get_property_id_by_label("fashion house X fashion collection", wikibase_api_url), | |
"designer of collection": get_property_id_by_label("designer of collection", wikibase_api_url)} |