from __future__ import division
import sys,json,math

def load_contexts(filename):
    # Returns a dict containing a {word: contextcount} mapping.
    # It loads everything into memory.

    data = {}
    for word,ccdict in stream_contexts(filename):
        data[word] = ccdict
    print "file %s has contexts for %s words" % (filename, len(data))
    return data

def stream_contexts(filename):
    # Streams through (word, countextcount) pairs.
    # Does NOT load everything at once.
    # This is a Python generator, not a normal function.
    for line in open(filename):
        word, n, ccdict = line.split("\t")
        n = int(n)
        ccdict = json.loads(ccdict)
        yield word, ccdict

def cossim(v1,v2):
    # Take two context-count dictionaries as input
    # and return the cosine similarity between the two vectors.
    ##
    return 0

def cloud_cat_dog():
    word_to_ccdict = load_contexts("twcounts.cloud_cat_dog")
    ##

def show_nearest(word_to_ccdict, w):
    print "Words most similar to", w
    ##

