def construct_analogy_test_set(test_examples, dictionary, ignore_missing=False):
    """
    Construct the analogy test set by mapping the words to their
    word vector ids.

    Arguments:
    - test_examples: iterable of 4-word iterables
    - dictionay: a mapping from words to ids
    - boolean ignore_missing: if True, words in the test set
                              that are not in the dictionary
                              will be dropeed.

    Returns:
    - a N by 4 numpy matrix.
    """

    test = []
    
    for example in test_examples:
        try:
            test.append([dictionary[word] for word in example])
        except __HOLE__:
            if ignore_missing:
                pass
            else:
                raise

    try:
        test = np.array(test, dtype=np.int32)
    except ValueError as e:
        # This should use raise ... from ... in Python 3.
        raise ValueError('Each row of the test set should contain '
                        '4 integer word ids', e)

    return test
dataset/ETHPy150Open maciejkula/glove-python/glove/metrics/accuracy.py/construct_analogy_test_set