Пример #1
0
 /**
  * @param string $string
  * @return phpMorphy_UserDict_Pattern
  */
 static function constructFromString($string)
 {
     $string = trim($string);
     $sp_pos = strpos($string, ' ');
     $pattern = null;
     $word = $string;
     if (false !== $sp_pos) {
         $pattern_string = trim(substr($string, $sp_pos + 1));
         if (strlen($pattern_string)) {
             $pattern = phpMorphy_UserDict_GrammarIdentifier::constructFromString($pattern_string);
             $word = substr($string, 0, $sp_pos);
         }
     }
     if (null === $pattern) {
         $pattern = phpMorphy_UserDict_GrammarIdentifier::construct(null, array());
     }
     $clazz = __CLASS__;
     return new $clazz($word, $pattern);
 }
Пример #2
0
 /**
  * @param DOMNode $node
  */
 private function onDeleteCommand(DOMNode $node)
 {
     $pattern = new phpMorphy_UserDict_Pattern($this->normalizeEncoding($this->getAttribute($node, 'lexem')), phpMorphy_UserDict_GrammarIdentifier::constructFromPosAndGrammems($this->normalizeEncoding($this->getAttribute($node, 'lexem-pos', false, null)), $this->normalizeEncoding($this->getAttribute($node, 'lexem-grammems', false, ''))));
     $from = strtolower($this->getAttribute($node, 'from', false, 'both'));
     $delete_from_internal = $from === 'internal' || $from === 'both';
     $delete_from_external = $from === 'external' || $from === 'both';
     $this->visitor->deleteLexem($pattern, $delete_from_internal, $delete_from_external);
 }
 /**
  * @todo Implement testMatch().
  */
 public function testMatch()
 {
     $obj = $this->object;
     $obj2 = new phpMorphy_UserDict_GrammarIdentifier(null, array('a', 'b', 'c'));
     $this->assertTrue($obj->match('PART_OF_SPEECH', array('c', 'b', 'a')));
     $this->assertFalse($obj->match('PART_OF_SPEECH_BOO', array('c', 'b', 'a')));
     $this->assertTrue($obj->match('PART_OF_SPEECH', array('d', 'c', 'b', 'a')));
     $this->assertFalse($obj->match('PART_OF_SPEECH', array('a', 'b')));
     $this->assertFalse($obj->match('PART_OF_SPEECH', array('a', 'b', 'd')));
     $this->assertTrue($obj2->match('ANY_STRING', array('c', 'b', 'a')));
     $this->assertFalse($obj2->match('ANY_STRING_ANY', array('c', 'b')));
     $obj3 = new phpMorphy_UserDict_GrammarIdentifier(null, array());
     $this->assertTrue($obj3->match('ANY_STRING', array('any_array', 'a', '1', 'd', 'z', 'x')));
     $this->assertTrue($obj3->match('ANY_STRING', array()));
     $this->assertTrue($obj3->match(null, array()));
 }