mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 17:36:30 +03:00
correct size, not counting dummy elements in the vector
This commit is contained in:
parent
33f8a0fe2e
commit
d133ffaff9
|
@ -15,10 +15,10 @@ cdef class KnowledgeBase:
|
|||
return self.get_size_entities()
|
||||
|
||||
def get_size_entities(self):
|
||||
return self._entries.size()
|
||||
return self._entries.size() - 1 # not counting dummy element on index 0
|
||||
|
||||
def get_size_aliases(self):
|
||||
return self._aliases_table.size()
|
||||
return self._aliases_table.size() - 1 # not counting dummy element on index 0
|
||||
|
||||
def add_entity(self, unicode entity_id, float prob, vectors=None, features=None):
|
||||
cdef hash_t id_hash = self.strings.add(entity_id)
|
||||
|
|
|
@ -21,35 +21,29 @@ def create_kb():
|
|||
print(" adding entity", entity_5301561)
|
||||
mykb.add_entity(entity_id=entity_5301561, prob=0.5)
|
||||
|
||||
print(" adding entity", entity_5301561)
|
||||
mykb.add_entity(entity_id=entity_5301561, prob=0.5)
|
||||
|
||||
print("kb size", len(mykb), mykb.get_size_entities(), mykb.get_size_aliases())
|
||||
|
||||
# adding aliases
|
||||
alias = "douglassss"
|
||||
print(" adding alias", alias)
|
||||
mykb.add_alias(alias=alias, entities=["Q42", "Q5301561"], probabilities=[0.8, 0.2])
|
||||
|
||||
print("kb size", len(mykb), mykb.get_size_entities(), mykb.get_size_aliases())
|
||||
|
||||
print("candidates for", alias)
|
||||
candidates = mykb.get_candidates(alias)
|
||||
print(" ", candidates)
|
||||
|
||||
print(" adding alias", alias)
|
||||
mykb.add_alias(alias=alias, entities=["Q42"], probabilities=[0.9])
|
||||
|
||||
print("kb size", len(mykb), mykb.get_size_entities(), mykb.get_size_aliases())
|
||||
alias1 = "douglassss"
|
||||
print(" adding alias", alias1)
|
||||
mykb.add_alias(alias=alias1, entities=["Q42", "Q5301561"], probabilities=[0.8, 0.2])
|
||||
|
||||
alias2 = "johny"
|
||||
print(" adding alias2", alias2)
|
||||
mykb.add_alias(alias=alias2, entities=["Q0", "Q42"], probabilities=[0.3, 1.1])
|
||||
print(" adding alias", alias2)
|
||||
mykb.add_alias(alias=alias2, entities=["Q0", "Q42", "Q5301561"], probabilities=[0.3, 0.1, 0.4])
|
||||
|
||||
alias3 = "adam"
|
||||
print(" adding alias", alias3)
|
||||
mykb.add_alias(alias=alias3, entities=["Q42"], probabilities=[1.0])
|
||||
|
||||
print("kb size", len(mykb), mykb.get_size_entities(), mykb.get_size_aliases())
|
||||
|
||||
print("candidates for", alias)
|
||||
candidates = mykb.get_candidates(alias)
|
||||
print("candidates for", alias1)
|
||||
candidates = mykb.get_candidates(alias1)
|
||||
print(" ", candidates)
|
||||
|
||||
print("candidates for", alias3)
|
||||
candidates = mykb.get_candidates(alias3)
|
||||
print(" ", candidates)
|
||||
|
||||
|
||||
|
|
|
@ -14,7 +14,12 @@ def test_kb_valid_entities():
|
|||
mykb.add_entity(entity_id="Q3", prob=0.5)
|
||||
|
||||
# adding aliases
|
||||
mykb.add_alias(alias="douglassss", entities=["Q2", "Q3"], probabilities=[0.8, 0.2])
|
||||
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 corresponding KB
|
||||
assert(mykb.get_size_entities() == 3)
|
||||
assert(mykb.get_size_aliases() == 2)
|
||||
|
||||
|
||||
def test_kb_invalid_entities():
|
||||
|
@ -28,7 +33,7 @@ def test_kb_invalid_entities():
|
|||
|
||||
# adding aliases - should fail because one of the given IDs is not valid
|
||||
with pytest.raises(ValueError):
|
||||
mykb.add_alias(alias="douglassss", entities=["Q2", "Q342"], probabilities=[0.8, 0.2])
|
||||
mykb.add_alias(alias="douglas", entities=["Q2", "Q342"], probabilities=[0.8, 0.2])
|
||||
|
||||
|
||||
def test_kb_invalid_probabilities():
|
||||
|
|
Loading…
Reference in New Issue
Block a user