class Divsi: svd = None def __init__(self): self.helper = DivsiHelper() self.cnet_normalized = conceptnet_2d_from_db('en') self.affectwn_raw = get_picklecached_thing('data/divsi/affectiveWNmatrix.pickle') self.affectWN = self.affectwn_raw.normalized() self.analogySpace = Blend([self.affectWN, self.cnet_normalized]).svd() self.EN_NL = get_nl('en') def load_svd(self, k=100): svd = self.tensor.svd(k=k) return svd def concept_similarity(self, universal_word): similarity = {} common = {} for interesting in self.helper.interestingTags(universal_word): L = interesting[0] R = interesting[1] try: left = self.analogySpace.weighted_u_vec(L) right = self.analogySpace.weighted_u_vec(R) similar = left.hat() * right.hat() common[L] = self.analogySpace.u_dotproducts_with(left).top_items(10) common[R] = self.analogySpace.u_dotproducts_with(right).top_items(10) similarity[similar] = [L, R] except Exception, E: pass sorted_similarity = self.helper.sortDictionary(similarity) return (sorted_similarity, common)