# Path: autoencoder/preprocessing/preprocessing.py
# def load_corpus(corpus_path):
#     corpus = load_json(corpus_path)
# 
#     return corpus
# 
# Path: autoencoder/baseline/doc_word2vec.py
# def load_w2v(file):
#     model = Word2Vec.load_word2vec_format(file, binary=True)
#     return model
# 
# def doc_word2vec(model, corpus, vocab, output, avg=True):
#     doc_codes = {}
#     for key, bow in corpus.iteritems():
#         vec = get_doc_codes(model, bow, vocab, avg)
#         doc_codes[key] = vec.tolist()
#     dump_json(doc_codes, output)
# 
#     return doc_codes
# 
# def get_similar_words(model, query, topn=10):
#     return zip(*model.most_similar(query, topn=topn))[0]
# 
# Path: autoencoder/utils/io_utils.py
# def write_file(data, file):
#     try:
#         with open(file, 'w') as datafile:
#             for line in data:
#                 datafile.write(' '.join(line) + '\n')
#     except Exception as e:
#         raise e
# 
# Path: autoencoder/utils/op_utils.py
# def revdict(d):
#     """
#     Reverse a dictionary mapping.
#     When two keys map to the same value, only one of them will be kept in the
#     result (which one is kept is arbitrary).
#     """
#     return dict((v, k) for (k, v) in d.iteritems())


import argparse
import numpy as np
    import pdb;pdb.set_trace()
from os import path
from autoencoder.preprocessing.preprocessing import load_corpus
from autoencoder.baseline.doc_word2vec import load_w2v, doc_word2vec, get_similar_words
from autoencoder.utils.io_utils import write_file
from autoencoder.utils.op_utils import revdict
'''
Created on Jan, 2017

@author: hugo

'''
from __future__ import absolute_import


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--corpus', required=True, type=str, help='path to the corpus file')
    parser.add_argument('-mf', '--mod_file', required=True, type=str, help='path to the word2vec mod file')
    parser.add_argument('-sw', '--sample_words', type=str, help='path to the output sample words file')
    parser.add_argument('-o', '--output', type=str, help='path to the output doc codes file')
    args = parser.parse_args()

    corpus = load_corpus(args.corpus)
    docs, vocab_dict = corpus['docs'], corpus['vocab']
    w2v = load_w2v(args.mod_file)

    # doc_codes = doc_word2vec(w2v, docs, revdict(vocab_dict), args.output, avg=True)
    if args.sample_words:
        queries = ['weapon', 'christian', 'compani', 'israel', 'law', 'hockey', 'comput', 'space']
        words = []
        for each in queries:

# Path: autoencoder/preprocessing/preprocessing.py
# def load_corpus(corpus_path):
#     corpus = load_json(corpus_path)
# 
#     return corpus
# 
# Path: autoencoder/baseline/doc_word2vec.py
# def load_w2v(file):
#     model = Word2Vec.load_word2vec_format(file, binary=True)
#     return model
# 
# def doc_word2vec(model, corpus, vocab, output, avg=True):
#     doc_codes = {}
#     for key, bow in corpus.iteritems():
#         vec = get_doc_codes(model, bow, vocab, avg)
#         doc_codes[key] = vec.tolist()
#     dump_json(doc_codes, output)
# 
#     return doc_codes
# 
# def get_similar_words(model, query, topn=10):
#     return zip(*model.most_similar(query, topn=topn))[0]
# 
# Path: autoencoder/utils/io_utils.py
# def write_file(data, file):
#     try:
#         with open(file, 'w') as datafile:
#             for line in data:
#                 datafile.write(' '.join(line) + '\n')
#     except Exception as e:
#         raise e
# 
# Path: autoencoder/utils/op_utils.py
# def revdict(d):
#     """
#     Reverse a dictionary mapping.
#     When two keys map to the same value, only one of them will be kept in the
#     result (which one is kept is arbitrary).
#     """
#     return dict((v, k) for (k, v) in d.iteritems())


# Path: run_doc_word2vec.py
import argparse
import numpy as np
    import pdb;pdb.set_trace()
from os import path
from autoencoder.preprocessing.preprocessing import load_corpus
from autoencoder.baseline.doc_word2vec import load_w2v, doc_word2vec, get_similar_words
from autoencoder.utils.io_utils import write_file
from autoencoder.utils.op_utils import revdict

'''
Created on Jan, 2017

@author: hugo

'''
from __future__ import absolute_import


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--corpus', required=True, type=str, help='path to the corpus file')
    parser.add_argument('-mf', '--mod_file', required=True, type=str, help='path to the word2vec mod file')
    parser.add_argument('-sw', '--sample_words', type=str, help='path to the output sample words file')
    parser.add_argument('-o', '--output', type=str, help='path to the output doc codes file')
    args = parser.parse_args()

    corpus = load_corpus(args.corpus)
    docs, vocab_dict = corpus['docs'], corpus['vocab']
    w2v = load_w2v(args.mod_file)

    # doc_codes = doc_word2vec(w2v, docs, revdict(vocab_dict), args.output, avg=True)
    if args.sample_words:
        queries = ['weapon', 'christian', 'compani', 'israel', 'law', 'hockey', 'comput', 'space']
        words = []
        for each in queries:

            words.append(get_similar_words(w2v, each, topn=5))