comparison importFromOpenMind/importer/ismi2model.py @ 34:74dfaed3600b

keep relation attributes but no attributes from openmind. change relation type attribute to '_type' too.
author casties
date Tue, 02 Feb 2016 15:16:29 +0100
parents 7e2e344c3b87
children d535f11a0d81
comparison
equal deleted inserted replaced
33:7e2e344c3b87 34:74dfaed3600b
23 'notes_old' 23 'notes_old'
24 ] 24 ]
25 25
26 # name of type attribute 26 # name of type attribute
27 node_type_attribute = '_type' 27 node_type_attribute = '_type'
28 rel_type_attribute = 'type' 28 rel_type_attribute = '_type'
29 29
30 entsURL=baseURL+"method=get_ents&oc=%s" 30 entsURL=baseURL+"method=get_ents&oc=%s"
31 31
32 entsByIdURL = baseURL+"method=get_ents&include_content=True&ids=%s" 32 entsByIdURL = baseURL+"method=get_ents&include_content=True&ids=%s"
33 33
54 ismi_relations = {} 54 ismi_relations = {}
55 nx_relations = {} 55 nx_relations = {}
56 56
57 57
58 def fixName(name, is_src_rel=False, is_tar_rel=False, att_from_rel=False): 58 def fixName(name, is_src_rel=False, is_tar_rel=False, att_from_rel=False):
59 # these are too embarrassing...
60 if 'FLORUIT' in name:
61 name = name.replace('FLORUIT', 'FLOURISH')
62
63 elif 'floruit' in name:
64 name = name.replace('floruit', 'flourish')
65
66 if is_src_rel: 59 if is_src_rel:
67 #name = name + '>' 60 #name = name + '>'
68 pass 61 pass
69 62
70 if is_tar_rel: 63 if is_tar_rel:
225 continue 218 continue
226 219
227 if not tar_id in nodes: 220 if not tar_id in nodes:
228 print("ERROR: relation %s tar node %s missing!"%(rel_id,tar_id)) 221 print("ERROR: relation %s tar node %s missing!"%(rel_id,tar_id))
229 continue 222 continue
230 223
224 # TODO: what about attributes of relation?
225 if len(rel['atts']) > 0:
226 print("INFO: relation with attributes! name=%s id=%s atts=%s"%(rel_name, rel_id, repr(rel['atts'])))
227
231 # create relation with type 228 # create relation with type
232 rel_atts = {rel_type_attribute: fixName(rel_name), 'ismi_id': rel_id} 229 rel_atts = {rel_type_attribute: fixName(rel_name), 'ismi_id': rel_id}
233 nx_rel = nx_graph.add_edge(src_id, tar_id, rel_atts) 230 nx_rel = nx_graph.add_edge(src_id, tar_id, attr_dict=rel_atts)
234 231
235 nx_relations[rel_id] = nx_rel 232 nx_relations[rel_id] = nx_rel
236 233
237 return nx_relations 234 return nx_relations
238 235