function __construct(phpMorphy_Storage_StorageInterface $ancodesMap)
 {
     if (false === ($this->ancodes_map = unserialize($ancodesMap->read(0, $ancodesMap->getFileSize())))) {
         throw new phpMorphy_Exception("Can`t open phpMorphy => Dialing ancodes map");
     }
     $this->reverse_map = array_flip($this->ancodes_map);
 }
Пример #2
0
 /**
  * @throws phpMorphy_Exception
  * @param phpMorphy_Storage_StorageInterface $storage
  *
  */
 protected function __construct(phpMorphy_Storage_StorageInterface $storage)
 {
     $this->data = unserialize($storage->read(0, $storage->getFileSize()));
     if (false === $this->data) {
         throw new phpMorphy_Exception("Broken gramtab data");
     }
     $this->grammems = $this->data['grammems'];
     $this->poses = $this->data['poses'];
     $this->ancodes = $this->data['ancodes'];
 }
Пример #3
0
 /**
  * @static
  * @throws phpMorphy_Exception
  * @param phpMorphy_Storage_StorageInterface $storage
  * @param bool $isLazy
  * @return phpMorphy_GramInfo_GramInfoInterface
  */
 static function create(phpMorphy_Storage_StorageInterface $storage, $isLazy)
 {
     if ($isLazy) {
         return new phpMorphy_GramInfo_Proxy($storage);
     }
     $header = phpMorphy_GramInfo_GramInfoAbstract::readHeader($storage->read(0, self::HEADER_SIZE));
     if (!phpMorphy_GramInfo_GramInfoAbstract::validateHeader($header)) {
         throw new phpMorphy_Exception('Invalid graminfo format');
     }
     $storage_type = $storage->getTypeAsString();
     $clazz = 'phpMorphy_GramInfo_' . ucfirst($storage_type);
     return new $clazz($storage->getResource(), $header);
 }
Пример #4
0
 /**
  * @static
  * @throws phpMorphy_Exception
  * @param phpMorphy_Storage_StorageInterface $storage
  * @param bool $isLazy
  * @return phpMorphy_Fsa_FsaInterface
  */
 static function create(phpMorphy_Storage_StorageInterface $storage, $isLazy)
 {
     if ($isLazy) {
         return new phpMorphy_Fsa_Proxy($storage);
     }
     $header = phpMorphy_Fsa_FsaAbstract::readHeader($storage->read(0, self::HEADER_SIZE, true));
     if (!phpMorphy_Fsa_FsaAbstract::validateHeader($header)) {
         throw new phpMorphy_Exception('Invalid fsa format');
     }
     if ($header['flags']['is_sparse']) {
         $type = 'sparse';
     } else {
         if ($header['flags']['is_tree']) {
             $type = 'tree';
         } else {
             throw new phpMorphy_Exception('Only sparse or tree fsa`s supported');
         }
     }
     $storage_type = $storage->getTypeAsString();
     $file_path = __DIR__ . "/access/fsa_{$type}_{$storage_type}.php";
     $clazz = 'phpMorphy_Fsa_' . ucfirst($type) . '_' . ucfirst($storage_type);
     return new $clazz($storage->getResource(), $header);
 }
Пример #5
0
 /**
  * Reads $len bytes from $offset offset
  *
  * @throws phpMorphy_Exception
  * @param int $offset Read from this offset
  * @param int $length How many bytes to read
  * @param bool $exactLength If this set to true, then exception thrown when we read less than $len bytes
  * @return string
  */
 public function read($offset, $length, $exactLength = true)
 {
     $result = $this->object->read($offset, $length, $exactLength);
     return $result === $this->object ? $this : $result;
 }