From 4edff7438274771d30849633b140d40a434fd491 Mon Sep 17 00:00:00 2001 From: LV-426 Date: Wed, 15 Oct 2014 18:40:54 +0200 Subject: meta_attr_list_to_meta_attr_map - used for '__type' injected meta attributes --- src-py/neo4j_util.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src-py') 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) -- cgit v1.3.1