From 76184374e2d438928417fbc2dc4a31380889ebab Mon Sep 17 00:00:00 2001 From: svlandeg Date: Mon, 22 Jul 2019 13:39:32 +0200 Subject: [PATCH] test corner cases --- spacy/kb.pyx | 3 +-- spacy/tests/pipeline/test_entity_linker.py | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/spacy/kb.pyx b/spacy/kb.pyx index 0f1c87de8..11d895eee 100644 --- a/spacy/kb.pyx +++ b/spacy/kb.pyx @@ -191,7 +191,7 @@ cdef class KnowledgeBase: def get_candidates(self, unicode alias): cdef hash_t alias_hash = self.vocab.strings[alias] - alias_index = self._alias_index.get(alias_hash) # TODO: check for error? unit test ! + alias_index = 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 diff --git a/spacy/tests/pipeline/test_entity_linker.py b/spacy/tests/pipeline/test_entity_linker.py index ab4055bba..ca6bf2b6c 100644 --- a/spacy/tests/pipeline/test_entity_linker.py +++ b/spacy/tests/pipeline/test_entity_linker.py @@ -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):