Source for file Mai.php
Documentation is available at Mai.php
* 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
* Mai is an overall class for Mai.
* @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
const MSG_TYPE_NORMAL = 1;
const MSG_TYPE_COMMAND = 2;
const MSG_TYPE_LOGOUT = 3;
const ENV_PRODUCTION = 1;
const ENV_DEVELOPMENT = 2;
* @link http://nl.wikipedia.org/wiki/Woordsoort
* Note: if you change these values synchronising with Mai-Ai.org will give
* incorrect data. Also your database will be out of sync.
const WT_BIJVOEGELIJK_NAAMWOORD = 1;
const WT_HOOFDTELWOORD = 3;
const WT_RANGTELWOORD = 4;
const WT_VRAGEND_VOORNAAMWOORD = 6;
const WT_PERSOONLIJK_VOORNAAMWOORD = 7;
const WT_PERSOONLIJK_VOORNAAMWOORD_VOORWERP = 8;
const WT_AANWIJZEND_VOORNAAMWOORD = 9;
const WT_BEZITTELIJK_VOORNAAMWOORD = 10;
const WT_VOORZETSEL = 11;
const WT_ZELFSTANDIG_NAAMWOORD = 13;
const WT_BEGROETING = 15;
const WT_PLAATSNAAM = 17;
const WVT_TEGENWOORDIGE_TIJD = 1;
const WVT_VERLEDEN_TIJD = 2;
* Word numbers (one or multiple)
* Persons (ik, jij, etc.)
const WP_1_ENKELVOUD = 1; //Ik
const WP_1_MEERVOUD = 2; //Wij
const WP_2_ENKELVOUD = 3; //Jij, u
const WP_2_MEERVOUD = 4; //Jullie, u
const WP_3_ENKELVOUD = 5; //Hij, zij, het
const WP_3_MEERVOUD = 6; //Zij
* Analyzer response types
const AN_RESPONSE_FULL_PATTERN = 1;
const STORAGE_TYPE_ARRAY = 1;
const STORAGE_TYPE_CLASS = 2;
* @var Mai Singleton instance
protected static $_instance;
* @var integer The enviroment of Mai.
protected static $_env = self::ENV_PRODUCTION;
* @var boolean Define TRUE when using an autoloader. This disables the require_once statements.
protected static $_autoloader = false;
* @var string Directory of the Mai class.
protected static $_baseDir;
* @var array Allowed text types.
public static $allowedTextTypes = array(self::MSG_TYPE_NORMAL, self::MSG_TYPE_COMMAND, self::MSG_TYPE_LOGOUT);
* @var array The names of the environments
public static $_envNames = array(
Mai::ENV_DEVELOPMENT => 'development',
Mai::ENV_PRODUCTION => 'production',
Mai::ENV_STAGING => 'staging'
* @var array Allowed environments.
protected static $_envAllowed = array(self::ENV_DEVELOPMENT, self::ENV_PRODUCTION, self::ENV_STAGING);
* @var array Allowed word types.
public static $allowedWordTypes = array(
self::WT_AANWIJZEND_VOORNAAMWOORD, self::WT_AFSCHEID, self::WT_BEGROETING,
self::WT_BEZITTELIJK_VOORNAAMWOORD, self::WT_BIJVOEGELIJK_NAAMWOORD, self::WT_HOOFDTELWOORD,
self::WT_LIDWOORD, self::WT_NAAM, self::WT_PERSOONLIJK_VOORNAAMWOORD,
self::WT_PERSOONLIJK_VOORNAAMWOORD_VOORWERP, self::WT_PLAATSNAAM, self::WT_RANGTELWOORD,
self::WT_VOEGWOORD, self::WT_VOORZETSEL, self::WT_VRAGEND_VOORNAAMWOORD,
self::WT_WERKWOORD, self::WT_ZELFSTANDIG_NAAMWOORD
* @var array Allowed times.
public static $allowedTimes = array(
self::WVT_TEGENWOORDIGE_TIJD,
* @var array Allowed numbers (for words).
public static $allowedNumbers = array(
* @var array Allowed persons (for words).
public static $allowedPersons = array(
* @var Boolean Whether Mai has been setup.
protected static $_init = false;
* Private constructor to prevent creation of this object.
* Retrieve singleton instance
if (null === self::$_instance) {
self::$_instance = new self();
//Define the location of this class
self::$_baseDir = realpath(dirname(__FILE__ ));
public static function init()
//Load required file for config
if(!self::getAutoloader()){ require_once 'Mai/Config.php'; }
//Let the Mai_Config class know that Mai is using it
//Define whether the scripts uses an autoloader or not
self::$_autoloader = Mai_Config::getVar()->application->autoloader;
//Load required field for Registry
if(!self::getAutoloader()){ require_once 'Mai/Registry.php'; }
//Load required field for stat
if(!self::getAutoloader()){ require_once 'Mai/Stat.php'; }
//Start the Mai_Stat class
Mai_Log::info("Mai: Mai started.");
public static function end()
* Returns the value of $_init.
public static function isInit()
* Set the environment type.
public static function setEnv($env)
trigger_error("Can't set enviroment, Mai has already been started.", E_USER_ERROR);
throw new UnexpectedValueException('Environment must be set.');
throw new UnexpectedValueException('Environment is not valid.');
* Return the environment type.
public static function getEnv()
* Set whether classes are loaded using a autoloader or not.
throw new UnexpectedValueException('Value can only be a boolean.');
self::$_autoloader = $value;
* Return the value of $_autoloader.
return self::$_autoloader;
* Return the location of the Mai class.
* Cloning of a singleton class is not allowed.
trigger_error('Clone is not allowed.', E_USER_ERROR);
|