Exemplo n.º 1
0
 def make_entity(self, text, type_, start, end):
     text = text.strip()
     if not len(text):
         return
     entity = ExtractedEntity()
     entity.text = text
     entity.type = type_
     entity.start = start
     entity.end = end
     return entity
Exemplo n.º 2
0
 def extract_spacy(self, text):
     try:
         doc = self.spacy(text)
         for ent in doc.ents:
             type_ = SPACY_TYPES.get(ent.label_)
             label = ent.text.strip()
             if type_ is not None and len(label):
                 entity = ExtractedEntity()
                 entity.text = label
                 entity.type = type_
                 entity.start = ent.start
                 entity.end = ent.end
                 yield entity
     except Exception:
         log.exception("spaCy failed")
Exemplo n.º 3
0
 def Extract(self, request, context):
     try:
         doc = self.nlp(request.text)
         count = 0
         for ent in doc.ents:
             type_ = SPACY_TYPES.get(ent.label_)
             label = ent.text.strip()
             if type_ is not None and len(label):
                 count += 1
                 entity = ExtractedEntity()
                 entity.text = label
                 entity.type = type_
                 entity.start = ent.start
                 entity.end = ent.end
                 yield entity
         log.info("[NER]: %d entities from %d chars", count,
                  len(request.text))
     except Exception as exc:
         log.exception("Failed to extract entities")
         context.abort(grpc.StatusCode.INTERNAL, str(exc))