2019-11-07 14:01:06 +03:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from mock import Mock
|
|
|
|
from spacy.matcher import DependencyMatcher
|
|
|
|
from ..util import get_doc
|
|
|
|
|
|
|
|
|
|
|
|
def test_issue4590(en_vocab):
|
|
|
|
"""Test that matches param in on_match method are the same as matches run with no on_match method"""
|
|
|
|
pattern = [
|
|
|
|
{"SPEC": {"NODE_NAME": "jumped"}, "PATTERN": {"ORTH": "jumped"}},
|
2019-11-20 15:15:24 +03:00
|
|
|
{
|
|
|
|
"SPEC": {"NODE_NAME": "fox", "NBOR_RELOP": ">", "NBOR_NAME": "jumped"},
|
|
|
|
"PATTERN": {"ORTH": "fox"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"SPEC": {"NODE_NAME": "quick", "NBOR_RELOP": ".", "NBOR_NAME": "jumped"},
|
|
|
|
"PATTERN": {"ORTH": "fox"},
|
|
|
|
},
|
2019-11-07 14:01:06 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
on_match = Mock()
|
|
|
|
|
|
|
|
matcher = DependencyMatcher(en_vocab)
|
|
|
|
matcher.add("pattern", on_match, pattern)
|
|
|
|
|
|
|
|
text = "The quick brown fox jumped over the lazy fox"
|
|
|
|
heads = [3, 2, 1, 1, 0, -1, 2, 1, -3]
|
2020-03-02 13:49:28 +03:00
|
|
|
deps = ["det", "amod", "amod", "nsubj", "ROOT", "prep", "det", "amod", "pobj"]
|
2019-11-20 15:15:24 +03:00
|
|
|
|
2019-11-07 14:01:06 +03:00
|
|
|
doc = get_doc(en_vocab, text.split(), heads=heads, deps=deps)
|
2019-11-20 15:15:24 +03:00
|
|
|
|
2019-11-07 14:01:06 +03:00
|
|
|
matches = matcher(doc)
|
2019-11-20 15:15:24 +03:00
|
|
|
|
2019-11-07 14:01:06 +03:00
|
|
|
on_match_args = on_match.call_args
|
|
|
|
|
|
|
|
assert on_match_args[0][3] == matches
|