unit test on number of candidates generated

This commit is contained in:
svlandeg 2019-03-21 12:48:59 +01:00
parent 0ff4ce6c59
commit 34969dddeb

View File

@ -63,3 +63,20 @@ def test_kb_invalid_combination():
with pytest.raises(ValueError): with pytest.raises(ValueError):
mykb.add_alias(alias="douglassss", entities=["Q2", "Q3"], probabilities=[0.3, 0.4, 0.1]) mykb.add_alias(alias="douglassss", entities=["Q2", "Q3"], probabilities=[0.3, 0.4, 0.1])
def test_candidate_generation():
"""Test correct candidate generation"""
mykb = KnowledgeBase()
# adding entities
mykb.add_entity(entity_id="Q1", prob=0.9)
mykb.add_entity(entity_id="Q2", prob=0.2)
mykb.add_entity(entity_id="Q3", prob=0.5)
# adding aliases
mykb.add_alias(alias="douglas", entities=["Q2", "Q3"], probabilities=[0.8, 0.2])
mykb.add_alias(alias="adam", entities=["Q2"], probabilities=[0.9])
# test the size of the relevant candidates
assert(len(mykb.get_candidates("douglas")) == 2)
assert(len(mykb.get_candidates("adam")) == 1)