Container
[ class tree: Container ] [ index: Container ] [ all elements ]

Source for file Sentence.php

Documentation is available at Sentence.php

  1. <?php
  2. /**
  3.  * Mai_Container_Sentence
  4.  * 
  5.  * Copyright (C) 2009  Mai (Me Artificial Intelligence)
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation, either version 3 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * This program 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
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19.  * 
  20.  * @author Wouter Bulten (wouterbulten@mai-ai.org)
  21.  * @copyright Copyright (C) 2009  Mai (Me Artificial Intelligence)
  22.  * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
  23.  * @link http://www.launchpad.net/mai
  24.  * 
  25.  * @category Mai
  26.  * @package Container
  27.  * @subpackage Sentence
  28.  * 
  29.  */
  30.  
  31. /** Load required file */
  32. {
  33.     require_once 'Mai/Container/Sentence/Interface.php';
  34. }
  35.  
  36. /**
  37.  * Mai_Container_Sentence is a container for a sentence.
  38.  * 
  39.  * @author Wouter Bulten (wouterbulten@mai-ai.org)
  40.  * @copyright Copyright (C) 2009  Mai (Me Artificial Intelligence)
  41.  * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
  42.  * @link http://www.launchpad.net/mai
  43.  * 
  44.  * @category Mai
  45.  * @package Container
  46.  * @subpackage Sentence
  47.  *
  48.  */
  49. class Mai_Container_Sentence implements Mai_Container_Sentence_Interface
  50. {
  51.     /**
  52.      * @var array Storage for words.
  53.      */
  54.     private $_words = array();
  55.     
  56.     /**
  57.      * @var String Sentence mark.
  58.      */
  59.     private $_sentenceMark;
  60.     
  61.     /**
  62.      * Insert a word in the storage.
  63.      * @param Mai_Container_Word The word to store.
  64.      * @param $location The location (key) where to store.
  65.      */
  66.     public function insertWord(Mai_Container_Word $word$location null)
  67.     {
  68.         if(!isset($location|| !is_numeric($location))
  69.         {
  70.             $this->_words[$word;
  71.         }
  72.         else
  73.         {
  74.             $this->_words[$location$word;
  75.         }
  76.     }
  77.     
  78.     /**
  79.      * Return a word from storage.
  80.      * @param Int $location The location (key) of storage.
  81.      * @param Bool $showError Set to false to return false if a word does not excist.
  82.      * @return Mai_Container_Word 
  83.      */
  84.     public function getWord($location$showError true)
  85.     {
  86.         if(!isset($location|| !is_numeric($location))
  87.         {
  88.             trigger_error('Location not set.'E_USER_ERROR);
  89.         }
  90.         
  91.         if(isset($this->_words[$location]&& $showError === true)
  92.         {
  93.             trigger_error('Word does not excist for location.'E_USER_NOTICE);
  94.         }
  95.         else
  96.         {
  97.             return false;
  98.         }
  99.         
  100.         return $this->_words[$location];
  101.     }
  102.     
  103.     /**
  104.      * Return all words (by reference)
  105.      * @return array 
  106.      */
  107.     public function &getAll()
  108.     {
  109.         return $this->_words;    
  110.     }
  111.     
  112.     /**
  113.      * Set the sentence mark of this sentence.
  114.      * @param String $sentenceMark 
  115.      */
  116.     public function setSentenceMark($sentenceMark)
  117.     {
  118.         if(!isset($location|| !is_numeric($location))
  119.         {
  120.             trigger_error('Sentence mark not set.'E_USER_ERROR);
  121.         }
  122.         
  123.         return $this->_sentenceMark;
  124.     }
  125.     
  126.     /**
  127.      * Return the sentence mark of this sentence.
  128.      * @return String 
  129.      */
  130.     public function getSentenceMark()
  131.     {
  132.         return $this->_sentenceMark;
  133.     }
  134. }

Documentation generated on Mon, 27 Jul 2009 19:55:12 +0200 by phpDocumentor 1.4.1