spaCy/spacy/tests/regression/test_issue6839.py
Peter Baumann 61b04a70d5
Run PhraseMatcher on Spans (#6918)
* Add regression test

* Run PhraseMatcher on Spans

* Add test for PhraseMatcher on Spans and Docs

* Add SCA

* Add test with 3 matches in Doc, 1 match in Span

* Update docs

* Use doc.length for find_matches in tokenizer

Co-authored-by: Adriane Boyd <adrianeboyd@gmail.com>
2021-02-10 23:43:32 +11:00

16 lines
512 B
Python

from spacy.tokens import Doc
from spacy.matcher import PhraseMatcher
def test_span_in_phrasematcher(en_vocab):
"""Ensure that PhraseMatcher accepts Span as input"""
doc = Doc(en_vocab,
words=["I", "like", "Spans", "and", "Docs", "in", "my", "input", ",", "and", "nothing", "else", "."])
span = doc[:8]
pattern = Doc(en_vocab, words=["Spans", "and", "Docs"])
matcher = PhraseMatcher(en_vocab)
matcher.add("SPACY", [pattern])
matches = matcher(span)
assert matches