Creator
[
class tree: Creator
] [
index: Creator
] [
all elements
]
Packages:
Analyzer
Base
Cache
Config
Container
Creator
Log
Memory
Pattern
Registry
Stat
Word
Source for file Pattern.php
Documentation is available at
Pattern.php
<?php
/**
* Mai_Creator_Pattern
*
* 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
Creator
*
@subpackage
Pattern
*/
/**
* Mai_Creator_Pattern is a creator class for patterns.
*
*
@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
Creator
*
@subpackage
Pattern
*
*/
class
Mai_Creator_Pattern
implements
Mai_Creator_Interface
{
/**
*
@var
array
Contains an array with words.
*/
protected
$_wordArray
=
array
(
)
;
/**
*
@var
Mai_Pattern
Contains the pattern.
*/
protected
$_pattern
;
/**
* Constructor checks if Mai has been set up.
*/
public
function
__construct
(
$creator
)
{
if
(
!
Mai
::
isInit
(
))
{
trigger_error
(
'Mai has not been setup yet. Please use Mai::init().'
,
E_USER_ERROR
)
;
}
//This class should only be created by Mai_Creator
if
(
!
(
$creator
instanceof
Mai_Creator
)
&&
Mai_Config
::
getVar
(
)
->
cache
->
allow_direct_access
!=
1
)
{
trigger_error
(
'Please use Mai_Creator to create an instance of Mai_Creator_Pattern.'
,
E_USER_NOTICE
)
;
}
}
public
function
setWordArray
(
array
$wordArray
)
{
$this
->
_wordArray
=
$wordArray
;
}
/**
/**
* Runs the splitting process.
*
@return
void
*/
public
function
run
(
)
{
if
(
empty
(
$this
->
_wordArray
))
{
throw
new
InvalidArgumentException
(
'Word array not set.'
)
;
}
$pattern
=
''
;
//Pattern will be stored in this variable
$patternArray
=
array
(
)
;
//An array of the pattern will be stored inside this variable.
//Create pattern
foreach
(
$this
->
_wordArray
as
$key
=>
$value
)
{
if
(
$key
!==
'sentence-mark'
)
{
$patternArray
[
]
=
$value
;
//$value is 0 if the word is unknown.
if
(
$value
===
0
)
{
$pattern
.=
'-0'
;
}
else
{
//Add the word type to the pattern
$pattern
.=
'-'
. (string)
$value
[
'wordtype'
]
;
}
}
}
//Remove first - from the pattern
$pattern
=
substr
(
$pattern
,
1
)
;
//Create new pattern
$this
->
_pattern
=
new
Mai_Pattern
(
$this
->
_wordArray
,
$pattern
,
$patternArray
)
;
}
/**
* Return the created pattern.
*
@return
Mai_Pattern
*/
public
function
returnPattern
(
)
{
return
$this
->
_pattern
;
}
}
Documentation generated on Mon, 27 Jul 2009 19:55:11 +0200 by
phpDocumentor 1.4.1