Version: current

      1 <?php
      2  /**
      3  * This file is part of phpMorphy library
      4  *
      5  * Copyright c 2007-2008 Kamaev Vladimir <heromantor@users.sourceforge.net>
      6  *
      7  * This library is free software; you can redistribute it and/or
      8  * modify it under the terms of the GNU Lesser General Public
      9  * License as published by the Free Software Foundation; either
     10  * version 2 of the License, or (at your option) any later version.
     11  *
     12  * This library is distributed in the hope that it will be useful,
     13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15  * Lesser General Public License for more details.
     16  *
     17  * You should have received a copy of the GNU Lesser General Public
     18  * License along with this library; if not, write to the
     19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
     20  * Boston, MA 02111-1307, USA.
     21  */
     22
     23 /**
     24  * This file is autogenerated at Wed, 14 Oct 2009 01:34:00 +0400, don`t change it!
     25  */
     26 class phpMorphy_Graminfo_Mem extends phpMorphy_Graminfo {
     27     function getGramInfoHeaderSize() {
     28         return 20;
     29     }
     30
     31     function readGramInfoHeader($offset) {
     32         $__mem = $this->resource;
     33
     34
     35         $result = unpack(
     36             'vid/vfreq/vforms_count/vpacked_forms_count/vancodes_count/vancodes_offset/vancodes_map_offset/vaffixes_offset/vaffixes_size/vbase_size',
     37             $GLOBALS['__phpmorphy_substr']($__mem, $offset, 20)
     38         );
     39
     40         $result['offset'] = $offset;
     41
     42         return $result;
     43     }
     44
     45     protected function readAncodesMap($info) {
     46         $__mem = $this->resource;
     47
     48         // TODO: this can be wrong due to aligning ancodes map section
     49         $offset = $info['offset'] + 20 + $info['forms_count'] * 2;
     50
     51
     52
     53         $forms_count = $info['packed_forms_count'];
     54         return unpack("v$forms_count",  $GLOBALS['__phpmorphy_substr']($__mem, $offset, $forms_count * 2));
     55     }
     56
     57     protected function splitAncodes($ancodes, $map) {
     58         $result = array();
     59         for($i = 1, $c = count($map), $j = 1; $i <= $c; $i++) {
     60             $res = array();
     61
     62             for($k = 0, $kc = $map[$i]; $k < $kc; $k++, $j++) {
     63                 $res[] = $ancodes[$j];
     64             }
     65
     66             $result[] = $res;
     67         }
     68
     69         return $result;
     70     }
     71
     72     function readAncodes($info) {
     73         $__mem = $this->resource;
     74
     75         // TODO: this can be wrong due to aligning ancodes section
     76         $offset = $info['offset'] + 20;
     77
     78
     79
     80         $forms_count = $info['forms_count'];
     81         $ancodes = unpack("v$forms_count", $GLOBALS['__phpmorphy_substr']($__mem, $offset, $forms_count * 2));
     82
     83         /*
     84         if(!$expand) {
     85             return $ancodes;
     86         }
     87         */
     88
     89         $map = $this->readAncodesMap($info);
     90
     91         return $this->splitAncodes($ancodes, $map);
     92     }
     93
     94     function readFlexiaData($info) {
     95         $__mem = $this->resource;
     96
     97         $offset = $info['offset'] + 20;
     98
     99         if(isset($info['affixes_offset'])) {
    100             $offset += $info['affixes_offset'];
    101         } else {
    102             $offset += $info['forms_count'] * 2 + $info['packed_forms_count'] * 2;
    103         }
    104
    105
    106         return explode($this->ends, $GLOBALS['__phpmorphy_substr']($__mem, $offset, $info['affixes_size'] - $this->ends_size));
    107     }
    108
    109     function readAllGramInfoOffsets() {
    110         return $this->readSectionIndex($this->header['flex_index_offset'], $this->header['flex_count']);
    111     }
    112
    113     protected function readSectionIndex($offset, $count) {
    114         $__mem = $this->resource;
    115
    116
    117
    118         return array_values(unpack("V$count", $GLOBALS['__phpmorphy_substr']($__mem, $offset, $count * 4)));
    119     }
    120
    121     function readAllFlexia() {
    122         $__mem = $this->resource;
    123
    124         $result = array();
    125
    126         $offset = $this->header['flex_offset'];
    127
    128         foreach($this->readSectionIndexAsSize($this->header['flex_index_offset'], $this->header['flex_count'], $this->header['flex_size']) as $size) {
    129             $header = $this->readGramInfoHeader($offset);
    130             $affixes = $this->readFlexiaData($header);
    131             $ancodes = $this->readAncodes($header, true);
    132
    133             $result[$header['id']] = array(
    134                 'header' => $header,
    135                 'affixes' => $affixes,
    136                 'ancodes' => $ancodes
    137             );
    138
    139             $offset += $size;
    140         }
    141
    142         return $result;
    143     }
    144
    145     function readAllPartOfSpeech() {
    146         $__mem = $this->resource;
    147
    148         $result = array();
    149
    150         $offset = $this->header['poses_offset'];
    151
    152         foreach($this->readSectionIndexAsSize($this->header['poses_index_offset'], $this->header['poses_count'], $this->header['poses_size']) as $size) {
    153
    154
    155             $res = unpack(
    156                 'vid/Cis_predict',
    157                 $GLOBALS['__phpmorphy_substr']($__mem, $offset, 3)
    158             );
    159
    160             $result[$res['id']] = array(
    161                 'is_predict' => (bool)$res['is_predict'],
    162                 'name' => $this->cleanupCString($GLOBALS['__phpmorphy_substr']($__mem, $offset + 3, $size - 3))
    163             );
    164
    165             $offset += $size;
    166         }
    167
    168         return $result;
    169     }
    170
    171     function readAllGrammems() {
    172         $__mem = $this->resource;
    173
    174         $result = array();
    175
    176         $offset = $this->header['grammems_offset'];
    177
    178         foreach($this->readSectionIndexAsSize($this->header['grammems_index_offset'], $this->header['grammems_count'], $this->header['grammems_size']) as $size) {
    179
    180
    181             $res = unpack(
    182                 'vid/Cshift',
    183                 $GLOBALS['__phpmorphy_substr']($__mem, $offset, 3)
    184             );
    185
    186             $result[$res['id']] = array(
    187                 'shift' => $res['shift'],
    188
    189                 'name' => $this->cleanupCString($GLOBALS['__phpmorphy_substr']($__mem, $offset + 3, $size - 3))
    190             );
    191
    192             $offset += $size;
    193         }
    194
    195         return $result;
    196     }
    197
    198     function readAllAncodes() {
    199         $__mem = $this->resource;
    200
    201         $result = array();
    202
    203         $offset = $this->header['ancodes_offset'];
    204
    205
    206         for($i = 0; $i < $this->header['ancodes_count']; $i++) {
    207             $res = unpack('vid/vpos_id', $GLOBALS['__phpmorphy_substr']($__mem, $offset, 4));
    208             $offset += 4;
    209
    210             list(, $grammems_count) = unpack('v', $GLOBALS['__phpmorphy_substr']($__mem, $offset, 2));
    211             $offset += 2;
    212
    213             $result[$res['id']] = array(
    214                 'pos_id' => $res['pos_id'],
    215                 'grammem_ids' => $grammems_count ?
    216                     array_values(unpack("v$grammems_count", $GLOBALS['__phpmorphy_substr']($__mem, $offset, $grammems_count * 2))) :
    217                     array(),
    218                 'offset' => $offset,
    219             );
    220
    221             $offset += $grammems_count * 2;
    222         }
    223
    224         return $result;
    225     }
    226 }
    227

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -