def test_conceptfeature(): from csc.divisi.flavors import ConceptByFeatureMatrix mat = ConceptByFeatureMatrix() mat.add_triple(('dog', 'IsA', 'pet'), 1.5) eq_(mat['dog', ('right', 'IsA', 'pet')], 1.5) eq_(mat['pet', ('left', 'IsA', 'dog')], 1.5) eq_(len(mat), 2)
def _make_size_matrix(): matrixlist = [] sizefile = open("size_similarities.physnet") for line in sizefile: l = eval(line) matrixlist.append(((l[0],l[1][1],l[1][2]),40)) return ConceptByFeatureMatrix.from_triples(matrixlist)
def test_conceptfeature_fromtriple(): from csc.divisi.flavors import ConceptByFeatureMatrix mat = ConceptByFeatureMatrix.from_triples([('dog', 'IsA', 'pet'), ('dog', 'IsA', 'pet'), ('dog', 'IsA', 'animal')], accumulate=True, constant_weight=1.5) eq_(mat['dog', ('right', 'IsA', 'pet')], 3.0) eq_(mat['pet', ('left', 'IsA', 'dog')], 3.0) eq_(mat['animal', ('left', 'IsA', 'dog')], 1.5) eq_(len(mat), 4)
def test_conceptfeature_fromtriple(): from csc.divisi.flavors import ConceptByFeatureMatrix mat = ConceptByFeatureMatrix.from_triples( [('dog', 'IsA', 'pet'), ('dog', 'IsA', 'pet'), ('dog', 'IsA', 'animal')], accumulate=True, constant_weight=1.5) eq_(mat['dog', ('right', 'IsA', 'pet')], 3.0) eq_(mat['pet', ('left', 'IsA', 'dog')], 3.0) eq_(mat['animal', ('left', 'IsA', 'dog')], 1.5) eq_(len(mat), 4)
def _make_color_matrix(): matrixlist = [] for file in os.listdir('./context'): color = file.split('.')[0] fstream = open('./context/' + file,'r') sets = [x.strip('\n') for x in fstream.readlines()] clist = ','.join(sets) words = clist.split(',') for word in words: word = word.strip() if word == '': continue print color, word matrixlist.append(((word, 'HasColor', color), 10)) matrixlist.append(((word, 'HasProperty', 'colorful'), 10)) matrixlist.append(((word, 'HasProperty', color), 10)) matrixlist.append(((color, 'HasColor', color), 50)) matrixlist.append(((color, 'HasProperty', color), 50)) return ConceptByFeatureMatrix.from_triples(matrixlist)