mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-11-04 09:57:26 +03:00 
			
		
		
		
	Add test utils and get_doc helper function
Create Doc object from given vocab, words and annotations to allow tests not to depend on loading the models.
This commit is contained in:
		
							parent
							
								
									e12c90e03f
								
							
						
					
					
						commit
						909f24d7df
					
				
							
								
								
									
										21
									
								
								spacy/tests/util.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								spacy/tests/util.py
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,21 @@
 | 
				
			||||||
 | 
					# coding: utf-8
 | 
				
			||||||
 | 
					from __future__ import unicode_literals
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from ..tokens import Doc
 | 
				
			||||||
 | 
					from ..attrs import ORTH, POS, HEAD, DEP
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def get_doc(vocab, words, tags=None, heads=None, deps=None):
 | 
				
			||||||
 | 
					    """Create Doc object from given vocab, words and annotations."""
 | 
				
			||||||
 | 
					    tags = tags or [''] * len(words)
 | 
				
			||||||
 | 
					    heads = heads or [0] * len(words)
 | 
				
			||||||
 | 
					    deps = deps or [''] * len(words)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    doc = Doc(vocab, words=words)
 | 
				
			||||||
 | 
					    attrs = doc.to_array([POS, HEAD, DEP])
 | 
				
			||||||
 | 
					    for i, (tag, head, dep) in enumerate(zip(tags, heads, deps)):
 | 
				
			||||||
 | 
					        attrs[i, 0] = doc.vocab.strings[tag]
 | 
				
			||||||
 | 
					        attrs[i, 1] = head
 | 
				
			||||||
 | 
					        attrs[i, 2] = doc.vocab.strings[dep]
 | 
				
			||||||
 | 
					    doc.from_array([POS, HEAD, DEP], attrs)
 | 
				
			||||||
 | 
					    return doc
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user