1818from linkml_runtime .utils .yamlutils import YAMLRoot
1919from pydantic import BaseModel
2020
21+ logger = logging .getLogger (__name__ )
22+
23+
2124VALID_SUBJECT = Union [URIRef , BNode ]
2225ANYDICT = Dict [str , Any ]
2326
@@ -60,7 +63,7 @@ def from_rdf_graph(
6063 if c2 .name in schemaview .class_ancestors (cn ):
6164 continue
6265 else :
63- logging .error (f'Inconsistent URI to class map: { uri } -> { c2 .name } , { c .name } ' )
66+ logger .error (f'Inconsistent URI to class map: { uri } -> { c2 .name } , { c .name } ' )
6467 uri_to_class_map [uri ] = c
6568 # data prefix map: supplements or overrides existing schema prefix map
6669 if isinstance (prefix_map , Converter ):
@@ -74,7 +77,7 @@ def from_rdf_graph(
7477 target_class_uriref : URIRef = target_class .class_class_uri
7578 root_dicts : List [ANYDICT ] = []
7679 root_subjects : List [VALID_SUBJECT ] = list (graph .subjects (RDF .type , target_class_uriref ))
77- logging .debug (f'ROOTS = { root_subjects } ' )
80+ logger .debug (f'ROOTS = { root_subjects } ' )
7881 # Step 2: walk RDF graph starting from root subjects, constructing dict tree
7982 node_tuples_to_visit : List [Tuple [VALID_SUBJECT , ClassDefinitionName ]] ## nodes and their type still to visit
8083 node_tuples_to_visit = [(subject , target_class .class_name ) for subject in root_subjects ]
@@ -101,14 +104,14 @@ def from_rdf_graph(
101104 type_classes = [uri_to_class_map [str (x )] for x in type_vals ]
102105 if len (type_classes ) > 1 :
103106 raise ValueError (f'Ambiguous types for { subject } == { type_classes } ' )
104- logging .info (f'Replacing { subject_class } with { type_classes } ' )
107+ logger .info (f'Replacing { subject_class } with { type_classes } ' )
105108 subject_class = type_classes [0 ].name
106109 # process all triples for this node
107110 for (_ , p , o ) in graph .triples ((subject , None , None )):
108111 processed_triples .add ((subject ,p ,o ))
109- logging .debug (f' Processing triple { subject } { p } { o } , subject type = { subject_class } ' )
112+ logger .debug (f' Processing triple { subject } { p } { o } , subject type = { subject_class } ' )
110113 if p == RDF .type :
111- logging .debug (f'Ignoring RDF.type for { subject } { o } , we automatically infer this from { subject_class } ' )
114+ logger .debug (f'Ignoring RDF.type for { subject } { o } , we automatically infer this from { subject_class } ' )
112115 elif p not in uri_to_slot :
113116 if ignore_unmapped_predicates :
114117 unmapped_predicates .add (p )
@@ -121,13 +124,13 @@ def from_rdf_graph(
121124 slot_name = underscore (slot .name )
122125 if isinstance (o , Literal ):
123126 if EnumDefinition .class_name in range_applicable_elements :
124- logging .debug (f'Assuming no meaning assigned for value { o } for Enum { slot .range } ' )
127+ logger .debug (f'Assuming no meaning assigned for value { o } for Enum { slot .range } ' )
125128 elif TypeDefinition .class_name not in range_applicable_elements :
126129 raise ValueError (f'Cannot map Literal { o } to a slot { slot .name } whose range { slot .range } is not a type;' )
127130 v = o .value
128131 elif isinstance (o , BNode ):
129132 if not is_inlined :
130- logging .error (f'blank nodes should be inlined; { slot_name } ={ o } in { subject } ' )
133+ logger .error (f'blank nodes should be inlined; { slot_name } ={ o } in { subject } ' )
131134 v = Pointer (o )
132135 else :
133136 if ClassDefinition .class_name in range_applicable_elements :
@@ -137,7 +140,7 @@ def from_rdf_graph(
137140 else :
138141 v = namespaces .curie_for (o )
139142 if v is None :
140- logging .debug (f'No CURIE for { p } ={ o } in { subject } [{ subject_class } ]' )
143+ logger .debug (f'No CURIE for { p } ={ o } in { subject } [{ subject_class } ]' )
141144 v = str (o )
142145 elif EnumDefinition .class_name in range_applicable_elements :
143146 range_union_elements = schemaview .slot_range_as_union (slot )
@@ -156,7 +159,7 @@ def from_rdf_graph(
156159 v = namespaces .curie_for (o )
157160 if v is None :
158161 v = str (o )
159- logging .debug (f'Casting { o } to string' )
162+ logger .debug (f'Casting { o } to string' )
160163 else :
161164 raise ValueError (f'Expected literal value ({ range_applicable_elements } ) for { slot_name } ={ o } ' )
162165 if is_inlined :
@@ -175,13 +178,13 @@ def from_rdf_graph(
175178 if slot .range in schemaview .all_classes ():
176179 node_tuples_to_visit .append ((o , ClassDefinitionName (slot .range )))
177180 if unmapped_predicates :
178- logging .info (f'Unmapped predicated: { unmapped_predicates } ' )
181+ logger .info (f'Unmapped predicated: { unmapped_predicates } ' )
179182 unprocessed_triples = set (graph .triples ((None , None , None ))) - processed_triples
180- logging .info (f'Triple processed = { len (processed_triples )} , unprocessed = { len (unprocessed_triples )} ' )
183+ logger .info (f'Triple processed = { len (processed_triples )} , unprocessed = { len (unprocessed_triples )} ' )
181184 if len (unprocessed_triples ) > 0 :
182185 if not allow_unprocessed_triples :
183186 for t in unprocessed_triples :
184- logging .warning (f' Unprocessed: { t } ' )
187+ logger .warning (f' Unprocessed: { t } ' )
185188 raise ValueError (f'Unprocessed triples: { len (unprocessed_triples )} ' )
186189 # Step 2: replace inline pointers with object dicts
187190 def repl (v ):
@@ -195,7 +198,7 @@ def repl(v):
195198 objs_to_visit : List [ANYDICT ] = copy (root_dicts )
196199 while len (objs_to_visit ) > 0 :
197200 obj = objs_to_visit .pop ()
198- logging .debug (f'Replacing pointers for { obj } ' )
201+ logger .debug (f'Replacing pointers for { obj } ' )
199202 for k , v in obj .items ():
200203 if v is None :
201204 continue
0 commit comments