<commit_before>__author__ = 'rwechsler'
import gensim
import cPickle as pickle
import argparse
import sys
import codecs


def load_word2vecmodel(file_name):
    return gensim.models.Word2Vec.load_word2vec_format(file_name, binary=True)


def load_prototype_dump(file_name):
    return pickle.load(open(file_name, "rb"))



if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Evaluate candidates')
    parser.add_argument('-w', action='store', dest="word2vec_file", required=True)
    parser.add_argument('-p', action='store', dest='prototype_file', required=True)
    parser.add_argument('-o', action="store", dest='output_file', required=True)

    arguments = parser.parse_args(sys.argv[1:])

    word2vec_model = load_word2vecmodel(arguments.word2vec_file)
    prototype_set = load_prototype_dump(arguments.prototype_file)

    outfile = codecs.open(arguments.output_file, "w", "utf-8")

    for candidate in prototype_set:
        print candidate
        for prototype, evidence_set in candidate[1]:
            outfile.write(candidate[0] + "\t" + word2vec_model.index2word[prototype] + "\t" + " ".join([word2vec_model.index2word[i] for i in evidence_set]) + "\n")

    outfile.close()
<commit_msg>Fixes.<commit_after>__author__ = 'rwechsler'
import gensim
import cPickle as pickle
import argparse
import sys
import codecs


def load_word2vecmodel(file_name):
    return gensim.models.Word2Vec.load_word2vec_format(file_name, binary=True)


def load_prototype_dump(file_name):
    return pickle.load(open(file_name, "rb"))



if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Evaluate candidates')
    parser.add_argument('-w', action='store', dest="word2vec_file", required=True)
    parser.add_argument('-p', action='store', dest='prototype_file', required=True)
    parser.add_argument('-o', action="store", dest='output_file', required=True)

    arguments = parser.parse_args(sys.argv[1:])

    word2vec_model = load_word2vecmodel(arguments.word2vec_file)
    prototype_set = load_prototype_dump(arguments.prototype_file)

    outfile = codecs.open(arguments.output_file, "w", "utf-8")

    for candidate in prototype_set:
        for prototype, evidence_set in candidate[1]:
            outfile.write(candidate[0] + "\t" + word2vec_model.index2word[prototype[1]] + "\t" + " ".join([word2vec_model.index2word[t[1]] for t in evidence_set]) + "\n")

    outfile.close()

{'fraction_non_alphanumeric': 0.12968299711815562, 'fraction_numerical': 0.013174145738987238, 'mean_word_length': 5.16751269035533, 'pattern_counts': {'":': 2, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3798220', 'n_tokens_mistral': 814, 'n_tokens_neox': 793, 'n_words': 146}