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 class phpMorphy_Link_Base {
     24     protected
     25         $fsa,
     26         $trans,
     27         $raw_trans;
     28
     29     function phpMorphy_Link_Base(phpMorphy_Fsa_Interface $fsa, $trans, $rawTrans) {
     30         $this->fsa = $fsa;
     31         $this->trans = $trans;
     32         $this->raw_trans = $rawTrans;
     33     }
     34
     35     function isAnnotation() { }
     36     function getTrans() { return $this->trans; }
     37     function getFsa() { return $this->fsa; }
     38     function getRawTrans() { return $this->raw_trans; }
     39 };
     40
     41 /**
     42  * This class represent "normal" link i.e. link that points to automat state
     43  */
     44 class phpMorphy_Link extends phpMorphy_Link_Base {
     45     function isAnnotation() { return false; }
     46
     47     function getDest() { return $this->trans['dest']; }
     48     function getAttr() { return $this->trans['attr']; }
     49
     50     function getTargetState() {
     51         return $this->createState($this->trans['dest']);
     52     }
     53
     54     protected function createState($index) {
     55         return new phpMorphy_State($this->fsa, $index);
     56     }
     57 }
     58
     59 class phpMorphy_Link_Annot extends phpMorphy_Link_Base {
     60     function isAnnotation() { return true; }
     61
     62     function getAnnotation() {
     63         return $this->fsa->getAnnot($this->raw_trans);
     64     }
     65 };
     66
     67 class phpMorphy_State {
     68     protected
     69         $fsa,
     70         $transes,
     71         $raw_transes;
     72
     73     function phpMorphy_State(phpMorphy_Fsa_Interface $fsa, $index) {
     74         $this->fsa = $fsa;
     75
     76         $this->raw_transes = $fsa->readState($index);
     77         $this->transes = $fsa->unpackTranses($this->raw_transes);
     78     }
     79
     80     function getLinks() {
     81         $result = array();
     82
     83         for($i = 0, $c = count($this->transes); $i < $c; $i++) {
     84             $trans = $this->transes[$i];
     85
     86             if(!$trans['term']) {
     87                 $result[] = $this->createNormalLink($trans, $this->raw_transes[$i]);
     88             } else {
     89                 $result[] = $this->createAnnotLink($trans, $this->raw_transes[$i]);
     90             }
     91         }
     92
     93         return $result;
     94     }
     95
     96     function getSize() { return count($this->transes); }
     97
     98     protected function createNormalLink($trans, $raw) {
     99         return new phpMorphy_Link($this->fsa, $trans, $raw);
    100     }
    101
    102     protected function createAnnotLink($trans, $raw) {
    103         return new phpMorphy_Link_Annot($this->fsa, $trans, $raw);
    104     }
    105 };
    106

[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. -