<s> from unittest import TestCase <EOL> from tests . factories import SentencedIEDocFactory <EOL> from iepy . data . models import IEDocument <EOL> from iepy . preprocess . pipeline import PreProcessSteps <EOL> from iepy . preprocess . tagger import TaggerRunner , StanfordTaggerRunner <EOL> from . manager_case import ManagerTestCase <EOL> class TestTaggerRunner ( ManagerTestCase ) : <EOL> ManagerClass = IEDocument <EOL> def test_tagger_runner_is_calling_postagger ( self ) : <EOL> doc = SentencedIEDocFactory ( text = '<STR_LIT>' ) <EOL> expected_postags = [ [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:.>' ] , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:.>' ] , [ '<STR_LIT>' , '<STR_LIT:.>' ] ] <EOL> i = iter ( expected_postags ) <EOL> def postagger ( sents ) : <EOL> return ( zip ( sent , next ( i ) ) for sent in sents ) <EOL> tag = TaggerRunner ( postagger ) <EOL> tag ( doc ) <EOL> self . assertTrue ( doc . was_preprocess_step_done ( PreProcessSteps . tagging ) ) <EOL> self . assertEqual ( doc . postags , sum ( expected_postags , [ ] ) ) <EOL> def test_tagger_runner_not_overriding_by_default ( self ) : <EOL> doc = SentencedIEDocFactory ( text = '<STR_LIT>' ) <EOL> postagger1 = lambda sents : [ [ ( x , '<STR_LIT:A>' ) for x in sent ] for sent in sents ] <EOL> postagger2 = lambda sents : [ [ ( x , '<STR_LIT:B>' ) for x in sent ] for sent in sents ] <EOL> tag = TaggerRunner ( postagger1 ) <EOL> tag ( doc ) <EOL> tag . postagger = postagger2 <EOL> tag ( doc ) <EOL> self . assertTrue ( all ( x == '<STR_LIT:A>' for x in doc . postags ) ) <EOL> def test_tagger_runner_overriding_when_selected ( self ) : <EOL> doc = SentencedIEDocFactory ( text = '<STR_LIT>' ) <EOL> postagger1 = lambda sents : [ [ ( x , '<STR_LIT:A>' ) for x in sent ] for sent in sents ] <EOL> postagger2 = lambda sents : [ [ ( x , '<STR_LIT:B>' ) for x in sent ] for sent in sents ] <EOL> tag = TaggerRunner ( postagger1 , override = True ) <EOL> tag ( doc ) <EOL> tag . postagger = postagger2 <EOL> tag ( doc ) <EOL> self . assertTrue ( all ( x == '<STR_LIT:B>' for x in doc . postags ) ) </s>
