File tree 1 file changed +18
-8
lines changed
1 file changed +18
-8
lines changed Original file line number Diff line number Diff line change 1
1
from src import services
2
+ from abi import logger
2
3
3
4
# Transform SPARQL results to list of dictionaries using the labels as keys
4
5
def results_to_list (results : list [dict ]) -> list [dict ]:
5
6
data = []
6
7
for row in results :
8
+ logger .debug (f"==> Row: { row } " )
7
9
data_dict = {}
8
10
for key in row .labels :
9
11
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:
21
23
Returns:
22
24
str: The class URI if found, None otherwise
23
25
"""
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
25
30
query = f"""
26
31
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
+
29
34
SELECT ?class
30
35
WHERE {{
31
- abi: { id } rdf:type ?class .
36
+ < { uri } > rdf:type ?class .
32
37
FILTER(?class != owl:NamedIndividual)
33
38
}}
34
39
"""
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
You can’t perform that action at this time.
0 commit comments