@@ -149,6 +149,7 @@ def reconcile_somef_data(data):
149
149
# print(json.dumps(out))
150
150
return out
151
151
152
+
152
153
@staticmethod
153
154
def apply_mapping (mapping_path , data ) -> Graph :
154
155
@@ -175,7 +176,16 @@ def apply_mapping(mapping_path, data) -> Graph:
175
176
# config = config.replace("$PATH", mapping_path).replace("$DATA", data_file)
176
177
# result_graph = morph_kgc.materialize(config)
177
178
# os.remove(temp_json_file_path)
178
-
179
+
180
+ # in case parameter 'data' be a path. Example: test_turtle_Export/test_basic_mapping_export
181
+
182
+ if isinstance (data , str ):
183
+ try :
184
+ with open (data , 'r' ) as file :
185
+ data = json .load (file )
186
+ except (json .JSONDecodeError , FileNotFoundError ) as e :
187
+ return None
188
+
179
189
# option sending directly the dictionary to materialize. IMPORTANT: just works with rml.ttl, not yml.
180
190
config = constants .MAPPING_CONFIG_DICT
181
191
config = config .replace ("$PATH" , mapping_path )
@@ -184,28 +194,33 @@ def apply_mapping(mapping_path, data) -> Graph:
184
194
'data_complete' : data
185
195
}
186
196
187
- result_graph = morph_kgc .materialize (config , data_complete )
197
+ try :
198
+ result_graph = morph_kgc .materialize (config , data_complete )
199
+ except Exception as e :
200
+ print ("Error materialize:" )
201
+ print (e )
202
+ raise
188
203
189
204
return result_graph
190
205
191
206
# @staticmethod
192
207
# def apply_mapping(mapping_path, data_path) -> Graph:
193
- """
194
- Given a mapping file and a data file, this method returns the MORPH-KGC materialization for the mapping
195
- Parameters
196
- ----------
197
- @param mapping_path: file path of the mapping
198
- @param data_path: file path with the JSON data to transform
199
-
200
- Returns
201
- -------
202
- An RDF graph with the desired triples
203
- """
204
- # mini test for morph-kgc
205
- # config = constants.MAPPING_CONFIG
206
- # # TO DO: Change RML URIs if they have been changed in the configuration.
207
- # config = config.replace("$PATH", mapping_path).replace("$DATA", data_path)
208
- # return morph_kgc.materialize(config)
208
+ # """
209
+ # Given a mapping file and a data file, this method returns the MORPH-KGC materialization for the mapping
210
+ # Parameters
211
+ # ----------
212
+ # @param mapping_path: file path of the mapping
213
+ # @param data_path: file path with the JSON data to transform
214
+
215
+ # Returns
216
+ # -------
217
+ # An RDF graph with the desired triples
218
+ # """
219
+ # # mini test for morph-kgc
220
+ # config = constants.MAPPING_CONFIG
221
+ # # # TO DO: Change RML URIs if they have been changed in the configuration.
222
+ # config = config.replace("$PATH", mapping_path).replace("$DATA", data_path)
223
+ # return morph_kgc.materialize(config)
209
224
210
225
def export_to_file (self , path , graph_format ):
211
226
"""
0 commit comments