Container
[
class tree: Container
] [
index: Container
] [
all elements
]
Packages:
Analyzer
Base
Cache
Config
Container
Creator
Log
Memory
Pattern
Registry
Stat
Word
Source for file Input.php
Documentation is available at
Input.php
<?php
/**
* Mai_Container_Input
*
* Copyright (C) 2009 Mai (Me Artificial Intelligence)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
@author
Wouter Bulten (wouterbulten@mai-ai.org)
*
@copyright
Copyright (C) 2009 Mai (Me Artificial Intelligence)
*
@license
http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
*
@link
http://www.launchpad.net/mai
*
*
@category
Mai
*
@package
Container
*
@subpackage
Input
*
*/
/** Load required file */
if
(
!
Mai
::
getAutoloader
(
))
{
require_once
'Mai/Container/Input/Interface.php'
;
}
/**
* Mai_Container_Input is a container for input.
* Input types currently supported:
* - Sentences
*
*
@author
Wouter Bulten (wouterbulten@mai-ai.org)
*
@copyright
Copyright (C) 2009 Mai (Me Artificial Intelligence)
*
@license
http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
*
@link
http://www.launchpad.net/mai
*
*
@category
Mai
*
@package
Container
*
@subpackage
Input
*
*/
class
Mai_Container_Input
implements
Mai_Container_Input_Interface
{
/**
*
@var
int
Type of input.
*/
private
$_inputType
=
0
;
/**
*
@var
array
Storage for sentences.
*/
private
$_sentences
=
array
(
)
;
/**
* Set the input type of this container.
*
@param
int
$type
*/
public
function
setType
(
$type
)
{
//Only normal input (sentences) is currently supported
if
(
$type
!==
Mai
::
MSG_TYPE_NORMAL
)
{
trigger_error
(
'Type is not valid or not supported.'
,
E_USER_WARNING
)
;
}
$this
->
_inputType
=
$type
;
}
/**
* Get the type of this container.
*
@return
int
*/
public
function
getType
(
)
{
return
$this
->
_inputType
;
}
/**
* Insert a word in the storage.
*
@param
Mai_Container_Sentence
The sentence to store.
*
@param
$location
The location (key) where to store.
*/
public
function
insertSentence
(
Mai_Container_Sentence
$sentence
,
$location
=
null
)
{
if
(
!
isset
(
$location
)
||
!
is_numeric
(
$location
))
{
$this
->
_sentences
[
]
=
$sentence
;
}
else
{
$this
->
_sentences
[
$location
]
=
$sentence
;
}
}
/**
* Return a sentence from storage.
*
@param
Int
$location
The location (key) of storage.
*
@param
Bool
$showError
Set to false to return false if a sentence does not excist.
*
@return
Mai_Container_Sentence
*/
public
function
getSentence
(
$location
,
$showError
=
true
)
{
if
(
!
isset
(
$location
)
||
!
is_numeric
(
$location
))
{
trigger_error
(
'Location not set.'
,
E_USER_ERROR
)
;
}
if
(
isset
(
$this
->
_sentences
[
$location
]
)
&&
$showError
===
true
)
{
trigger_error
(
'Sentences does not excist for location.'
,
E_USER_NOTICE
)
;
}
else
{
return
false
;
}
return
$this
->
_sentences
[
$location
]
;
}
/**
* Return all sentences
*
@return
array
*/
public
function
getAll
(
)
{
return
$this
->
_sentences
;
}
/**
* Function to implement the IteratorAggregate interface.
*
@return
ArrayIterator
*/
public
function
getIterator
(
)
{
return
new
ArrayIterator
(
$this
->
_sentences
)
;
}
}
Documentation generated on Mon, 27 Jul 2009 19:55:06 +0200 by
phpDocumentor 1.4.1