Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
['a', 'z', 'f'],
['c', 'z', 'f'],
['b', 'z', 'f'],
])
model = ComplEx(k=2, batches_count=2)
with pytest.raises(ValueError): # Model not fitted
query_topn(model, top_n=2)
model.fit(X)
with pytest.raises(ValueError):
query_topn(model, top_n=2)
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a')
with pytest.raises(ValueError):
query_topn(model, top_n=2, relation='y')
with pytest.raises(ValueError):
query_topn(model, top_n=2, tail='e')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='y', tail='e')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='xx', relation='y')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='yakkety')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='sax')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='x', rels_to_consider=['y', 'z'])
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='f', rels_to_consider=['y', 'z', 'error'])
with pytest.raises(ValueError): # Model not fitted
query_topn(model, top_n=2)
model.fit(X)
with pytest.raises(ValueError):
query_topn(model, top_n=2)
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a')
with pytest.raises(ValueError):
query_topn(model, top_n=2, relation='y')
with pytest.raises(ValueError):
query_topn(model, top_n=2, tail='e')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='y', tail='e')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='xx', relation='y')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='yakkety')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='sax')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='x', rels_to_consider=['y', 'z'])
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='f', rels_to_consider=['y', 'z', 'error'])
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='e', rels_to_consider='y')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='x', ents_to_consider=['zz', 'top'])
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='e', ents_to_consider=['a', 'b'])
['b', 'y', 'a'],
['a', 'y', 'c'],
['c', 'y', 'a'],
['a', 'y', 'd'],
['c', 'x', 'd'],
['b', 'y', 'c'],
['f', 'y', 'e'],
['a', 'z', 'f'],
['c', 'z', 'f'],
['b', 'z', 'f'],
])
model = ComplEx(k=2, batches_count=2)
with pytest.raises(ValueError): # Model not fitted
query_topn(model, top_n=2)
model.fit(X)
with pytest.raises(ValueError):
query_topn(model, top_n=2)
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a')
with pytest.raises(ValueError):
query_topn(model, top_n=2, relation='y')
with pytest.raises(ValueError):
query_topn(model, top_n=2, tail='e')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='y', tail='e')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='xx', relation='y')
with pytest.raises(ValueError):
model = ComplEx(k=2, batches_count=2)
with pytest.raises(ValueError): # Model not fitted
query_topn(model, top_n=2)
model.fit(X)
with pytest.raises(ValueError):
query_topn(model, top_n=2)
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a')
with pytest.raises(ValueError):
query_topn(model, top_n=2, relation='y')
with pytest.raises(ValueError):
query_topn(model, top_n=2, tail='e')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='y', tail='e')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='xx', relation='y')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='yakkety')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='sax')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='x', rels_to_consider=['y', 'z'])
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='f', rels_to_consider=['y', 'z', 'error'])
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='e', rels_to_consider='y')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='x', ents_to_consider=['zz', 'top'])
query_topn(model, top_n=2, head='a', tail='e', ents_to_consider=['a', 'b'])
subj, pred, obj, top_n = 'a', 'x', 'e', 3
Y, S = query_topn(model, top_n=top_n, head=subj, relation=pred)
assert len(Y) == len(S)
assert len(Y) == top_n
assert np.all(Y[:, 0] == subj)
assert np.all(Y[:, 1] == pred)
Y, S = query_topn(model, top_n=top_n, relation=pred, tail=obj)
assert np.all(Y[:, 1] == pred)
assert np.all(Y[:, 2] == obj)
ents_to_con = ['a', 'b', 'c', 'd']
Y, S = query_topn(model, top_n=top_n, relation=pred, tail=obj, ents_to_consider=ents_to_con)
assert np.all([x in ents_to_con for x in Y[:, 0]])
rels_to_con = ['y', 'x']
Y, S = query_topn(model, top_n=10, head=subj, tail=obj, rels_to_consider=rels_to_con)
assert np.all([x in rels_to_con for x in Y[:, 1]])
Y, S = query_topn(model, top_n=10, relation=pred, tail=obj)
assert all(S[i] >= S[i + 1] for i in range(len(S) - 1))
with pytest.raises(ValueError):
query_topn(model, top_n=2)
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a')
with pytest.raises(ValueError):
query_topn(model, top_n=2, relation='y')
with pytest.raises(ValueError):
query_topn(model, top_n=2, tail='e')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='y', tail='e')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='xx', relation='y')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='yakkety')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='sax')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='x', rels_to_consider=['y', 'z'])
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='f', rels_to_consider=['y', 'z', 'error'])
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='e', rels_to_consider='y')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='x', ents_to_consider=['zz', 'top'])
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='e', ents_to_consider=['a', 'b'])
subj, pred, obj, top_n = 'a', 'x', 'e', 3
Y, S = query_topn(model, top_n=top_n, head=subj, relation=pred)
assert len(Y) == len(S)
assert len(Y) == top_n
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='sax')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='x', rels_to_consider=['y', 'z'])
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='f', rels_to_consider=['y', 'z', 'error'])
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='e', rels_to_consider='y')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='x', ents_to_consider=['zz', 'top'])
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='e', ents_to_consider=['a', 'b'])
subj, pred, obj, top_n = 'a', 'x', 'e', 3
Y, S = query_topn(model, top_n=top_n, head=subj, relation=pred)
assert len(Y) == len(S)
assert len(Y) == top_n
assert np.all(Y[:, 0] == subj)
assert np.all(Y[:, 1] == pred)
Y, S = query_topn(model, top_n=top_n, relation=pred, tail=obj)
assert np.all(Y[:, 1] == pred)
assert np.all(Y[:, 2] == obj)
ents_to_con = ['a', 'b', 'c', 'd']
Y, S = query_topn(model, top_n=top_n, relation=pred, tail=obj, ents_to_consider=ents_to_con)
assert np.all([x in ents_to_con for x in Y[:, 0]])
rels_to_con = ['y', 'x']
Y, S = query_topn(model, top_n=10, head=subj, tail=obj, rels_to_consider=rels_to_con)
assert np.all([x in rels_to_con for x in Y[:, 1]])
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='xx', relation='y')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='yakkety')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='sax')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='x', rels_to_consider=['y', 'z'])
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='f', rels_to_consider=['y', 'z', 'error'])
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='e', rels_to_consider='y')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='x', ents_to_consider=['zz', 'top'])
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='e', ents_to_consider=['a', 'b'])
subj, pred, obj, top_n = 'a', 'x', 'e', 3
Y, S = query_topn(model, top_n=top_n, head=subj, relation=pred)
assert len(Y) == len(S)
assert len(Y) == top_n
assert np.all(Y[:, 0] == subj)
assert np.all(Y[:, 1] == pred)
Y, S = query_topn(model, top_n=top_n, relation=pred, tail=obj)
assert np.all(Y[:, 1] == pred)
assert np.all(Y[:, 2] == obj)
ents_to_con = ['a', 'b', 'c', 'd']
Y, S = query_topn(model, top_n=top_n, relation=pred, tail=obj, ents_to_consider=ents_to_con)
assert np.all([x in ents_to_con for x in Y[:, 0]])
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='y', tail='e')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='xx', relation='y')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='yakkety')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='sax')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='x', rels_to_consider=['y', 'z'])
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='f', rels_to_consider=['y', 'z', 'error'])
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='e', rels_to_consider='y')
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', relation='x', ents_to_consider=['zz', 'top'])
with pytest.raises(ValueError):
query_topn(model, top_n=2, head='a', tail='e', ents_to_consider=['a', 'b'])
subj, pred, obj, top_n = 'a', 'x', 'e', 3
Y, S = query_topn(model, top_n=top_n, head=subj, relation=pred)
assert len(Y) == len(S)
assert len(Y) == top_n
assert np.all(Y[:, 0] == subj)
assert np.all(Y[:, 1] == pred)
Y, S = query_topn(model, top_n=top_n, relation=pred, tail=obj)
assert np.all(Y[:, 1] == pred)
assert np.all(Y[:, 2] == obj)
ents_to_con = ['a', 'b', 'c', 'd']
assert np.all(Y[:, 0] == subj)
assert np.all(Y[:, 1] == pred)
Y, S = query_topn(model, top_n=top_n, relation=pred, tail=obj)
assert np.all(Y[:, 1] == pred)
assert np.all(Y[:, 2] == obj)
ents_to_con = ['a', 'b', 'c', 'd']
Y, S = query_topn(model, top_n=top_n, relation=pred, tail=obj, ents_to_consider=ents_to_con)
assert np.all([x in ents_to_con for x in Y[:, 0]])
rels_to_con = ['y', 'x']
Y, S = query_topn(model, top_n=10, head=subj, tail=obj, rels_to_consider=rels_to_con)
assert np.all([x in rels_to_con for x in Y[:, 1]])
Y, S = query_topn(model, top_n=10, relation=pred, tail=obj)
assert all(S[i] >= S[i + 1] for i in range(len(S) - 1))