comparison importFromOpenMind/importer/ismixml2model.py @ 47:378dcb66a27f

new compare_models comparing the existence of nodes and relations in two graphs. fixed bugs in ismixml2model.
author casties
date Mon, 06 Feb 2017 18:44:43 +0100
parents f3945ef1e6a4
children 6625019a0c96
comparison
equal deleted inserted replaced
46:f3945ef1e6a4 47:378dcb66a27f
155 oc = ent_elem.get('object-class') 155 oc = ent_elem.get('object-class')
156 156
157 # set type 157 # set type
158 attrs[node_type_attribute] = fixName(oc) 158 attrs[node_type_attribute] = fixName(oc)
159 159
160 ismi_id = ent_elem.get('id') 160 ismi_id = int(ent_elem.get('id'))
161 # rename id to ismi_id 161 # rename id to ismi_id
162 attrs['ismi_id'] = ismi_id 162 attrs['ismi_id'] = ismi_id
163 163
164 if len(ov) > 0: 164 if len(ov) > 0:
165 # save ov as label 165 # save ov as label
167 #if 'nov' in ent: 167 #if 'nov' in ent:
168 # # add normalized value 168 # # add normalized value
169 # attrs['_n_label'] = ent.get('nov') 169 # attrs['_n_label'] = ent.get('nov')
170 170
171 # create node 171 # create node
172 #log('DEBUG', "new node(%s, %s)"%(ismi_id, attrs)) 172 log('DEBUG', "new node(%s, %s)"%(ismi_id, attrs))
173 nx_graph.add_node(ismi_id, **attrs) 173 nx_graph.add_node(ismi_id, **attrs)
174 node = nx_graph.node[ismi_id] 174 node = nx_graph.node[ismi_id]
175 175
176 return node 176 return node
177 177
178 178
179 def relationFromRel(rel_elem): 179 def relationFromRel(rel_elem):
180 """Create graph relation from etree element. 180 """Create graph relation from etree element.
181 """ 181 """
182 rel_id = rel_elem.get('id') 182 rel_id = int(rel_elem.get('id'))
183 rel_name = rel_elem.get('object-class') 183 rel_name = rel_elem.get('object-class')
184 src_id = rel_elem.get('source-id') 184 src_id = int(rel_elem.get('source-id'))
185 tar_id = rel_elem.get('target-id') 185 tar_id = int(rel_elem.get('target-id'))
186 if not src_id in nx_nodes: 186 if not src_id in nx_nodes:
187 log("ERROR", "relation %s src node %s missing!"%(rel_id,src_id)) 187 log("WARNING", "relation %s src node %s missing!"%(rel_id,src_id))
188 return None 188 return None
189 189
190 if not tar_id in nx_nodes: 190 if not tar_id in nx_nodes:
191 log("ERROR", "relation %s tar node %s missing!"%(rel_id,tar_id)) 191 log("WARNING", "relation %s tar node %s missing!"%(rel_id,tar_id))
192 return None 192 return None
193 193
194 ov = rel_elem.text or '' 194 ov = rel_elem.text or ''
195 195
196 attrs = {} 196 attrs = {}
256 # # own value of relation is not useful 256 # # own value of relation is not useful
257 # attrs['ov'] = ov 257 # attrs['ov'] = ov
258 258
259 attrs[rel_type_attribute] = fixName(rel_name) 259 attrs[rel_type_attribute] = fixName(rel_name)
260 attrs['ismi_id'] = rel_id 260 attrs['ismi_id'] = rel_id
261 log('DEBUG', "new edge(%s, %s, %s)"%(src_id, tar_id, attrs)) 261 #log('DEBUG', "new edge(%s, %s, %s)"%(src_id, tar_id, attrs))
262 # create relation with type 262 # create relation with type
263 nx_rel = nx_graph.add_edge(src_id, tar_id, attr_dict=attrs) 263 nx_rel = nx_graph.add_edge(src_id, tar_id, attr_dict=attrs)
264 264
265 return nx_rel 265 return nx_rel
266 266
273 log('INFO', "XML says %s entities"%xml_num) 273 log('INFO', "XML says %s entities"%xml_num)
274 274
275 # iterate through entities element 275 # iterate through entities element
276 for ent_elem in ents_elem: 276 for ent_elem in ents_elem:
277 cnt += 1 277 cnt += 1
278 ismi_id = ent_elem.get('id') 278
279 oc = ent_elem.get('object-class')
280 if oc in exclude_objects_of_type:
281 # skip this entity
282 continue
283
284 ismi_id = int(ent_elem.get('id'))
279 log('DEBUG', "reading entity[%s]"%ismi_id) 285 log('DEBUG', "reading entity[%s]"%ismi_id)
280 286
281 if ismi_id in nx_nodes: 287 if ismi_id in nx_nodes:
282 log("ERROR", "entity with id=%s exists!"%ismi_id) 288 log("ERROR", "entity with id=%s exists!"%ismi_id)
283 return 289 return
301 log('INFO', "XML says %s relations"%xml_num) 307 log('INFO', "XML says %s relations"%xml_num)
302 308
303 # iterate through entities element 309 # iterate through entities element
304 for rel_elem in rels_elem: 310 for rel_elem in rels_elem:
305 cnt += 1 311 cnt += 1
306 ismi_id = rel_elem.get('id') 312
313 ismi_id = int(rel_elem.get('id'))
307 log('DEBUG', "reading relation[%s]"%ismi_id) 314 log('DEBUG', "reading relation[%s]"%ismi_id)
308 315
309 if ismi_id in nx_relations: 316 if ismi_id in nx_relations:
310 print("ERROR: relation with id=%s exists!"%ismi_id) 317 print("ERROR: relation with id=%s exists!"%ismi_id)
311 return 318 return