mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-10-30 23:47:31 +03:00 
			
		
		
		
	Only run noun chunks iterator in Span if available (closes #3199)
This commit is contained in:
		
							parent
							
								
									ff36b14cb2
								
							
						
					
					
						commit
						ea07f3022e
					
				
							
								
								
									
										15
									
								
								spacy/tests/regression/test_issue3199.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								spacy/tests/regression/test_issue3199.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,15 @@ | |||
| # coding: utf8 | ||||
| from __future__ import unicode_literals | ||||
| 
 | ||||
| from spacy.tokens import Doc | ||||
| from spacy.vocab import Vocab | ||||
| 
 | ||||
| 
 | ||||
| def test_issue3199(): | ||||
|     """Test that Span.noun_chunks works correctly if no noun chunks iterator | ||||
|     is available. To make this test future-proof, we're constructing a Doc | ||||
|     with a new Vocab here and setting is_parsed to make sure the noun chunks run. | ||||
|     """ | ||||
|     doc = Doc(Vocab(), words=["This", "is", "a", "sentence"]) | ||||
|     doc.is_parsed = True | ||||
|     assert list(doc[0:3].noun_chunks) == [] | ||||
|  | @ -403,8 +403,9 @@ cdef class Span: | |||
|             # objects. See Issue #375 | ||||
|             spans = [] | ||||
|             cdef attr_t label | ||||
|             for start, end, label in self.doc.noun_chunks_iterator(self): | ||||
|                 spans.append(Span(self.doc, start, end, label=label)) | ||||
|             if self.doc.noun_chunks_iterator is not None: | ||||
|                 for start, end, label in self.doc.noun_chunks_iterator(self): | ||||
|                     spans.append(Span(self.doc, start, end, label=label)) | ||||
|             for span in spans: | ||||
|                 yield span | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user