import torch


def build_edge_attr(node2feature, edge_index):
    """
    Build edge_attr from LU_INDEX of connected nodes of each edge.
    """
    r,c = edge_index
    edge_attr = []
    features = {}
    num_features = 0
    for sent_node, received_node in zip(r,c):
        
        sent_LU_INDEX = int(node2feature[sent_node.item()]['LU_INDEX'])
        received_LU_INDEX = int(node2feature[received_node.item()]['LU_INDEX'])
        
        feature = (sent_LU_INDEX, received_LU_INDEX)
        if feature in features:
            edge_attr.append(features[feature])
        else:
            features[feature] = num_features
            edge_attr.append(features[feature])
            num_features += 1
        
    return torch.tensor(edge_attr), features