Example #1
0
def get_label_by_name(name):
    cmd = "g.V().has('name','{0}').label()".format(name)
    isSucess, result = client.gremlin_client_req(cmd)
    if isSucess is not True:
        return isSucess, result

    value = result.get('data', [])

    return True, value
Example #2
0
def get_node_by_name(label, name):
    cmd = "g.V()"
    if label is not None:
        cmd = cmd + ".hasLabel('{0}')".format(label)
    cmd = cmd + ".has('name','{0}')".format(name)
    cmd = cmd + ".dedup()"
    isSucess, result = client.gremlin_client_req(cmd)
    if isSucess is not True:
        return isSucess, result
    value = result.get('data', [])

    return True, value
Example #3
0
def get_node_property_value(label, name, propertyKey):
    cmd = "g.V()"
    if label is not None:
        cmd = cmd + ".hasLabel('{0}')".format(label)
    cmd = cmd + ".has('name','{0}').values('{1}')".format(name, propertyKey)
    logging.info("send: %s" % (cmd))
    isSucess, result = client.gremlin_client_req(cmd)
    if isSucess is not True:
        return isSucess, result
    value = result.get('data', [])

    return True, value
Example #4
0
def get_ndegree_object(startNode, \
                       edgeList, \
                       endNode, \
                       appendList = None):
    #init cmd
    cmd = "g.V()"

    #parse start node
    subjectLabel = startNode.label
    subjectPropertiesList = startNode.propertiesList

    #split joint subjectLabel
    if not common.data_is_NULL(subjectLabel):
        s_label_str = "hasLabel('{0}')".format(subjectLabel)
        cmd = cmd + "." + s_label_str

    #split joint subjectPorperty
    if not common.data_is_NULL(subjectPropertiesList):
        cmd = cmd + '.' + _package_propertiesList_(subjectPropertiesList)

    #split joint predict
    for edge in edgeList:
        if common.data_is_NULL(edge.direction):
            predictDirection = "both"
        else:
            predictDirection = edge.direction

        if common.data_is_NULL(edge.label):
            predict_str = "{0}()".format(predictDirection)
        else:
            predict_str = "{0}('{1}')".format(predictDirection, edge.label)
        cmd = cmd + "." + predict_str

    #parse start node
    objectLabel = endNode.label
    objectPropertiesList = endNode.propertiesList

    #split joint objectLabel
    if not common.data_is_NULL(objectLabel):
        o_label_str = "hasLabel('{0}')".format(objectLabel)
        cmd = cmd + "." + o_label_str

    #split object property
    if not common.data_is_NULL(objectPropertiesList):
        cmd = cmd + "." + _package_propertiesList_(objectPropertiesList)

    if not common.data_is_NULL(appendList):
        for append in appendList:
            cmd = cmd + "." + append

    #send query cmd
    logging.info("cmd: %s" % (cmd))
    return client.gremlin_client_req(cmd)
Example #5
0
def get_edges_by_properties(label, propertiesList):
    #init cmd
    cmd = "g.E()"
    #split subject label
    if not common.data_is_NULL(label):
        label_str = "hasLabel('{0}')".format(label)
        cmd = cmd + '.' + label_str

    #split property
    if not common.data_is_NULL(propertiesList):
        cmd = cmd + '.' + _package_propertiesList_(propertiesList)

    #print send cmd
    logging.info("cmd: %s" % (cmd))
    return client.gremlin_client_req(cmd)
Example #6
0
def get_node_name_by_property(label, propertyKey, propertyValue):
    cmd = "g.V()"
    if label is not None:
        cmd = cmd + ".hasLabel('{0}')".format(label)
    cmd = cmd + ".has('{0}','{1}').values('name')".format(
        propertyKey, propertyValue)
    logging.info("send: %s" % (cmd))
    isSucess, result = client.gremlin_client_req(cmd)
    if isSucess is not True:
        return isSucess, result
    nameList = result.get('data', None)
    if common.data_is_NULL(nameList):
        return False, None
    name = nameList[0]
    return True, name
Example #7
0
def get_common(cmd):
    return client.gremlin_client_req(cmd)
Example #8
0
def get_edges_by_label(label):
    cmd = "g.E().hasLabel('{0}')".format(label)
    logging.info("send: %s" % (cmd))
    return client.gremlin_client_req(cmd)