comparison importFromOpenMind/importer/model2model.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 f5e078e903df
comparison
equal deleted inserted replaced
33:7e2e344c3b87 34:74dfaed3600b
30 #add_link_attributes = {'ismi_id': 'https://ismi-dev.mpiwg-berlin.mpg.de/drupal-ismi/entity/%s'} 30 #add_link_attributes = {'ismi_id': 'https://ismi-dev.mpiwg-berlin.mpg.de/drupal-ismi/entity/%s'}
31 add_link_attributes = {'ismi_id': 'https://ismi-dev.mpiwg-berlin.mpg.de/om4-ismi/browse/entityDetails.xhtml?eid=%s'} 31 add_link_attributes = {'ismi_id': 'https://ismi-dev.mpiwg-berlin.mpg.de/om4-ismi/browse/entityDetails.xhtml?eid=%s'}
32 32
33 # name of type attribute 33 # name of type attribute
34 node_type_attribute = '_type' 34 node_type_attribute = '_type'
35 rel_type_attribute = 'type' 35 rel_type_attribute = '_type'
36 36
37 37
38 def fixName(name, is_src_rel=False, is_tar_rel=False, att_from_rel=False): 38 def fixName(name, is_src_rel=False, is_tar_rel=False, att_from_rel=False):
39 if is_src_rel: 39 if is_src_rel:
40 #name = name + '>' 40 #name = name + '>'
180 # iterate list 180 # iterate list
181 cnt = 0 181 cnt = 0
182 for nx_edge in edges: 182 for nx_edge in edges:
183 (nx_src, nx_tar) = nx_edge 183 (nx_src, nx_tar) = nx_edge
184 # get attributes of edge 184 # get attributes of edge
185 rel_attrs = nx_graph.edge[nx_src][nx_tar][0] 185 rel_attrs = nx_graph.edge[nx_src][nx_tar][0][:]
186 rel_type = rel_attrs[rel_type_attribute] 186 rel_type = rel_attrs[rel_type_attribute]
187 rel_id = rel_attrs['ismi_id'] 187 rel_id = rel_attrs['ismi_id']
188 # create new relation 188 # create new relation
189 invrel_atts = {rel_type_attribute: fixName(rel_type, is_tar_rel=True), 'ismi_id': -rel_id} 189 rel_attrs[rel_type_attribute] = fixName(rel_type, is_tar_rel=True)
190 nx_graph.add_edge(nx_tar, nx_src, invrel_atts) 190 rel_attrs['ismi_id': -rel_id]
191 nx_graph.add_edge(nx_tar, nx_src, attr_dict=invrel_atts)
191 192
192 cnt += 1 193 cnt += 1
193 if cnt % 100 == 0: 194 if cnt % 100 == 0:
194 print(" %s relations"%cnt) 195 print(" %s relations"%cnt)
195 196