66
77settings = Settings ()
88
9+
910class OntologyManager :
1011 def __init__ (self ):
1112 self .graph = Graph ()
1213 self .label_map : dict [str , str ] = {}
1314
1415 def load_ontologies (self ):
15- print (f"[INFO] Connecting to SPARQL endpoint: { settings .ONTOLOGY_SPARQL_ENDPOINT } " )
16+ print (
17+ f"[INFO] Connecting to SPARQL endpoint: { settings .ONTOLOGY_SPARQL_ENDPOINT } "
18+ )
1619 for graph_iri in settings .get_graph_iris ():
1720 print (f"[INFO] Loading named graph: { graph_iri } " )
1821 g = self ._load_named_graph (settings .ONTOLOGY_SPARQL_ENDPOINT , graph_iri )
@@ -23,12 +26,14 @@ def load_ontologies(self):
2326 def _load_named_graph (self , endpoint : str , graph_iri : str ) -> Graph :
2427 sparql = SPARQLWrapper (endpoint )
2528 sparql .setCredentials (settings .GRAPHDB_USERNAME , settings .GRAPHDB_PASSWORD )
26- sparql .setQuery (f"""
29+ sparql .setQuery (
30+ f"""
2731 CONSTRUCT {{ ?s ?p ?o }}
2832 WHERE {{
2933 GRAPH <{ graph_iri } > {{ ?s ?p ?o }}
3034 }}
31- """ )
35+ """
36+ )
3237 sparql .setReturnFormat (TURTLE )
3338 result = sparql .query ().convert ()
3439
@@ -69,7 +74,9 @@ def _build_label_map(self):
6974 print (f"[INFO] Label map built with { len (self .label_map )} unambiguous labels." )
7075
7176 def _check_ambiguities (self , seen : dict [str , str | list [str ]]) -> dict [str , str ]:
72- ambiguous_labels = {label for label , iris in seen .items () if isinstance (iris , list )}
77+ ambiguous_labels = {
78+ label for label , iris in seen .items () if isinstance (iris , list )
79+ }
7380
7481 if ambiguous_labels :
7582 msg = f"Found ambiguous labels: { ', ' .join (sorted (ambiguous_labels ))} \n Please resolve these in your ontology before proceeding."
@@ -79,7 +86,9 @@ def _check_ambiguities(self, seen: dict[str, str | list[str]]) -> dict[str, str]
7986 print (f"[WARNING] { msg } " )
8087
8188 # Return only unambiguous labels (those with a single IRI string)
82- return {label : iris for label , iris in seen .items () if not isinstance (iris , list )}
89+ return {
90+ label : iris for label , iris in seen .items () if not isinstance (iris , list )
91+ }
8392
8493 def get_label_map (self ) -> dict [str , str ]:
8594 return self .label_map
0 commit comments