<commit_before>import networkx as nx
from sklearn.neighbors import KDTree


def getTraxelFeatureVector(traxel, featureName, maxNumDimensions=3):
    """
    extract a feature vector from a traxel
    """
    result = []
    for i in range(maxNumDimensions):
        try:
            result.append(traxel.get_feature_value(featureName, i))
        except:
            if i == 0:
                print("Error when accessing feature {}[{}] for traxel (Id={},Timestep={})".format(featureName,
                                                                                                  i,
                                                                                                  traxel.Id,
                                                                                                  traxel.Timestep))
                print "Available features are: "
                print traxel.print_available_features()
                raise Exception
            else:
                pass
    return result


class NodeMap:
    """
    To access per node features of the hypotheses graph, 
    this node map provides the same interface as pgmlink's NodeMaps
    """

    def __init__(self, graph, attributeName):
        self.__graph = graph
        self.__attributeName = attributeName

    def __getitem__(self, key):
        return self.__graph.node[key][self.__attributeName]


class HypothesesGraph:
    """
    Replacement for pgmlink's hypotheses graph, 
    with a similar API so it can be used as drop-in replacement.

    Internally it uses [networkx](http://networkx.github.io/) to construct the graph.
    """
<commit_msg>raise Exception when trained number of merger is less than maxNumObjects in Merger Resolving<commit_after>import networkx as nx
from sklearn.neighbors import KDTree

def getTraxelFeatureVector(traxel, featureName, maxNumDimensions=3):
    """
    extract a feature vector from a traxel
    """
    result = []
    for i in range(maxNumDimensions):
        try:
            result.append(traxel.get_feature_value(featureName, i))
        except:
            if i == 0:
                print("Error when accessing feature {}[{}] for traxel (Id={},Timestep={})".format(featureName,
                                                                                                  i,
                                                                                                  traxel.Id,
                                                                                                  traxel.Timestep))
                print "Available features are: "
                print traxel.print_available_features()
                raise Exception
            else:
                print("Error: Classifier was trained with less merger than maxNumObjects {}.".format(maxNumDimensions))
                raise Exception
    return result


class NodeMap:
    """
    To access per node features of the hypotheses graph, 
    this node map provides the same interface as pgmlink's NodeMaps
    """

    def __init__(self, graph, attributeName):
        self.__graph = graph
        self.__attributeName = attributeName

    def __getitem__(self, key):
        return self.__graph.node[key][self.__attributeName]


class HypothesesGraph:
    """
    Replacement for pgmlink's hypotheses graph, 
    with a similar API so it can be used as drop-in replacement.

    Internally it uses [networkx](http://networkx.github.io/) to construct the graph.
    """

{'fraction_non_alphanumeric': 0.07153116920425165, 'fraction_numerical': 0.0011490950876185005, 'mean_word_length': 1.497847919655667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4531222', 'n_tokens_mistral': 834, 'n_tokens_neox': 787, 'n_words': 252}