# -*- coding:utf-8 -*-
import numpy as np
from q84 import make_word_index
from q86 import get_word_vector

ppmi_file = 'ppmi.txt'
matrix_file = 'matrix_d'
word1 = 'United_States'
word2 = 'U.S'

def cosine_similarity(word1, word2):
    t_idx = make_word_index(ppmi_file, 0)
    a = np.array(get_word_vector(word1, t_idx))
    b = np.array(get_word_vector(word2, t_idx))
    return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))

def main():
    sim = cosine_similarity(word1, word2)
    print '"%s" and "%s" of similarity is %s' % (word1, word2, sim)

if __name__ == '__main__':
    main()
