Skip to content

Commit 68388b6

Browse files
committed
fix: error using prefix abi
1 parent 6a7f0b9 commit 68388b6

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

lib/abi/utils/SPARQL.py

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from src import services
2+
from abi import logger
23

34
# Transform SPARQL results to list of dictionaries using the labels as keys
45
def results_to_list(results: list[dict]) -> list[dict]:
56
data = []
67
for row in results:
8+
logger.debug(f"==> Row: {row}")
79
data_dict = {}
810
for key in row.labels:
911
data_dict[key] = str(row[key]) if row[key] else None
@@ -21,18 +23,26 @@ def get_class_uri_from_individual_uri(uri: str) -> str:
2123
Returns:
2224
str: The class URI if found, None otherwise
2325
"""
24-
id = uri.split("/")[-1]
26+
if not str(uri).startswith("http://ontology.naas.ai/abi/"):
27+
return None
28+
29+
# Use the full URI in the query instead of trying to extract the ID
2530
query = f"""
2631
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
27-
PREFIX abi: <http://ontology.naas.ai/abi/>
28-
32+
PREFIX owl: <http://www.w3.org/2002/07/owl#>
33+
2934
SELECT ?class
3035
WHERE {{
31-
abi:{id} rdf:type ?class .
36+
<{uri}> rdf:type ?class .
3237
FILTER(?class != owl:NamedIndividual)
3338
}}
3439
"""
35-
results = services.triple_store_service.query(query)
36-
result_list = results_to_list(results)
37-
38-
return result_list[0]['class'] if result_list else None
40+
try:
41+
results = services.triple_store_service.query(query)
42+
result_list = results_to_list(results)
43+
logger.debug(f"==> Result List: {result_list}")
44+
class_uri = result_list[0]['class'] if result_list else None
45+
return class_uri
46+
except Exception as e:
47+
logger.error(f"Error getting class URI from individual URI {uri}: {e}")
48+
return None

0 commit comments

Comments
 (0)