Example #1
0
 /**
  * @param ParseTextRequest $request
  * @return ParseTextResponse
  */
 public function execute(ParseTextRequest $request)
 {
     $gateway = Context::$dictionaryGateway;
     $dictionary = $gateway->findDictionaryByName($request->dictionaryName);
     $parser = new Parser(new CzechConfig());
     $parser->setDictionary($dictionary);
     $parser->parse($request->text);
     $dictionary = $parser->getDictionary();
     $gateway->save($dictionary);
     $response = new ParseTextResponse();
     $response->dictionaryName = $dictionary->getName();
     return $response;
 }
Example #2
0
 /**
  * @test
  */
 public function givenTextParsesItInDictionary()
 {
     $text = " Á\tbb čurák ,\n č'č?    Ďď—ď -   KURVA ěéĚÉě! FfFf'f 1234.67. ";
     $expect = "" . "addWord: á\n" . "addWord: bb\n" . "addWord: č'č\n" . "addWord: ďď—ď\n" . "addWord: ěéěéě\n" . "addWord: ffff'f\n" . "addWord: 1234.67\n" . "addSentence: <1> <2>, <3>?\n" . "addSentence: <4> - <5>!\n" . "addSentence: <6> <7>.";
     $this->p->setDictionary(new WritableDictionarySpy());
     $this->p->parse($text);
     /** @var WritableDictionarySpy $dSpy */
     $dSpy = $this->p->getDictionary();
     $this->assertEquals($expect, $dSpy->getLog());
 }