def update_attribute(uid, attribute_dict): ts = time.time() Index = ManualIndexManager(graph) # manage index ts = time.time() node_name = "node_index" node_index = Index.get_index(Node, node_name) user_node = node_index.get("uid", uid)[0] # return with a list print user_node # update attribute-value for k, v in attribute_dict.iteritems(): user_node[k] = v # push to neo4j-db graph.push(user_node) te = time.time() print te - ts
def create_tag(tag_id, attribute_dict=dict()): Index = ManualIndexManager(graph) # manage index index_name = "tag_index" tag_index = Index.get_or_create_index(Node, index_name) exist = tag_index.get("tag", tag_id) if exist: tag_node = exist[0] for k, v in attribute_dict.iteritems(): tag_node[k] = v graph.push(tag_node) else: tag_node = Node("Tag", tag=tag_id) # create event node with only one event_id for k, v in attribute_dict.iteritems(): tag_node[k] = v graph.create(tag_node) tag_index.add("tag", tag_id, tag_node) return True
def create_event(event, attribute_dict=dict()): Index = ManualIndexManager(graph) # manage index event_index = Index.get_or_create_index(Node, event_index_name) exist = event_index.get("event", event) if exist: event_node = exist[0] for k, v in attribute_dict.iteritems(): event_node[k] = v graph.push(event_node) else: event_node = Node( "Event", event_id=event) # create event node with only one event_id for k, v in attribute_dict.iteritems(): event_node[k] = v graph.create(event_node) event_index.add("event", event, event_node) return True
def create_group(group_id, attribute_dict=dict()): Index = ManualIndexManager(graph) # manage index group_index = Index.get_or_create_index(Node, group_index_name) exist = group_index.get("group", group_id) if exist: group_node = exist[0] for k, v in attribute_dict.iteritems(): group_node[k] = v graph.push(group_node) else: group_node = Node( "Group", group=group_id) # create event node with only one event_id for k, v in attribute_dict.iteritems(): group_node[k] = v graph.create(group_node) group_index.add("group", group_id, group_node) return True
def put_in_user_portrait(): Index = ManualIndexManager(graph) # manage index node_name = "node_index" node_index = Index.get_index(Node, node_name) f = open("user_portrait.txt", "rb") count = 0 update_node = [] for item in f: user_dict = json.loads(item) uid = user_dict["uid"] exist = node_index.get("uid", uid) if not exist: Index.get_or_create_indexed_node(node_name, "uid", uid, user_dict) else: user_node = exist[0] for k, v in user_dict.iteritems(): user_node[k] = v graph.push(user_node) count += 1 print count f.close()