adding and retrieving aliases

This commit is contained in:
svlandeg 2019-03-18 17:50:01 +01:00
parent a14fb54b17
commit a4d876d471
3 changed files with 28 additions and 5 deletions

View File

@ -116,4 +116,10 @@ cdef class KnowledgeBase:
probs=probs
))
self._alias_index[alias_key] = alias_index
return alias_index
return alias_index
cdef inline c_get_candidates(self, hash_t alias_key):
cdef int64_t alias_index = self._alias_index[alias_key]
cdef _AliasC candidates = self._aliases_table[alias_index]
print("candidates", candidates)

View File

@ -38,5 +38,8 @@ cdef class KnowledgeBase:
self.c_add_aliases(alias_key=alias_hash, entities=entities, probabilities=probabilities)
def get_candidates(self, unicode alias):
cdef hash_t alias_hash = hash_string(alias)
cdef _AliasC candidates = self.c_get_candidates(alias_key=alias_hash)
return candidates

View File

@ -6,12 +6,26 @@ def create_kb():
mykb = KnowledgeBase()
print("kb size", len(mykb))
entity_id = "Q42"
mykb.add_entity(entity_id=entity_id, prob=0.5)
print("adding entity", entity_id)
# adding entities
entity_42 = "Q42" # douglas adams
mykb.add_entity(entity_id=entity_42, prob=0.5)
print("adding entity", entity_42)
entity_5301561 = "Q5301561"
mykb.add_entity(entity_id=entity_5301561, prob=0.5)
print("adding entity", entity_5301561)
print("kb size", len(mykb))
# adding aliases
alias = "douglas"
print("adding alias", alias)
mykb.add_alias(alias=alias, entities=["Q42", "Q5301561"], probabilities=[0.8, 0.2])
print("kb size", len(mykb))
print("aliases for", alias)
mykb.get_candidates(alias)
def add_el():
nlp = spacy.load('en_core_web_sm')