mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-26 09:56:28 +03:00
adding and retrieving aliases
This commit is contained in:
parent
cf34113250
commit
151b855cc8
|
@ -117,3 +117,9 @@ cdef class KnowledgeBase:
|
|||
))
|
||||
self._alias_index[alias_key] = 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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue
Block a user