Mercurial > hg > drupalISMI
comparison importFromOpenMind/importer/ismi2model.py @ 33:7e2e344c3b87
make name of type attribute configurable. default '_type' for nodes.
author | casties |
---|---|
date | Tue, 02 Feb 2016 14:41:08 +0100 |
parents | ce12475d2109 |
children | 74dfaed3600b |
comparison
equal
deleted
inserted
replaced
32:ce12475d2109 | 33:7e2e344c3b87 |
---|---|
21 'node_type', | 21 'node_type', |
22 'nov', | 22 'nov', |
23 'notes_old' | 23 'notes_old' |
24 ] | 24 ] |
25 | 25 |
26 # name of type attribute | |
27 node_type_attribute = '_type' | |
28 rel_type_attribute = 'type' | |
26 | 29 |
27 entsURL=baseURL+"method=get_ents&oc=%s" | 30 entsURL=baseURL+"method=get_ents&oc=%s" |
28 | 31 |
29 entsByIdURL = baseURL+"method=get_ents&include_content=True&ids=%s" | 32 entsByIdURL = baseURL+"method=get_ents&include_content=True&ids=%s" |
30 | 33 |
147 oc = ent['oc'] | 150 oc = ent['oc'] |
148 if oc != etype: | 151 if oc != etype: |
149 print("ERROR: entity type doesn't match!") | 152 print("ERROR: entity type doesn't match!") |
150 return None | 153 return None |
151 | 154 |
152 # rename if type attr exists | |
153 if 'type' in attrs: | |
154 attrs['type2'] = attrs['type'] | |
155 if '_n_type' in attrs: | |
156 # rename normalized attribute | |
157 attrs['_n_type2'] = attrs['_n_type'] | |
158 del attrs['n_type'] | |
159 | |
160 # set type | 155 # set type |
161 attrs['type'] = fixName(oc) | 156 attrs[node_type_attribute] = fixName(oc) |
162 | 157 |
163 ismi_id = ent['id'] | 158 ismi_id = ent['id'] |
164 # rename id to ismi_id | 159 # rename id to ismi_id |
165 attrs['ismi_id'] = ismi_id | 160 attrs['ismi_id'] = ismi_id |
166 | 161 |
232 if not tar_id in nodes: | 227 if not tar_id in nodes: |
233 print("ERROR: relation %s tar node %s missing!"%(rel_id,tar_id)) | 228 print("ERROR: relation %s tar node %s missing!"%(rel_id,tar_id)) |
234 continue | 229 continue |
235 | 230 |
236 # create relation with type | 231 # create relation with type |
237 nx_rel = nx_graph.add_edge(src_id, tar_id, type=fixName(rel_name), ismi_id=rel_id) | 232 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) | |
238 | 234 |
239 nx_relations[rel_id] = nx_rel | 235 nx_relations[rel_id] = nx_rel |
240 | 236 |
241 return nx_relations | 237 return nx_relations |
242 | 238 |