Пример #1
0
def addMultiNodesFromJsonFile(neoGraph,filename):
    file = open(filename)
# for all lines in the file
    while 1:
        line = file.readline()
        if not line:
            break
        # replace '' with ""
        respCmtJson = line.replace("'", "\"");
        # ture string to json
        js = simplejson.loads(respCmtJson)
        # lable  and key_values
        labels = []
        key_values = {}
        #put ID into the dict
        key_values['ID'] = js['ID']
        keyValues = js['AVP_LIST']
        # for all key_values in the AVP_LIST
        for keyValue in keyValues:
            # if ATTRIBUTE is category then put the value into label
              if keyValue['ATTRIBUTE'] == 'entity_category':
                  labels = keyValue['VALUE'].split(',')
                  labels = tuple(labels)
                  #print len(labels)
              else:
                  key_values[keyValue['ATTRIBUTE']] = keyValue['VALUE']
        # labels is tuple  and key_values is a dict
        # use with which can create a node
        node = Node()
        neoGraph.create(node)
        node.__init__(*labels,**key_values)
        node.push() 
        createIndexofNode(neoGraph,node)
        autoBuildRelationShip(neoGraph,node)  
Пример #2
0
def addNode(neoGraph,jsonNode):
    respCmtJson = jsonNode.replace("'", "\"");
    # turn string to json
    js = simplejson.loads(respCmtJson)
    # lable  and key_values
    labels = []
    key_values = {}
    #put ID into the dict
    key_values['ID'] = js['ID']
    keyValues = js['AVP_LIST']
    # for all key_values in the AVP_LIST
    for keyValue in keyValues:
    # if ATTRIBUTE is category then put the value into label
        if keyValue['ATTRIBUTE'] == 'entity_category':
            labels = keyValue['VALUE'].split(',')
            labels = tuple(labels)
        else:
            key_values[keyValue['ATTRIBUTE']] = keyValue['VALUE']
    # labels is tuple  and key_values is a dict
    node = Node()
    neoGraph.create(node)
    node.__init__(*labels,**key_values)
    node.push()