mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-11-04 09:57:26 +03:00 
			
		
		
		
	* Move test * Allow default in Lookups.get_table * Start with blank tables in Lookups.from_bytes * Refactor lemmatizer to hold instance of Lookups * Get lookups table within the lemmatization methods to make sure it references the correct table (even if the table was replaced or modified, e.g. when loading a model from disk) * Deprecate other arguments on Lemmatizer.__init__ and expect Lookups for consistency * Remove old and unsupported Lemmatizer.load classmethod * Refactor language-specific lemmatizers to inherit as much as possible from base class and override only what they need * Update tests and docs * Fix more tests * Fix lemmatizer * Upgrade pytest to try and fix weird CI errors * Try pytest 4.6.5
		
			
				
	
	
		
			41 lines
		
	
	
		
			935 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			935 B
		
	
	
	
		
			Python
		
	
	
	
	
	
# coding: utf-8
 | 
						|
from __future__ import unicode_literals
 | 
						|
 | 
						|
import pytest
 | 
						|
from spacy.vocab import Vocab
 | 
						|
from spacy.tokens import Doc
 | 
						|
from spacy.lemmatizer import Lemmatizer
 | 
						|
from spacy.lookups import Lookups
 | 
						|
 | 
						|
 | 
						|
@pytest.fixture
 | 
						|
def lemmatizer():
 | 
						|
    lookups = Lookups()
 | 
						|
    lookups.add_table("lemma_lookup", {"dogs": "dog", "boxen": "box", "mice": "mouse"})
 | 
						|
    return Lemmatizer(lookups)
 | 
						|
 | 
						|
 | 
						|
@pytest.fixture
 | 
						|
def vocab(lemmatizer):
 | 
						|
    return Vocab(lemmatizer=lemmatizer)
 | 
						|
 | 
						|
 | 
						|
def test_empty_doc(vocab):
 | 
						|
    doc = Doc(vocab)
 | 
						|
    assert len(doc) == 0
 | 
						|
 | 
						|
 | 
						|
def test_single_word(vocab):
 | 
						|
    doc = Doc(vocab, words=["a"])
 | 
						|
    assert doc.text == "a "
 | 
						|
    doc = Doc(vocab, words=["a"], spaces=[False])
 | 
						|
    assert doc.text == "a"
 | 
						|
 | 
						|
 | 
						|
def test_lookup_lemmatization(vocab):
 | 
						|
    doc = Doc(vocab, words=["dogs", "dogses"])
 | 
						|
    assert doc[0].text == "dogs"
 | 
						|
    assert doc[0].lemma_ == "dog"
 | 
						|
    assert doc[1].text == "dogses"
 | 
						|
    assert doc[1].lemma_ == "dogses"
 |