test corner cases

This commit is contained in:
svlandeg 2019-07-22 13:39:32 +02:00
parent 9f8c1e71a2
commit 76184374e2
2 changed files with 3 additions and 2 deletions

View File

@ -191,7 +191,7 @@ cdef class KnowledgeBase:
def get_candidates(self, unicode alias):
cdef hash_t alias_hash = self.vocab.strings[alias]
alias_index = <int64_t>self._alias_index.get(alias_hash) # TODO: check for error? unit test !
alias_index = <int64_t>self._alias_index.get(alias_hash)
alias_entry = self._aliases_table[alias_index]
return [Candidate(kb=self,
@ -219,7 +219,6 @@ cdef class KnowledgeBase:
cdef hash_t alias_hash = self.vocab.strings[alias]
cdef hash_t entity_hash = self.vocab.strings[entity]
# TODO: error ?
if entity_hash not in self._entry_index or alias_hash not in self._alias_index:
return 0.0

View File

@ -43,6 +43,8 @@ def test_kb_valid_entities(nlp):
# test retrieval of prior probabilities
assert_almost_equal(mykb.get_prior_prob(entity="Q2", alias="douglas"), 0.8)
assert_almost_equal(mykb.get_prior_prob(entity="Q3", alias="douglas"), 0.2)
assert_almost_equal(mykb.get_prior_prob(entity="Q342", alias="douglas"), 0.0)
assert_almost_equal(mykb.get_prior_prob(entity="Q3", alias="douglassssss"), 0.0)
def test_kb_invalid_entities(nlp):