mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-10-30 23:47:31 +03:00 
			
		
		
		
	Merge branch 'develop' into feature/disable-pipes
This commit is contained in:
		
						commit
						de1e5f35d5
					
				|  | @ -230,7 +230,7 @@ cdef class Matcher: | |||
|         key (unicode): The match ID. | ||||
|         RETURNS (bool): Whether the matcher contains rules for this match ID. | ||||
|         """ | ||||
|         return key in self._patterns | ||||
|         return self._normalize_key(key) in self._patterns | ||||
| 
 | ||||
|     def add(self, key, on_match, *patterns): | ||||
|         """Add a match-rule to the matcher. A match-rule consists of: an ID key, | ||||
|  | @ -490,7 +490,7 @@ cdef class PhraseMatcher: | |||
|         RETURNS (bool): Whether the matcher contains rules for this match ID. | ||||
|         """ | ||||
|         cdef hash_t ent_id = self.matcher._normalize_key(key) | ||||
|         return ent_id in self.phrase_ids | ||||
|         return ent_id in self._callbacks | ||||
| 
 | ||||
|     def __reduce__(self): | ||||
|         return (self.__class__, (self.vocab,), None, None) | ||||
|  |  | |||
|  | @ -48,7 +48,7 @@ from thinc.neural.util import get_array_module | |||
| from .. import util | ||||
| from ..util import get_async, get_cuda_stream | ||||
| from .._ml import zero_init, PrecomputableAffine, PrecomputableMaxouts | ||||
| from .._ml import Tok2Vec, doc2feats, rebatch, fine_tune | ||||
| from .._ml import Tok2Vec, doc2feats, rebatch | ||||
| from .._ml import Residual, drop_layer, flatten | ||||
| from .._ml import link_vectors_to_models | ||||
| from .._ml import HistoryFeatures | ||||
|  |  | |||
|  | @ -64,6 +64,12 @@ def test_matcher_init(en_vocab, words): | |||
|     assert matcher(doc) == [] | ||||
| 
 | ||||
| 
 | ||||
| def test_matcher_contains(matcher): | ||||
|     matcher.add('TEST', None, [{'ORTH': 'test'}]) | ||||
|     assert 'TEST' in matcher | ||||
|     assert 'TEST2' not in matcher | ||||
| 
 | ||||
| 
 | ||||
| def test_matcher_no_match(matcher): | ||||
|     words = ["I", "like", "cheese", "."] | ||||
|     doc = get_doc(matcher.vocab, words) | ||||
|  | @ -113,6 +119,7 @@ def test_matcher_empty_dict(en_vocab): | |||
|     matches = matcher(doc) | ||||
|     assert matches[0][1:] == (0, 2) | ||||
| 
 | ||||
| 
 | ||||
| def test_matcher_operator_shadow(en_vocab): | ||||
|     matcher = Matcher(en_vocab) | ||||
|     abc = ["a", "b", "c"] | ||||
|  | @ -124,6 +131,7 @@ def test_matcher_operator_shadow(en_vocab): | |||
|     assert len(matches) == 1 | ||||
|     assert matches[0][1:] == (0, 3) | ||||
| 
 | ||||
| 
 | ||||
| def test_matcher_phrase_matcher(en_vocab): | ||||
|     words = ["Google", "Now"] | ||||
|     doc = get_doc(en_vocab, words) | ||||
|  | @ -134,6 +142,22 @@ def test_matcher_phrase_matcher(en_vocab): | |||
|     assert len(matcher(doc)) == 1 | ||||
| 
 | ||||
| 
 | ||||
| def test_phrase_matcher_length(en_vocab): | ||||
|     matcher = PhraseMatcher(en_vocab) | ||||
|     assert len(matcher) == 0 | ||||
|     matcher.add('TEST', None, get_doc(en_vocab, ['test'])) | ||||
|     assert len(matcher) == 1 | ||||
|     matcher.add('TEST2', None, get_doc(en_vocab, ['test2'])) | ||||
|     assert len(matcher) == 2 | ||||
| 
 | ||||
| 
 | ||||
| def test_phrase_matcher_contains(en_vocab): | ||||
|     matcher = PhraseMatcher(en_vocab) | ||||
|     matcher.add('TEST', None, get_doc(en_vocab, ['test'])) | ||||
|     assert 'TEST' in matcher | ||||
|     assert 'TEST2' not in matcher | ||||
| 
 | ||||
| 
 | ||||
| def test_matcher_match_zero(matcher): | ||||
|     words1 = 'He said , " some words " ...'.split() | ||||
|     words2 = 'He said , " some three words " ...'.split() | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user