Example #1
0
def p_edge_spec(p):
    '''
        edge_spec :
                  | '[' edge_rank edge_props ']'
                  | '[' ':' LABEL edge_rank edge_props ']'
                  | '[' STRING '-' '>' STRING edge_rank edge_props ']'
                  | '[' ':' LABEL STRING '-' '>' STRING edge_rank edge_props ']'
    '''
    e = Edge()
    if len(p) == 5:
        e.ranking = p[2]
        e.props = p[3]
    elif len(p) == 7:
        e.name = p[3]
        e.ranking = p[4]
        e.props = p[5]
    elif len(p) == 9:
        e.src = p[2].get_sVal()
        e.dst = p[5].get_sVal()
        e.ranking = p[6]
        e.props = p[7]
    elif len(p) == 11:
        e.name = p[3]
        e.src = p[4].get_sVal()
        e.dst = p[7].get_sVal()
        e.ranking = p[8]
        e.props = p[9]
    p[0] = e
Example #2
0
 def gen_edge(cls, src_id, dst_id, type, edge_name, ranking, props):
     edge = Edge()
     edge.src = src_id
     edge.dst = dst_id
     edge.type = type
     edge.name = edge_name
     edge.ranking = ranking
     edge.props = props
     return edge
Example #3
0
    def as_relationship(self):
        """convert the edge data to structure Relationship

        :return: Relationship
        """
        if len(self._row.values) < self.PROP_START_INDEX:
            raise RuntimeError('The row value is bad format, '
                               'as relationship failed: len is {}'
                               .format(len(self._row.values)))
        edge = Edge()
        edge.src = self._row.values[0]
        edge.type = self._row.values[1].get_iVal()
        edge.name = self._edge_name
        edge.ranking = self._row.values[2].get_iVal()
        edge.dst = self._row.values[3]
        edge.props = {}
        index = self.PROP_START_INDEX
        while index < len(self._col_names):
            edge.props[self._col_names[index]] = self._row.values[index]
            index = index + 1

        return Relationship(edge).set_decode_type(self._decode_type)
Example #4
0
def p_edge_spec(p):
    '''
        edge : '[' edge_rank edge_props ']'
             | '[' ':' LABEL edge_props ']'
             | '[' ':' LABEL edge_rank edge_props ']'
             | '[' vid '-' '>' vid edge_props ']'
             | '[' vid '-' '>' vid edge_rank edge_props ']'
             | '[' ':' LABEL vid '-' '>' vid edge_props ']'
             | '[' ':' LABEL vid '-' '>' vid edge_rank edge_props ']'
             | '[' vid '<' '-' vid edge_props ']'
             | '[' vid '<' '-' vid edge_rank edge_props ']'
             | '[' ':' LABEL vid '<' '-' vid edge_props ']'
             | '[' ':' LABEL vid '<' '-' vid edge_rank edge_props ']'
    '''
    e = Edge()
    name = None
    rank = None
    src = None
    dst = None
    props = None
    etype = None

    if len(p) == 5:
        rank = p[2]
        props = p[3]
    elif len(p) == 6:
        name = p[3]
        props = p[4]
    elif len(p) == 7:
        name = p[3]
        rank = p[4]
        props = p[5]
    elif len(p) == 8:
        src = p[2]
        dst = p[5]
        if p[3] == '<' and p[4] == '-':
            etype = -1
        props = p[6]
    elif len(p) == 9:
        src = p[2]
        dst = p[5]
        if p[3] == '<' and p[4] == '-':
            etype = -1
        rank = p[6]
        props = p[7]
    elif len(p) == 10:
        name = p[3]
        src = p[4]
        dst = p[7]
        if p[5] == '<' and p[6] == '-':
            etype = -1
        props = p[8]
    elif len(p) == 11:
        name = p[3]
        src = p[4]
        dst = p[7]
        if p[5] == '<' and p[6] == '-':
            etype = -1
        rank = p[8]
        props = p[9]

    e.name = name
    e.ranking = rank
    e.src = src
    e.dst = dst
    e.props = props
    # default value of e.type is 1 if etype is None
    e.type = etype

    p[0] = Value(eVal=e)
Example #5
0
def p_edge_spec(p):
    '''
        edge : '[' edge_rank edge_props ']'
             | '[' ':' LABEL edge_props ']'
             | '[' ':' LABEL edge_rank edge_props ']'
             | '[' STRING '-' '>' STRING edge_props ']'
             | '[' STRING '-' '>' STRING edge_rank edge_props ']'
             | '[' ':' LABEL STRING '-' '>' STRING edge_props ']'
             | '[' ':' LABEL STRING '-' '>' STRING edge_rank edge_props ']'
             | '[' STRING '<' '-' STRING edge_props ']'
             | '[' STRING '<' '-' STRING edge_rank edge_props ']'
             | '[' ':' LABEL STRING '<' '-' STRING edge_props ']'
             | '[' ':' LABEL STRING '<' '-' STRING edge_rank edge_props ']'
    '''
    e = Edge()
    name = None
    rank = 0
    src = None
    dst = None
    props = None
    type = 1

    if len(p) == 5:
        rank = p[2]
        props = p[3]
    elif len(p) == 6:
        name = p[3]
        props = p[4]
    elif len(p) == 7:
        name = p[3]
        rank = p[4]
        props = p[5]
    elif len(p) == 8:
        src = p[2].get_sVal()
        dst = p[5].get_sVal()
        if p[3] == '<' and p[4] == '-':
            type = -1
        props = p[6]
    elif len(p) == 9:
        src = p[2].get_sVal()
        dst = p[5].get_sVal()
        if p[3] == '<' and p[4] == '-':
            type = -1
        rank = p[6]
        props = p[7]
    elif len(p) == 10:
        name = p[3]
        src = p[4].get_sVal()
        dst = p[7].get_sVal()
        if p[5] == '<' and p[6] == '-':
            type = -1
        props = p[8]
    elif len(p) == 11:
        name = p[3]
        src = p[4].get_sVal()
        dst = p[7].get_sVal()
        if p[5] == '<' and p[6] == '-':
            type = -1
        rank = p[8]
        props = p[9]

    e.name = None if name is None else bytes(name, 'utf-8')
    e.ranking = rank
    e.src = src
    e.dst = dst
    e.props = props
    e.type = type

    p[0] = Value(eVal=e)