mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-10-31 07:57:35 +03:00 
			
		
		
		
	Fix on_match callback for DependencyMatcher (#6313)
Fix `DependencyMatcher` so that the callback is called only once per match.
This commit is contained in:
		
							parent
							
								
									2918923541
								
							
						
					
					
						commit
						5d2cb86c34
					
				|  | @ -218,11 +218,16 @@ def test_dependency_matcher_callback(en_vocab, doc): | ||||||
|     pattern = [ |     pattern = [ | ||||||
|         {"RIGHT_ID": "quick", "RIGHT_ATTRS": {"ORTH": "quick"}}, |         {"RIGHT_ID": "quick", "RIGHT_ATTRS": {"ORTH": "quick"}}, | ||||||
|     ] |     ] | ||||||
|  |     nomatch_pattern = [ | ||||||
|  |         {"RIGHT_ID": "quick", "RIGHT_ATTRS": {"ORTH": "NOMATCH"}}, | ||||||
|  |     ] | ||||||
| 
 | 
 | ||||||
|     matcher = DependencyMatcher(en_vocab) |     matcher = DependencyMatcher(en_vocab) | ||||||
|     mock = Mock() |     mock = Mock() | ||||||
|     matcher.add("pattern", [pattern], on_match=mock) |     matcher.add("pattern", [pattern], on_match=mock) | ||||||
|  |     matcher.add("nomatch_pattern", [nomatch_pattern], on_match=mock) | ||||||
|     matches = matcher(doc) |     matches = matcher(doc) | ||||||
|  |     assert len(matches) == 1 | ||||||
|     mock.assert_called_once_with(matcher, doc, 0, matches) |     mock.assert_called_once_with(matcher, doc, 0, matches) | ||||||
| 
 | 
 | ||||||
|     # check that matches with and without callback are the same (#4590) |     # check that matches with and without callback are the same (#4590) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user