Exemplo n.º 1
0
def test_get_doc_char_span(vocab, tokens, i, j, destructive, covering,
                           expected, label):
    doc = Doc(vocab, tokens)
    span = get_doc_char_span(doc,
                             i,
                             j,
                             destructive=destructive,
                             covering=covering,
                             label=label or "")
    assert span.text == expected
    if label is not None:
        assert span.label_ == label
Exemplo n.º 2
0
 def __call__(self, doc: Doc) -> Doc:
     matches = self.get_char_spans(doc.text)
     spans = []
     for i, j, text in matches:
         span = get_doc_char_span(doc,
                                  i,
                                  j,
                                  destructive=self.destructive,
                                  label=self.get_label(text))
         if span:
             spans.append(span)
     [s.text for s in spans
      ]  # TODO: resolve the evaluation bug and remove this line
     ents = filter_spans(doc.ents + tuple(spans))
     doc.ents = tuple(ents)
     return doc
Exemplo n.º 3
0
 def __call__(self, doc: Doc) -> Doc:
     text = self._to_text(doc)
     _matches = list(self.get_char_spans(text))
     matches = _modify_spans(_matches, text, doc.text)
     spans = []
     for i, j, text in matches:
         if i is None or j is None:
             continue
         span = get_doc_char_span(
             doc,
             i,
             j,
             destructive=self.destructive,
             covering=not self.destructive,
             label=self.get_label(text),
         )
         if span and self._to_text(span) == text:
             spans.append(span)
     [s.text for s in spans
      ]  # TODO: resolve the evaluation bug and remove this line
     ents = filter_spans(doc.ents + tuple(spans))
     doc.ents = tuple(ents)
     return doc
Exemplo n.º 4
0
def test_get_doc_char_span(vocab, tokens, i, j, expected):
    doc = Doc(vocab, tokens)
    span = get_doc_char_span(doc, i, j)
    assert span.text == expected