diff options
| author | LV-426 <lv-426@taproot.org.il> | 2014-10-15 18:40:54 +0200 |
|---|---|---|
| committer | LV-426 <lv-426@taproot.org.il> | 2014-10-15 18:40:54 +0200 |
| commit | 4edff7438274771d30849633b140d40a434fd491 (patch) | |
| tree | 36191b96bdc4734a85764b367149537c152a53fc /src-py | |
| parent | 5f9a2481861c27f32208671f166785ba1e9cbdda (diff) | |
meta_attr_list_to_meta_attr_map - used for '__type' injected meta attributes
Diffstat (limited to 'src-py')
| -rw-r--r-- | src-py/neo4j_util.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src-py/neo4j_util.py b/src-py/neo4j_util.py index 1c4ee081..6b79a84c 100644 --- a/src-py/neo4j_util.py +++ b/src-py/neo4j_util.py @@ -164,6 +164,28 @@ def gen_query_create_from_link_map(link_map, input_to_DB_property_map=lambda _: 'link_attr' : input_to_DB_property_map(prop_dict)} q_params_set.append(q_params) +def meta_attr_list_to_meta_attr_map(e_set, meta_attr='__type'): + """ + convert a list of maps each containing a meta_attr key into a + meta_attr-mapped collection of lists with the meta_attr removed - eg: + + in: [{'id':0, '__type': 'T'}, {'id':1, '__type': 'T'}] + out: { 'T', [{'id':0}, {'id':1}] } + """ + ret = {} + for v in e_set: + assert None != v['__type'] # attert type meta-attr is present + + v_type = v['__type'] + if None == ret.get(v_type):# init type list if necessary + ret[v_type] = [] + + v_no_meta = v.copy() + del v_no_meta['__type'] + + ret[v_type].append(v_no_meta) + + return ret q = "match (src {id: {src}.id}),(dst {id: {dst}.id}) create (src)-[:%(l_type)s {link_attr}]->(dst)" % {'l_type':l_type} return (q, q_params_set) |
