- improvements to L10N implementations
- improvements of namespaces for idioms and cortex classes - Improvements on main classes - Fixed bug of idioms (when you change the idiom, it wasn't changing the Inflect class)
Esse commit está contido em:
@@ -8,6 +8,7 @@
|
||||
<input type='button' value='show projects' onclick="showProjects()"/>
|
||||
<input type='button' value='show users' onclick="showUsers()"/>
|
||||
<input type='button' value='analyze project x' onclick="analyze()"/>
|
||||
<input type='button' value='analyze project y' onclick="analyzeY()"/>
|
||||
<input type='button' value='logoff' onclick="logoff()"/>
|
||||
</body>
|
||||
<script>
|
||||
@@ -110,7 +111,34 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function analyzeY()
|
||||
{
|
||||
|
||||
$.ajax({
|
||||
type:'POST',
|
||||
url:'http://localhost/mind/',
|
||||
data:{
|
||||
program:'use',
|
||||
what:'project',
|
||||
name:'y'
|
||||
},
|
||||
success: function(ret){
|
||||
document.getElementById('result').innerHTML= "<br/>"+ret
|
||||
$.ajax({
|
||||
type:'POST',
|
||||
url:'http://localhost/mind/',
|
||||
data:{
|
||||
program:'analyze'
|
||||
},
|
||||
success: function(ret){
|
||||
document.getElementById('result').innerHTML+= "<br/>"+ret
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function logoff()
|
||||
{
|
||||
$.ajax({
|
||||
|
||||
@@ -48,5 +48,4 @@ class En {
|
||||
You *must* send some POST data acoording your request, and also a variable "program" by post, with the name of the program you want to run.
|
||||
MESSAGE;
|
||||
}
|
||||
}
|
||||
?>
|
||||
}
|
||||
@@ -4,10 +4,10 @@
|
||||
*
|
||||
* @author felipe
|
||||
*/
|
||||
class ptBR {
|
||||
class pt {
|
||||
private $messages= Array();
|
||||
|
||||
public $name= 'pt-BR';
|
||||
public $name= 'pt';
|
||||
|
||||
/**
|
||||
* This method returns the translated message
|
||||
@@ -55,5 +55,4 @@ class ptBR {
|
||||
You *must* send some POST data acoording your request, and also a variable "program" by post, with the name of the program you want to run.
|
||||
MESSAGE;
|
||||
}
|
||||
}
|
||||
?>
|
||||
}
|
||||
+88
-214
@@ -12,7 +12,9 @@
|
||||
public $about= null;
|
||||
public $defaults= null;
|
||||
public $conf= null;
|
||||
|
||||
public static $currentProject= null;
|
||||
public static $ref= Array();
|
||||
public static $projectsDir= '';
|
||||
public static $pluginList= Array();
|
||||
public static $l10n= null;
|
||||
@@ -32,7 +34,7 @@
|
||||
*/
|
||||
public static function isInstalled()
|
||||
{
|
||||
return file_exists('mind3rd/SQLite/mind');
|
||||
return file_exists(_MINDSRC_.'/mind3rd/SQLite/mind');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,6 +42,7 @@
|
||||
* You can pass a rich string with %s, %i, etc, sending extra parameters
|
||||
* If the boolean flag $echo is sent, it prints it to the output, otherwise,
|
||||
* only returns it
|
||||
* This is an alias for MindSpeaker::write
|
||||
*
|
||||
* @param String $k
|
||||
* @param Bolean $echo
|
||||
@@ -48,38 +51,14 @@
|
||||
*/
|
||||
public static function write($k, $echo=true)
|
||||
{
|
||||
$msg= Mind::$l10n->getMessage($k);
|
||||
if(!$msg)
|
||||
{
|
||||
$msg= Mind::message("L10N: Message $k does not exist", '[Fail]', false);
|
||||
}
|
||||
$args= func_get_args();
|
||||
$parms= "";
|
||||
if(sizeof($args)>2)
|
||||
{
|
||||
for($i=2; $i<sizeof($args); $i++)
|
||||
{
|
||||
$parms.= ', "'.$args[$i].'"';
|
||||
}
|
||||
$parms= '"'.$msg.'"'.$parms;
|
||||
eval("\$print= sprintf(".$parms.");");
|
||||
}else{
|
||||
$print= $msg;
|
||||
}
|
||||
$count= 1;
|
||||
while(strlen($print) >= _CONSOLE_LINE_LENGTH_ && strpos($print, '..')>-1)
|
||||
{
|
||||
$print= preg_replace("/\.\./", '.', $print, $count);
|
||||
}
|
||||
if($echo)
|
||||
echo $print;
|
||||
return $msg;
|
||||
return MindSpeaker::write($k, $echo, func_get_args());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns or prints a message formated to represent failures, passes
|
||||
* or any kind of alert
|
||||
*
|
||||
* This is an alias for MindSpeaker::message
|
||||
*
|
||||
* @param String $message The message itself
|
||||
* @param String $status The status to be shown in the end of the message
|
||||
* @param Boolean $echo if it should be printed or not
|
||||
@@ -87,12 +66,87 @@
|
||||
*/
|
||||
public static function message($message, $status, $echo=true)
|
||||
{
|
||||
$msg= str_pad($message, _CONSOLE_LINE_LENGTH_ - strlen($status), '.').$status."\n";
|
||||
if($echo)
|
||||
echo $msg;
|
||||
return $msg;
|
||||
return MindSpeaker::message($message, $status, $echo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for MindCommand::readPassword
|
||||
* @param String $stars
|
||||
* @return String $password
|
||||
*/
|
||||
public static function readPassword($stars)
|
||||
{
|
||||
return MindCommand::readPassword($stars);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will copy the whole directory, recursively
|
||||
* but it is focused to the "generate project" tool
|
||||
* This is an alias for MindDir::copyDir
|
||||
*
|
||||
* @author Felipe Nascimento
|
||||
* @name copyDir
|
||||
* @param String $source
|
||||
* @param String $dest
|
||||
* @param [String $flag]
|
||||
* @return boolean
|
||||
*/
|
||||
static function copyDir($source, $dest, $flag= false)
|
||||
{
|
||||
return MindDir::copyDir($source, $dest, $flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes recusrively a directory
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
* @method deleteDir
|
||||
* @param String $dir
|
||||
* @return boolean
|
||||
*/
|
||||
static function deleteDir($dir)
|
||||
{
|
||||
return MindDir::deleteDir($dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a MindPlugin based object to the
|
||||
* plugins and triggers list
|
||||
* Alias for MindPlugin::addPlugin
|
||||
*
|
||||
* @param MindPlugin $plugin
|
||||
*/
|
||||
static function addPlugin(&$plugin)
|
||||
{
|
||||
MindPlugin::addPlugin($plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the project already exists,
|
||||
* false, otherwise
|
||||
* Alias for MindProject::hasProject
|
||||
*
|
||||
* @global Mind $_MIND
|
||||
* @param String $project
|
||||
* @return boolean
|
||||
*/
|
||||
static function hasProject($project)
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
return MindProject::hasProject($project);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads data from the passed project
|
||||
* Alias for MindProject::openProject
|
||||
*
|
||||
* @param AssocArray $p
|
||||
* @return boolean
|
||||
*/
|
||||
public static function openProject($p)
|
||||
{
|
||||
return MindProject::openProject($p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@@ -108,188 +162,8 @@
|
||||
Mind::$l10n= new $this->defaults['default_human_language']();
|
||||
Mind::$langPath= $path.'/mind3rd/API/languages/';
|
||||
Mind::$curLang= $this->defaults['default_human_language'];
|
||||
$langPath= $path.'/mind3rd/API/languages/'.$this->defaults['default_human_languageName'].'/';
|
||||
|
||||
$langPath= $path.'/mind3rd/API/languages/';//.$this->defaults['default_human_languageName'].'/';
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . $langPath);
|
||||
}
|
||||
/**
|
||||
* function taken from: http://www.dasprids.de/blog/2008/08/22/getting-a-password-hidden-from-stdin-with-php-cli
|
||||
* this method should read the passwords from console, not showing any character
|
||||
* or replacing them by stars(asterisks)
|
||||
* @method readPassword
|
||||
* @param Boolan $stars if true, show an * for each typed char
|
||||
* @return String password
|
||||
*/
|
||||
public static function readPassword($stars)
|
||||
{
|
||||
// Get current style
|
||||
$oldStyle = shell_exec('stty -g');
|
||||
|
||||
if ($stars === false) {
|
||||
shell_exec('stty -echo');
|
||||
$password = rtrim(fgets(STDIN), "\n");
|
||||
} else {
|
||||
shell_exec('stty -icanon -echo min 1 time 0');
|
||||
|
||||
$password = '';
|
||||
while (true) {
|
||||
$char = fgetc(STDIN);
|
||||
|
||||
if ($char === "\n") {
|
||||
break;
|
||||
} else if (ord($char) === 127) {
|
||||
if (strlen($password) > 0) {
|
||||
fwrite(STDOUT, "\x08 \x08");
|
||||
$password = substr($password, 0, -1);
|
||||
}
|
||||
} else {
|
||||
fwrite(STDOUT, "*");
|
||||
$password .= $char;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reset old style
|
||||
shell_exec('stty ' . $oldStyle);
|
||||
|
||||
// Return the password
|
||||
return $password;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will copy the whole directory, recursively
|
||||
* but it is focused to the "generate project" tool
|
||||
* @author Felipe Nascimento
|
||||
* @name copyDir
|
||||
* @param String $source
|
||||
* @param String $dest
|
||||
* @param [String $flag]
|
||||
* @return boolean
|
||||
*/
|
||||
static function copyDir($source, $dest, $flag= false)
|
||||
{
|
||||
// Simple copy for a file
|
||||
if($flag)
|
||||
{
|
||||
$s= '...'.substr($source, -30);
|
||||
showLoadStatus("Copying ".$s, $_SESSION['currentPerc']);
|
||||
}
|
||||
if (is_file($source))
|
||||
{
|
||||
$c = copy($source, $dest);
|
||||
chmod($dest, 0777);
|
||||
return $c;
|
||||
}
|
||||
// Make destination directory
|
||||
if(!is_dir($dest))
|
||||
{
|
||||
$oldumask = umask(0);
|
||||
mkdir($dest, 0777);
|
||||
umask($oldumask);
|
||||
}
|
||||
// Loop through the folder
|
||||
$dir = dir($source);
|
||||
while(false !== $entry = $dir->read())
|
||||
{
|
||||
// Skip pointers
|
||||
if ( in_array($entry, array(".","..",".svn") ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// Deep copy directories
|
||||
if ($dest !== "$source/$entry")
|
||||
{
|
||||
Mind::copyDir("$source/$entry", "$dest/$entry", $flag);
|
||||
}
|
||||
}
|
||||
// Clean up
|
||||
$dir->close();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes recusrively a directory
|
||||
* @author thiago <erkethan@free.fr>
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
* @method deleteDir
|
||||
* @param String $dir
|
||||
* @return boolean
|
||||
*/
|
||||
static function deleteDir($dir)
|
||||
{
|
||||
if(!file_exists($dir))
|
||||
return true;
|
||||
if(!is_dir($dir) || is_link($dir))
|
||||
return unlink($dir);
|
||||
foreach(scandir($dir) as $item)
|
||||
{
|
||||
if ($item == '.' || $item == '..')
|
||||
continue;
|
||||
if(!$this->deleteDir($dir . "/" . $item))
|
||||
{
|
||||
chmod($dir . "/" . $item, 0777);
|
||||
if(!$this->deleteDir($dir . "/" . $item))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return rmdir($dir);
|
||||
}
|
||||
|
||||
static function addPlugin(&$plugin)
|
||||
{
|
||||
if(in_array($plugin->trigger, Mind::$triggers))
|
||||
{
|
||||
if(!isset(Mind::$pluginList[$plugin->trigger]))
|
||||
Mind::$pluginList[$plugin->trigger]= Array( 'before'=>Array(),
|
||||
'after'=>Array());
|
||||
Mind::$pluginList[$plugin->trigger][$plugin->event][]= $plugin;
|
||||
}
|
||||
}
|
||||
|
||||
static function hasProject($project)
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
$projectfile= Mind::$projectsDir.$project;
|
||||
$noAccess= true;
|
||||
|
||||
$db= new MindDB();
|
||||
$hasProject= "SELECT pk_project,
|
||||
project.name as name
|
||||
from project_user,
|
||||
project
|
||||
where fk_user= ".$_SESSION['pk_user']."
|
||||
and project.name = '".$project."'
|
||||
and fk_project = pk_project
|
||||
";
|
||||
$data= $db->query($hasProject);
|
||||
if(sizeof($data)>0)
|
||||
foreach($data as $row)
|
||||
{
|
||||
$noAccess= false;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!file_exists($projectfile) || $noAccess)
|
||||
{
|
||||
Mind::write('noProject', true, $project);
|
||||
return false;
|
||||
}
|
||||
return $row;
|
||||
}
|
||||
|
||||
public static function openProject($p)
|
||||
{
|
||||
$_SESSION['currentProject']= $p['pk_project'];
|
||||
$_SESSION['currentProjectName']= $p['name'];
|
||||
$_SESSION['currentProjectDir']= Mind::$projectsDir.$p['name'];
|
||||
$p['path']= Mind::$projectsDir.$p['name'];
|
||||
$p['sources']= Mind::$projectsDir.$p['name'].'/sources';
|
||||
Mind::$currentProject= $p;
|
||||
if(isset($_SESSION['currentProject']))
|
||||
{
|
||||
if($_SESSION['currentProject'] == $p['pk_project'])
|
||||
return true;
|
||||
}
|
||||
Mind::write('projectOpened', true, $p['name']);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -122,5 +122,48 @@ class MindCommand extends Symfony\Component\Console\Command\Command
|
||||
return $this->verifyCredentials();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
/**
|
||||
* function taken from: http://www.dasprids.de/blog/2008/08/22/getting-a-password-hidden-from-stdin-with-php-cli
|
||||
* this method should read the passwords from console, not showing any character
|
||||
* or replacing them by stars(asterisks)
|
||||
* @method readPassword
|
||||
* @param Boolan $stars if true, show an * for each typed char
|
||||
* @return String password
|
||||
*/
|
||||
public static function readPassword($stars)
|
||||
{
|
||||
// Get current style
|
||||
$oldStyle = shell_exec('stty -g');
|
||||
|
||||
if ($stars === false) {
|
||||
shell_exec('stty -echo');
|
||||
$password = rtrim(fgets(STDIN), "\n");
|
||||
} else {
|
||||
shell_exec('stty -icanon -echo min 1 time 0');
|
||||
|
||||
$password = '';
|
||||
while (true) {
|
||||
$char = fgetc(STDIN);
|
||||
|
||||
if ($char === "\n") {
|
||||
break;
|
||||
} else if (ord($char) === 127) {
|
||||
if (strlen($password) > 0) {
|
||||
fwrite(STDOUT, "\x08 \x08");
|
||||
$password = substr($password, 0, -1);
|
||||
}
|
||||
} else {
|
||||
fwrite(STDOUT, "*");
|
||||
$password .= $char;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reset old style
|
||||
shell_exec('stty ' . $oldStyle);
|
||||
|
||||
// Return the password
|
||||
return $password;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* Description of MindDir
|
||||
*
|
||||
* @author felipe
|
||||
*/
|
||||
class MindDir {
|
||||
/**
|
||||
* This method will copy the whole directory, recursively
|
||||
* but it is focused to the "generate project" tool
|
||||
* @author Felipe Nascimento
|
||||
* @name copyDir
|
||||
* @param String $source
|
||||
* @param String $dest
|
||||
* @param [String $flag]
|
||||
* @return boolean
|
||||
*/
|
||||
static function copyDir($source, $dest, $flag= false)
|
||||
{
|
||||
// Simple copy for a file
|
||||
if($flag)
|
||||
{
|
||||
$s= '...'.substr($source, -30);
|
||||
showLoadStatus("Copying ".$s, $_SESSION['currentPerc']);
|
||||
}
|
||||
if (is_file($source))
|
||||
{
|
||||
$c = copy($source, $dest);
|
||||
chmod($dest, 0777);
|
||||
return $c;
|
||||
}
|
||||
// Make destination directory
|
||||
if(!is_dir($dest))
|
||||
{
|
||||
$oldumask = umask(0);
|
||||
mkdir($dest, 0777);
|
||||
umask($oldumask);
|
||||
}
|
||||
// Loop through the folder
|
||||
$dir = dir($source);
|
||||
while(false !== $entry = $dir->read())
|
||||
{
|
||||
// Skip pointers
|
||||
if ( in_array($entry, array(".","..",".svn") ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// Deep copy directories
|
||||
if ($dest !== "$source/$entry")
|
||||
{
|
||||
Mind::copyDir("$source/$entry", "$dest/$entry", $flag);
|
||||
}
|
||||
}
|
||||
// Clean up
|
||||
$dir->close();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes recusrively a directory
|
||||
* @author thiago <erkethan@free.fr>
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
* @method deleteDir
|
||||
* @param String $dir
|
||||
* @return boolean
|
||||
*/
|
||||
static function deleteDir($dir)
|
||||
{
|
||||
if(!file_exists($dir))
|
||||
return true;
|
||||
if(!is_dir($dir) || is_link($dir))
|
||||
return unlink($dir);
|
||||
foreach(scandir($dir) as $item)
|
||||
{
|
||||
if ($item == '.' || $item == '..')
|
||||
continue;
|
||||
if(!$this->deleteDir($dir . "/" . $item))
|
||||
{
|
||||
chmod($dir . "/" . $item, 0777);
|
||||
if(!$this->deleteDir($dir . "/" . $item))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return rmdir($dir);
|
||||
}
|
||||
}
|
||||
@@ -19,4 +19,21 @@
|
||||
$this->event= $evt=='before'? 'before':'after';
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a MindPlugin based object to the
|
||||
* plugins and triggers list
|
||||
*
|
||||
* @param MindPlugin $plugin
|
||||
*/
|
||||
static function addPlugin(&$plugin)
|
||||
{
|
||||
if(in_array($plugin->trigger, Mind::$triggers))
|
||||
{
|
||||
if(!isset(Mind::$pluginList[$plugin->trigger]))
|
||||
Mind::$pluginList[$plugin->trigger]= Array( 'before'=>Array(),
|
||||
'after'=>Array());
|
||||
Mind::$pluginList[$plugin->trigger][$plugin->event][]= $plugin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,74 @@
|
||||
* @author felipe
|
||||
*/
|
||||
class MindProject {
|
||||
//put your code here
|
||||
/**
|
||||
* Returns true if the project already exists,
|
||||
* false, otherwise
|
||||
*
|
||||
* @global Mind $_MIND
|
||||
* @param String $project
|
||||
* @return boolean
|
||||
*/
|
||||
static function hasProject($project)
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
$projectfile= Mind::$projectsDir.$project;
|
||||
$noAccess= true;
|
||||
|
||||
$db= new MindDB();
|
||||
$hasProject= "SELECT pk_project,
|
||||
project.name as name
|
||||
from project_user,
|
||||
project
|
||||
where fk_user= ".$_SESSION['pk_user']."
|
||||
and project.name = '".$project."'
|
||||
and fk_project = pk_project
|
||||
";
|
||||
$data= $db->query($hasProject);
|
||||
if(sizeof($data)>0)
|
||||
foreach($data as $row)
|
||||
{
|
||||
$noAccess= false;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!file_exists($projectfile) || $noAccess)
|
||||
{
|
||||
Mind::write('noProject', true, $project);
|
||||
return false;
|
||||
}
|
||||
return $row;
|
||||
}
|
||||
|
||||
public static function loadIdiom($idiom)
|
||||
{
|
||||
$idiom= str_replace('\\', DIRECTORY_SEPARATOR, $idiom);
|
||||
$langPath= $path.'/mind3rd/API/languages/'.$idiom.'/';
|
||||
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . $langPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads data from the passed project
|
||||
*
|
||||
* @param AssocArray $p
|
||||
* @return boolean
|
||||
*/
|
||||
public static function openProject($p)
|
||||
{
|
||||
$_SESSION['currentProject']= $p['pk_project'];
|
||||
$_SESSION['currentProjectName']= $p['name'];
|
||||
$_SESSION['currentProjectDir']= Mind::$projectsDir.$p['name'];
|
||||
$p['path']= Mind::$projectsDir.$p['name'];
|
||||
$p['sources']= Mind::$projectsDir.$p['name'].'/sources';
|
||||
$ini= parse_ini_file(Mind::$projectsDir.$p['name'].'/mind.ini');
|
||||
$p= array_merge($p, $ini);
|
||||
|
||||
Mind::$currentProject= $p;
|
||||
Mind::$curLang= Mind::$currentProject['idiom'];
|
||||
Mind::$content= '';
|
||||
Mind::write('projectOpened', true, $p['name']);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
class MindSpeaker
|
||||
{
|
||||
/**
|
||||
* This method returns or outputs messages using the L10N library
|
||||
* You can pass a rich string with %s, %i, etc, sending extra parameters
|
||||
* If the boolean flag $echo is sent, it prints it to the output, otherwise,
|
||||
* only returns it
|
||||
*
|
||||
* @param String $k
|
||||
* @param Bolean $echo
|
||||
* @param mixed... extra parameter to be treated in the string
|
||||
* @return String
|
||||
*/
|
||||
public static function write($k, $echo=true, $args=false)
|
||||
{
|
||||
$msg= Mind::$l10n->getMessage($k);
|
||||
if(!$msg)
|
||||
{
|
||||
$msg= Mind::message("L10N: Message $k does not exist", '[Fail]', false);
|
||||
}
|
||||
if(!is_array($args))
|
||||
$args= func_get_args();
|
||||
$parms= "";
|
||||
if(sizeof($args)>2)
|
||||
{
|
||||
for($i=2; $i<sizeof($args); $i++)
|
||||
{
|
||||
$parms.= ', "'.$args[$i].'"';
|
||||
}
|
||||
$parms= '"'.$msg.'"'.$parms;
|
||||
eval("\$print= sprintf(".$parms.");");
|
||||
}else{
|
||||
$print= $msg;
|
||||
}
|
||||
$count= 1;
|
||||
while(strlen($print) >= _CONSOLE_LINE_LENGTH_ && strpos($print, '..')>-1)
|
||||
{
|
||||
$print= preg_replace("/\.\./", '.', $print, $count);
|
||||
}
|
||||
if($echo)
|
||||
echo $print;
|
||||
return $msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns or prints a message formated to represent failures, passes
|
||||
* or any kind of alert
|
||||
*
|
||||
* @param String $message The message itself
|
||||
* @param String $status The status to be shown in the end of the message
|
||||
* @param Boolean $echo if it should be printed or not
|
||||
* @return string
|
||||
*/
|
||||
public static function message($message, $status, $echo=true)
|
||||
{
|
||||
$msg= str_pad($message, _CONSOLE_LINE_LENGTH_ - strlen($status), '.').$status."\n";
|
||||
if($echo)
|
||||
echo $msg;
|
||||
return $msg;
|
||||
}
|
||||
}
|
||||
@@ -157,11 +157,11 @@ class Lexer
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
$this->glue= chr('176');
|
||||
$this->lang= Mind::$l10n->name;
|
||||
$this->lang= Mind::$currentProject['idiom'];
|
||||
$xml= simplexml_load_file(Mind::$langPath.$this->lang.'/lexics.xml');
|
||||
include(Mind::$langPath.$this->lang.'/Inflect.php');
|
||||
//include(Mind::$langPath.$this->lang.'/Inflect.php');
|
||||
|
||||
$this->validChars= (string)$xml->validchars->lower;
|
||||
$this->validChars = (string)$xml->validchars->lower;
|
||||
$this->validChars.= (string)$xml->validchars->upper;
|
||||
$this->validChars.= (string)$xml->validchars->special;
|
||||
$this->validChars.= (string)$xml->validchars->numbers;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* This class is responsable to the analisys of the system
|
||||
* preparing the relations and apply the first rules
|
||||
*
|
||||
* @author felipe
|
||||
*/
|
||||
class Analyst {
|
||||
|
||||
/**
|
||||
* This method receives each expression and analizes
|
||||
* the best way to act and to store the understood
|
||||
* structure
|
||||
*
|
||||
* @param String $expression
|
||||
* @param String $structure
|
||||
* @param Array $structureKeys
|
||||
* @return Boolean True if everything went ok, false when any error occurred
|
||||
*/
|
||||
public static function analize($expression, $structure, $structureKeys){
|
||||
|
||||
// let's simply print it as a message, by now
|
||||
echo implode(' ', $expression).'-'.$structure.'-'.implode('|', $structureKeys).'<br/>';
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
* @package cortex.analyst
|
||||
* @author felipe
|
||||
*/
|
||||
class Canonic extends Inflect{
|
||||
class Canonic{
|
||||
|
||||
/**
|
||||
* Takes a word to its canonic form(singular, male form)
|
||||
@@ -16,8 +16,8 @@ class Canonic extends Inflect{
|
||||
*/
|
||||
public static function canonize($word)
|
||||
{
|
||||
if(!self::isSingular($word))
|
||||
$word= self::toSingular($word);
|
||||
if(!pt\Inflect::isSingular($word)) /* TODO: fix it*/
|
||||
$word= pt\Inflect::toSingular($word);
|
||||
/*if(self::isFemale($word)) // demands more tests
|
||||
// apparently, female substantives are brought to a wrong male form
|
||||
$word= self::toMale($word);*/
|
||||
@@ -35,15 +35,17 @@ class Canonic extends Inflect{
|
||||
$newContent= Array();
|
||||
|
||||
Mind::$tokenizer= new Tokenizer();
|
||||
$ignoreForms= Mind::$currentProject['idiom'].'\IgnoreForms';
|
||||
$verbalizer= Mind::$currentProject['idiom'].'\Verbalizer';
|
||||
|
||||
foreach($content as $word)
|
||||
{
|
||||
if(IgnoreForms::shouldBeIgnored($word))
|
||||
if($ignoreForms::shouldBeIgnored($word))
|
||||
continue;
|
||||
if(!Tokenizer::isQualifier($word) && !Tokenizer::isQuantifier($word))
|
||||
{
|
||||
if(strlen($word) > 1 && ($isVerb= Verbalizer::isVerb($word)))
|
||||
$word= Verbalizer::toInfinitive($word);
|
||||
if(strlen($word) > 1 && ($isVerb= $verbalizer::isVerb($word)))
|
||||
$word= $verbalizer::toInfinitive($word);
|
||||
else{
|
||||
$word= explode(':', $word);
|
||||
$word[0]= Canonic::canonize($word[0]);
|
||||
@@ -55,5 +57,4 @@ class Canonic extends Inflect{
|
||||
Mind::$content= $newContent;
|
||||
return $newContent;
|
||||
}
|
||||
}
|
||||
?>
|
||||
}
|
||||
@@ -62,8 +62,10 @@ class Syntaxer {
|
||||
$len= strlen($found[0]);
|
||||
$expression= array_slice(Token::$words, $found[1], $len);
|
||||
$tokens= array_slice(Token::$spine, $found[1], $len);
|
||||
echo implode(' ', $expression).'-'.$found[0].'-'.implode('|', $tokens);
|
||||
echo '<br/>';
|
||||
$struct= $found[0];
|
||||
|
||||
// let's analize it, now
|
||||
Analyst::analize($expression, $struct, $tokens);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,9 @@ class Token
|
||||
|
||||
public function add($word)
|
||||
{
|
||||
$ignoreForms= Mind::$currentProject['idiom'].'\IgnoreForms';
|
||||
$verbalizer= Mind::$currentProject['idiom'].'\Verbalizer';
|
||||
|
||||
if(in_array($word, Tokenizer::$qualifiers['coma']))
|
||||
{
|
||||
$word= ',';
|
||||
@@ -47,7 +50,7 @@ class Token
|
||||
|
||||
self::$words[]= $word;
|
||||
|
||||
if(IgnoreForms::shouldBeIgnored($word))
|
||||
if($ignoreForms::shouldBeIgnored($word))
|
||||
{
|
||||
self::$spine[]= Token::MT_ANY;
|
||||
self::$string.= Token::MS_ANY;
|
||||
@@ -130,7 +133,7 @@ class Token
|
||||
// we know these words are already on its
|
||||
// canonic form, so, we can simply look for
|
||||
// it on the list
|
||||
if(Verbalizer::isInVerbList($word))
|
||||
if($verbalizer::isInVerbList($word))
|
||||
{
|
||||
self::$spine[]= Token::MT_VERB;
|
||||
self::$string.= Token::MS_VERB;
|
||||
|
||||
@@ -30,7 +30,7 @@ class Tokenizer extends Token{
|
||||
* sent XML file
|
||||
*
|
||||
* @name loadSintatics
|
||||
* @param SimpleXML $resource
|
||||
* @param String $resource
|
||||
* @return AssocArray
|
||||
*/
|
||||
public static function loadSintatics($resource)
|
||||
@@ -153,15 +153,16 @@ class Tokenizer extends Token{
|
||||
{
|
||||
if(!file_exists('sintatics.list'))
|
||||
{
|
||||
self::loadSintatics(fopen(Mind::$langPath.Mind::$l10n->name.'/sintatics.list', 'rb'));
|
||||
self::loadSintatics(fopen(Mind::$langPath.Mind::$currentProject['idiom'].
|
||||
'/sintatics.list', 'rb'));
|
||||
$qnt= simplexml_load_file(Mind::$langPath.
|
||||
Mind::$l10n->name.
|
||||
Mind::$currentProject['idiom'].
|
||||
'/quantifiers.xml');
|
||||
$qlf= simplexml_load_file(Mind::$langPath.
|
||||
Mind::$l10n->name.
|
||||
Mind::$currentProject['idiom'].
|
||||
'/qualifiers.xml');
|
||||
$tps= simplexml_load_file(Mind::$langPath.
|
||||
Mind::$l10n->name.
|
||||
Mind::$currentProject['idiom'].
|
||||
'/datatypes.xml');
|
||||
self::loadQuantifiers($qnt);
|
||||
self::loadQualifiers($qlf);
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
namespace en;
|
||||
/**
|
||||
* This class provides a list of instructtions
|
||||
* which define when a word should be ignored,
|
||||
* plus a list of key words to ignore
|
||||
*
|
||||
* @package cortex.analyst
|
||||
* @author felipe
|
||||
*/
|
||||
class IgnoreForms {
|
||||
/**
|
||||
* The list of words to be ignored
|
||||
* @var Array
|
||||
* @static
|
||||
*/
|
||||
public static $ignoreList= false;
|
||||
|
||||
/**
|
||||
* A list of rules, to identify words to be ignored
|
||||
* @var Array
|
||||
* @static
|
||||
*/
|
||||
public static $ignoreRules= Array(
|
||||
'/(.)[nrth]ly$/' // like currently, monthly...
|
||||
);
|
||||
|
||||
/**
|
||||
* This method reads the ignore.list file and
|
||||
* parses it to an indexed array
|
||||
* @static
|
||||
* @name loadVerbs
|
||||
*/
|
||||
public static function loadIgnoreList()
|
||||
{
|
||||
if(!file_exists('ignore.list'))
|
||||
$fR= fopen(\Mind::$langPath.\Mind::$l10n->name.'/ignore.list', 'rb');
|
||||
else
|
||||
$fR= fopen('ignore.list', 'rb');
|
||||
self::$ignoreList= Array();
|
||||
while (!feof($fR)){
|
||||
$word= preg_replace('/\s/', '', fgets($fR, 4096));
|
||||
self::$ignoreList[$word]= true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns wheter the word should or not be ignored
|
||||
* @name shouldBeIgnored
|
||||
* @param string $word
|
||||
* @return boolean
|
||||
*/
|
||||
public static function shouldBeIgnored($word)
|
||||
{
|
||||
if(!self::$ignoreList)
|
||||
self::loadIgnoreList();
|
||||
if(isset(self::$ignoreList[$word]))
|
||||
return true;
|
||||
foreach(self::$ignoreRules as $rule)
|
||||
{
|
||||
if(preg_match($rule, $word))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the word should be used
|
||||
* @name shouldBeUsed
|
||||
* @static
|
||||
* @param string $word
|
||||
* @return boolean
|
||||
*/
|
||||
public static function shouldBeUsed($word)
|
||||
{
|
||||
return !self::shouldBeIgnored($word);
|
||||
}
|
||||
}
|
||||
@@ -1,35 +1,29 @@
|
||||
<?php
|
||||
// Thanks to http://www.eval.ca/articles/php-pluralize (MIT license)
|
||||
// http://dev.rubyonrails.org/browser/trunk/activesupport/lib/active_support/inflections.rb (MIT license)
|
||||
// http://www.fortunecity.com/bally/durrus/153/gramch13.html
|
||||
// http://www2.gsu.edu/~wwwesl/egw/crump.htm
|
||||
//
|
||||
// Changes (12/17/07)
|
||||
// Major changes
|
||||
// --
|
||||
// Fixed irregular noun algorithm to use regular expressions just like the original Ruby source.
|
||||
// (this allows for things like fireman -> firemen
|
||||
// Fixed the order of the singular array, which was backwards.
|
||||
//
|
||||
// Minor changes
|
||||
// --
|
||||
// Removed incorrect pluralization rule for /([^aeiouy]|qu)ies$/ => $1y
|
||||
// Expanded on the list of exceptions for *o -> *oes, and removed rule for buffalo -> buffaloes
|
||||
// Removed dangerous singularization rule for /([^f])ves$/ => $1fe
|
||||
// Added more specific rules for singularizing lives, wives, knives, sheaves, loaves, and leaves and thieves
|
||||
// Added exception to /(us)es$/ => $1 rule for houses => house and blouses => blouse
|
||||
// Added excpetions for feet, geese and teeth
|
||||
// Added rule for deer -> deer
|
||||
//
|
||||
// Changed by Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
// added is_singular static method
|
||||
//
|
||||
// Changes:
|
||||
// Removed rule for virus -> viri
|
||||
// Added rule for potato -> potatoes
|
||||
// Added rule for *us -> *uses
|
||||
/*
|
||||
Thanks to http://www.eval.ca/articles/php-toPlural (MIT license)
|
||||
http://dev.rubyonrails.org/browser/trunk/activesupport/lib/active_support/inflections.rb (MIT license)
|
||||
http://www.fortunecity.com/bally/durrus/153/gramch13.html
|
||||
http://www2.gsu.edu/~wwwesl/egw/crump.htm
|
||||
This classe has been partly inspired on the above cite codes.
|
||||
The other methods and all the regular expression except the ones
|
||||
refered to plural and singular on english were created by:
|
||||
Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
* You can contribute changing this file and telling me, or maybe
|
||||
* adding tests to it, and in case you find anything weird, please
|
||||
* let me know :)
|
||||
*/
|
||||
|
||||
class Inflect
|
||||
namespace en;
|
||||
|
||||
/**
|
||||
* This class should inflect words for different idioms
|
||||
* changing its genre and number
|
||||
* IN THIS CASE: pt-BR
|
||||
* @name Inflect
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
* @package cortex.analyst
|
||||
*/
|
||||
class Inflect implements \inflection
|
||||
{
|
||||
static $plural = array(
|
||||
'/(quiz)$/i' => "$1zes",
|
||||
@@ -82,6 +76,9 @@ class Inflect
|
||||
'/(us)es$/i' => "$1",
|
||||
'/s$/i' => ""
|
||||
);
|
||||
static $female= Array();
|
||||
static $male= Array();
|
||||
static $genreSpecific= Array();
|
||||
|
||||
static $irregular = array(
|
||||
'move' => 'moves',
|
||||
@@ -105,18 +102,24 @@ class Inflect
|
||||
'information',
|
||||
'equipment'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
* @method isSingular
|
||||
* @return boolean
|
||||
* @param String $string
|
||||
*/
|
||||
public static function is_singular( $string )
|
||||
{
|
||||
// if it is uncountable, then, it may be treated as a singular
|
||||
if(in_array($string, Inflect::$uncountable))
|
||||
if(in_array($string, self::$uncountable))
|
||||
return true;
|
||||
// let's check for irregular forms
|
||||
if(in_array($string, array_keys(Inflect::$irregular)))
|
||||
if(in_array($string, array_keys(self::$irregular)))
|
||||
return true;
|
||||
// now, let's see if the word isn't the plural from a irregular form
|
||||
// still faster than running all the plural forms, I bet
|
||||
elseif(in_array($string, Inflect::$irregular))
|
||||
elseif(in_array($string, self::$irregular))
|
||||
return false;
|
||||
// ok, if the word reached here, it diserves some care
|
||||
// let's finally check if it matches with any plural rule
|
||||
@@ -130,7 +133,13 @@ class Inflect
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function pluralize( $string )
|
||||
/**
|
||||
* Set a word to plural
|
||||
* @method toPlural
|
||||
* @param String $string
|
||||
* @return String
|
||||
*/
|
||||
public static function toPlural($string)
|
||||
{
|
||||
// save some time in the case that singular and plural are the same
|
||||
if ( in_array( strtolower( $string ), self::$uncountable ) )
|
||||
@@ -155,7 +164,14 @@ class Inflect
|
||||
return $string;
|
||||
}
|
||||
|
||||
public static function singularize( $string )
|
||||
/**
|
||||
* Sets a word to singular form
|
||||
*
|
||||
* @method toSingular
|
||||
* @param String $string
|
||||
* @return String
|
||||
*/
|
||||
public static function toSingular($string)
|
||||
{
|
||||
// save some time in the case that singular and plural are the same
|
||||
if ( in_array( strtolower( $string ), self::$uncountable ) )
|
||||
@@ -180,11 +196,15 @@ class Inflect
|
||||
return $string;
|
||||
}
|
||||
|
||||
public static function pluralize_if($count, $string)
|
||||
{
|
||||
if ($count == 1)
|
||||
return "1 $string";
|
||||
else
|
||||
return $count . " " . self::pluralize($string);
|
||||
}
|
||||
/**
|
||||
* Verifies whether the given word is female or not
|
||||
*
|
||||
* @method isFemale
|
||||
* @param String $string
|
||||
* @return String
|
||||
*/
|
||||
public static function isFemale($string)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
namespace en;
|
||||
/**
|
||||
* This class should identify verbs
|
||||
* NOTICE that its goals is about the present/future words...
|
||||
* past is not supported
|
||||
* @package cortex.analyst
|
||||
* @author felipe
|
||||
*/
|
||||
class Verbalizer {
|
||||
/**
|
||||
* @var AssocArray $verbs - The associative list of verbs
|
||||
* @static $verbs
|
||||
*/
|
||||
public static $verbs= false;
|
||||
|
||||
/**
|
||||
* @var AssocArray An array of verbs that may indicate a possibility
|
||||
*/
|
||||
static $possibilities= Array(
|
||||
'can',
|
||||
'may',
|
||||
'maybe',
|
||||
'possibly',
|
||||
'probably'
|
||||
);
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @var AssocArray the possible flections a verb may suffer
|
||||
*/
|
||||
static $flections = array(
|
||||
'/y$/' => 'ies',
|
||||
'/s$/' => 'es',
|
||||
'/.$/' => '$1s'
|
||||
);
|
||||
|
||||
/**
|
||||
* Words that should NOT be changed
|
||||
* @static
|
||||
* @var AssocArray A list of fixed exceptions
|
||||
*/
|
||||
static $exceptions= Array(
|
||||
'has' => 'have',
|
||||
'have' => 'has',
|
||||
'be' => 'be'
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns if the passed word means the verb is a possibility
|
||||
* @param string $word
|
||||
* @static
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isAPosibility($string)
|
||||
{
|
||||
return in_array($string, self::$possibilities);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the passed word is in the infinitive form
|
||||
* @param string $word
|
||||
* @static
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isInfinitive($string)
|
||||
{
|
||||
$isInVerBlist= self::isInVerbList($string);
|
||||
foreach(self::$flections as $pattern=>$result)
|
||||
{
|
||||
if(preg_match('/'.$result.'$/i', $string) && $isInVerBlist)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to bring any word to its infinitive form
|
||||
* Returns false if it is not in the verbs.list
|
||||
* @param string $word
|
||||
* @return string
|
||||
* @static
|
||||
*/
|
||||
public static function toInfinitive($string)
|
||||
{
|
||||
$string= strtolower($string);
|
||||
if(self::isInfinitive($string))
|
||||
return $string;
|
||||
|
||||
if(isset(self::$exceptions[$string]))
|
||||
{
|
||||
return self::$exceptions[$string];
|
||||
}
|
||||
if(self::isAPosibility($string))
|
||||
{
|
||||
return $string;
|
||||
}
|
||||
|
||||
foreach(self::$flections as $pattern=>$result)
|
||||
{
|
||||
$pattern= ''.$pattern.'i';
|
||||
if(preg_match($pattern, $string))
|
||||
{
|
||||
$tmpWord= preg_replace($pattern, $result, $string);
|
||||
if(self::isInVerbList($tmpWord))
|
||||
return $tmpWord;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies if the passed word is in the verbs.list
|
||||
* @param string $word
|
||||
* @return boolean
|
||||
* @static
|
||||
*/
|
||||
public static function isInVerbList($string)
|
||||
{
|
||||
if(!self::$verbs)
|
||||
self::loadVerbs();
|
||||
return isset(self::$verbs[$string]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the received word is a verb or not
|
||||
* @param string $word
|
||||
* @static
|
||||
*/
|
||||
public static function isVerb($word)
|
||||
{
|
||||
$word= self::toInfinitive($word);
|
||||
if($word)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method reads the verbs.list file and
|
||||
* parses it to an indexed array
|
||||
* @name loadVerbs
|
||||
* @static
|
||||
*/
|
||||
public static function loadVerbs()
|
||||
{
|
||||
if(!file_exists('verbs.list'))
|
||||
$fR= fopen(\Mind::$langPath.\Mind::$l10n->name.'/verbs.list', 'rb');
|
||||
else
|
||||
$fR= fopen('verbs.list', 'rb');
|
||||
self::$verbs= Array();
|
||||
while (!feof($fR)){
|
||||
$verb= preg_replace('/\s/', '', fgets($fR, 4096));
|
||||
self::$verbs[$verb]= true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Document : datatypes.xml
|
||||
Created on : January 3, 2011, 12:04 AM
|
||||
Author : felipe
|
||||
Description:
|
||||
This document defines the translation and
|
||||
definition for data types in database
|
||||
It uses the most basic forms of data to be
|
||||
stored
|
||||
-->
|
||||
<root>
|
||||
<varchar>string,characters,chars,varchar,description,desc,obs,observation</varchar>
|
||||
<char>char,character,c,letter,digit</char>
|
||||
<int>int,integer,number</int>
|
||||
<float>float,real,double,money,percentage,perc,precision</float>
|
||||
<boolean>bool,boolean</boolean>
|
||||
<date>date,day,calendar,dt</date>
|
||||
<time>time,datetime,dthr,hr,hour</time>
|
||||
<file>blob,oid,lo,file,binary,image,picture</file>
|
||||
</root>
|
||||
@@ -0,0 +1,8 @@
|
||||
the
|
||||
at
|
||||
that
|
||||
which
|
||||
whom
|
||||
whose
|
||||
well
|
||||
too
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Document : lexics.xml
|
||||
Created on : November 6, 2010, 1:40 PM
|
||||
Author : felipe
|
||||
Description:
|
||||
Lists the valid characteres to be allowed, or to be translated
|
||||
-->
|
||||
<root>
|
||||
<validchars>
|
||||
<lower>abcdefghijklmnopqrstuvxyzw</lower>
|
||||
<upper>ABCDEFGHIJKLMNOPQRSTUVXYZW</upper>
|
||||
<special>."</special>
|
||||
<numbers>1234567890</numbers>
|
||||
<symbols>\/!@#$%*()_-+=,.'":>&<</symbols>
|
||||
</validchars>
|
||||
<replacements>
|
||||
<from></from>
|
||||
<to ></to>
|
||||
</replacements>
|
||||
</root>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Document : qualifiers.xml
|
||||
Created on : december 21, 2010, 1:57 Am
|
||||
Author : felipenmoura
|
||||
Description:
|
||||
This file describes the words that may be used as qualifiers
|
||||
-->
|
||||
<root>
|
||||
<must>must,should,needs,demands,requires</must>
|
||||
<may>may,can</may>
|
||||
<notnull>not null,notnull,required,needed</notnull>
|
||||
<of>of</of>
|
||||
<be>is,are</be>
|
||||
<key>key,pk,indice</key>
|
||||
<coma>and</coma>
|
||||
</root>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Document : quantifiers.xml
|
||||
Created on : November 7, 2010, 4:29 PM
|
||||
Author : felipenmoura
|
||||
Description:
|
||||
This file describes the words that may be used as quantifiers
|
||||
-->
|
||||
<root>
|
||||
<none>none,zero,0,nothing,noone</none>
|
||||
<one>one,1,a</one>
|
||||
<many>many,much,some,any,various,n,m,x</many>
|
||||
<or>or,/,to,until</or>
|
||||
</root>
|
||||
@@ -0,0 +1,730 @@
|
||||
is
|
||||
are
|
||||
set
|
||||
accept
|
||||
add
|
||||
admire
|
||||
admit
|
||||
advise
|
||||
afford
|
||||
agree
|
||||
alert
|
||||
allow
|
||||
amuse
|
||||
analyse
|
||||
announce
|
||||
annoy
|
||||
answer
|
||||
apologise
|
||||
appear
|
||||
applaud
|
||||
appreciate
|
||||
approve
|
||||
argue
|
||||
arrange
|
||||
arrest
|
||||
arrive
|
||||
ask
|
||||
attach
|
||||
attack
|
||||
attempt
|
||||
attend
|
||||
attract
|
||||
avoid
|
||||
|
||||
back
|
||||
bake
|
||||
balance
|
||||
ban
|
||||
bang
|
||||
bare
|
||||
bat
|
||||
bathe
|
||||
battle
|
||||
beam
|
||||
beg
|
||||
behave
|
||||
belong
|
||||
bleach
|
||||
bless
|
||||
blind
|
||||
blink
|
||||
blot
|
||||
blush
|
||||
boast
|
||||
boil
|
||||
bolt
|
||||
bomb
|
||||
book
|
||||
bore
|
||||
borrow
|
||||
bounce
|
||||
bow
|
||||
box
|
||||
brake
|
||||
brake
|
||||
branch
|
||||
breathe
|
||||
bruise
|
||||
brush
|
||||
bubble
|
||||
bump
|
||||
burn
|
||||
bury
|
||||
buzz
|
||||
calculate
|
||||
call
|
||||
camp
|
||||
care
|
||||
carry
|
||||
carve
|
||||
cause
|
||||
challenge
|
||||
change
|
||||
charge
|
||||
chase
|
||||
cheat
|
||||
check
|
||||
cheer
|
||||
chew
|
||||
choke
|
||||
chop
|
||||
claim
|
||||
clap
|
||||
clean
|
||||
clear
|
||||
clip
|
||||
close
|
||||
coach
|
||||
coil
|
||||
collect
|
||||
colour
|
||||
comb
|
||||
command
|
||||
communicate
|
||||
compare
|
||||
compete
|
||||
complain
|
||||
complete
|
||||
concentrate
|
||||
concern
|
||||
confess
|
||||
confuse
|
||||
connect
|
||||
consider
|
||||
consist
|
||||
contain
|
||||
continue
|
||||
copy
|
||||
correct
|
||||
cough
|
||||
count
|
||||
cover
|
||||
crack
|
||||
crash
|
||||
crawl
|
||||
cross
|
||||
crush
|
||||
cry
|
||||
cure
|
||||
curl
|
||||
curve
|
||||
cycle
|
||||
dam
|
||||
damage
|
||||
dance
|
||||
dare
|
||||
decay
|
||||
deceive
|
||||
decide
|
||||
decorate
|
||||
delay
|
||||
delight
|
||||
deliver
|
||||
depend
|
||||
describe
|
||||
desert
|
||||
deserve
|
||||
destroy
|
||||
detect
|
||||
develop
|
||||
disagree
|
||||
disappear
|
||||
disapprove
|
||||
disarm
|
||||
discover
|
||||
dislike
|
||||
divide
|
||||
double
|
||||
doubt
|
||||
drag
|
||||
drain
|
||||
dream
|
||||
dress
|
||||
drip
|
||||
drop
|
||||
drown
|
||||
drum
|
||||
dry
|
||||
dust
|
||||
earn
|
||||
educate
|
||||
embarrass
|
||||
employ
|
||||
empty
|
||||
encourage
|
||||
end
|
||||
enjoy
|
||||
enter
|
||||
entertain
|
||||
escape
|
||||
examine
|
||||
excite
|
||||
excuse
|
||||
exercise
|
||||
exist
|
||||
expand
|
||||
expect
|
||||
explain
|
||||
explode
|
||||
extend
|
||||
face
|
||||
fade
|
||||
fail
|
||||
fancy
|
||||
fasten
|
||||
fax
|
||||
fear
|
||||
fence
|
||||
fetch
|
||||
file
|
||||
fill
|
||||
film
|
||||
fire
|
||||
fit
|
||||
fix
|
||||
flap
|
||||
flash
|
||||
float
|
||||
flood
|
||||
flow
|
||||
flower
|
||||
fold
|
||||
follow
|
||||
fool
|
||||
force
|
||||
form
|
||||
found
|
||||
frame
|
||||
frighten
|
||||
fry
|
||||
gather
|
||||
gaze
|
||||
glow
|
||||
glue
|
||||
grab
|
||||
grate
|
||||
grease
|
||||
greet
|
||||
grin
|
||||
grip
|
||||
groan
|
||||
guarantee
|
||||
guard
|
||||
guess
|
||||
guide
|
||||
hammer
|
||||
hand
|
||||
handle
|
||||
hang
|
||||
happen
|
||||
harass
|
||||
harm
|
||||
hate
|
||||
haunt
|
||||
head
|
||||
heal
|
||||
heap
|
||||
heat
|
||||
help
|
||||
hook
|
||||
hop
|
||||
hope
|
||||
hover
|
||||
hug
|
||||
hum
|
||||
hunt
|
||||
hurry
|
||||
identify
|
||||
ignore
|
||||
imagine
|
||||
impress
|
||||
improve
|
||||
include
|
||||
increase
|
||||
influence
|
||||
inform
|
||||
inject
|
||||
injure
|
||||
instruct
|
||||
intend
|
||||
interest
|
||||
interfere
|
||||
interrupt
|
||||
introduce
|
||||
invent
|
||||
invite
|
||||
irritate
|
||||
itch
|
||||
jail
|
||||
jam
|
||||
jog
|
||||
join
|
||||
joke
|
||||
judge
|
||||
juggle
|
||||
jump
|
||||
kick
|
||||
kill
|
||||
kiss
|
||||
kneel
|
||||
knit
|
||||
knock
|
||||
knot
|
||||
label
|
||||
land
|
||||
last
|
||||
laugh
|
||||
launch
|
||||
learn
|
||||
level
|
||||
license
|
||||
lick
|
||||
lie
|
||||
lighten
|
||||
like
|
||||
list
|
||||
listen
|
||||
live
|
||||
load
|
||||
lock
|
||||
long
|
||||
look
|
||||
love
|
||||
man
|
||||
manage
|
||||
march
|
||||
mark
|
||||
marry
|
||||
match
|
||||
mate
|
||||
matter
|
||||
measure
|
||||
meddle
|
||||
melt
|
||||
memorise
|
||||
mend
|
||||
messup
|
||||
milk
|
||||
mine
|
||||
miss
|
||||
mix
|
||||
moan
|
||||
moor
|
||||
mourn
|
||||
move
|
||||
muddle
|
||||
mug
|
||||
multiply
|
||||
murder
|
||||
nail
|
||||
name
|
||||
need
|
||||
nest
|
||||
nod
|
||||
note
|
||||
notice
|
||||
number
|
||||
obey
|
||||
object
|
||||
observe
|
||||
obtain
|
||||
occur
|
||||
offend
|
||||
offer
|
||||
open
|
||||
order
|
||||
overflow
|
||||
owe
|
||||
own
|
||||
pack
|
||||
paddle
|
||||
paint
|
||||
park
|
||||
part
|
||||
pass
|
||||
paste
|
||||
pat
|
||||
pause
|
||||
peck
|
||||
pedal
|
||||
peel
|
||||
peep
|
||||
perform
|
||||
permit
|
||||
phone
|
||||
pick
|
||||
pinch
|
||||
pine
|
||||
place
|
||||
plan
|
||||
plant
|
||||
play
|
||||
please
|
||||
plug
|
||||
point
|
||||
poke
|
||||
polish
|
||||
pop
|
||||
possess
|
||||
post
|
||||
pour
|
||||
practise
|
||||
pray
|
||||
preach
|
||||
precede
|
||||
prefer
|
||||
prepare
|
||||
present
|
||||
preserve
|
||||
press
|
||||
pretend
|
||||
prevent
|
||||
prick
|
||||
print
|
||||
produce
|
||||
program
|
||||
promise
|
||||
protect
|
||||
provide
|
||||
pull
|
||||
pump
|
||||
punch
|
||||
puncture
|
||||
punish
|
||||
push
|
||||
question
|
||||
queue
|
||||
race
|
||||
radiate
|
||||
rain
|
||||
raise
|
||||
reach
|
||||
realise
|
||||
receive
|
||||
recognise
|
||||
record
|
||||
reduce
|
||||
reflect
|
||||
refuse
|
||||
regret
|
||||
reign
|
||||
reject
|
||||
rejoice
|
||||
relax
|
||||
release
|
||||
rely
|
||||
remain
|
||||
remember
|
||||
remind
|
||||
remove
|
||||
repair
|
||||
repeat
|
||||
replace
|
||||
reply
|
||||
report
|
||||
reproduce
|
||||
request
|
||||
rescue
|
||||
retire
|
||||
return
|
||||
rhyme
|
||||
rinse
|
||||
risk
|
||||
rob
|
||||
rock
|
||||
roll
|
||||
rot
|
||||
rub
|
||||
ruin
|
||||
rule
|
||||
rush
|
||||
sack
|
||||
sail
|
||||
satisfy
|
||||
save
|
||||
saw
|
||||
scare
|
||||
scatter
|
||||
scold
|
||||
scorch
|
||||
scrape
|
||||
scratch
|
||||
scream
|
||||
screw
|
||||
scribble
|
||||
scrub
|
||||
seal
|
||||
search
|
||||
separate
|
||||
serve
|
||||
settle
|
||||
shade
|
||||
share
|
||||
shave
|
||||
shelter
|
||||
shiver
|
||||
shock
|
||||
shop
|
||||
shrug
|
||||
sigh
|
||||
sign
|
||||
signal
|
||||
sin
|
||||
sip
|
||||
ski
|
||||
skip
|
||||
slap
|
||||
slip
|
||||
slow
|
||||
smash
|
||||
smell
|
||||
smile
|
||||
smoke
|
||||
snatch
|
||||
sneeze
|
||||
sniff
|
||||
snore
|
||||
snow
|
||||
soak
|
||||
soothe
|
||||
sound
|
||||
spare
|
||||
spark
|
||||
sparkle
|
||||
spell
|
||||
spill
|
||||
spoil
|
||||
spot
|
||||
spray
|
||||
sprout
|
||||
squash
|
||||
squeak
|
||||
squeal
|
||||
squeeze
|
||||
stain
|
||||
stamp
|
||||
stare
|
||||
start
|
||||
stay
|
||||
steer
|
||||
step
|
||||
stir
|
||||
stitch
|
||||
stop
|
||||
store
|
||||
strap
|
||||
strengthen
|
||||
stretch
|
||||
strip
|
||||
stroke
|
||||
stuff
|
||||
subtract
|
||||
succeed
|
||||
suck
|
||||
suffer
|
||||
suggest
|
||||
suit
|
||||
supply
|
||||
support
|
||||
suppose
|
||||
surprise
|
||||
surround
|
||||
suspect
|
||||
suspend
|
||||
switch
|
||||
talk
|
||||
tame
|
||||
tap
|
||||
taste
|
||||
tease
|
||||
telephone
|
||||
tempt
|
||||
terrify
|
||||
test
|
||||
thank
|
||||
thaw
|
||||
tick
|
||||
tickle
|
||||
tie
|
||||
time
|
||||
tip
|
||||
tire
|
||||
touch
|
||||
tour
|
||||
tow
|
||||
trace
|
||||
trade
|
||||
train
|
||||
transport
|
||||
trap
|
||||
travel
|
||||
treat
|
||||
tremble
|
||||
trick
|
||||
trip
|
||||
trot
|
||||
trouble
|
||||
trust
|
||||
try
|
||||
tug
|
||||
tumble
|
||||
turn
|
||||
twist
|
||||
type
|
||||
undress
|
||||
unfasten
|
||||
unite
|
||||
unlock
|
||||
unpack
|
||||
untidy
|
||||
use
|
||||
vanish
|
||||
visit
|
||||
wail
|
||||
wait
|
||||
walk
|
||||
wander
|
||||
want
|
||||
warm
|
||||
warn
|
||||
wash
|
||||
waste
|
||||
watch
|
||||
water
|
||||
wave
|
||||
weigh
|
||||
welcome
|
||||
whine
|
||||
whip
|
||||
whirl
|
||||
whisper
|
||||
whistle
|
||||
wink
|
||||
wipe
|
||||
wish
|
||||
wobble
|
||||
wonder
|
||||
work
|
||||
worry
|
||||
wrap
|
||||
wreck
|
||||
wrestle
|
||||
wriggle
|
||||
x-ray
|
||||
yawn
|
||||
yell
|
||||
zip
|
||||
zoom
|
||||
awake
|
||||
be
|
||||
beat
|
||||
become
|
||||
begin
|
||||
bend
|
||||
bet
|
||||
bid
|
||||
bite
|
||||
blow
|
||||
break
|
||||
bring
|
||||
broadcast
|
||||
build
|
||||
burn
|
||||
buy
|
||||
catch
|
||||
choose
|
||||
come
|
||||
cost
|
||||
cut
|
||||
dig
|
||||
do
|
||||
draw
|
||||
dream
|
||||
drive
|
||||
drink
|
||||
eat
|
||||
fall
|
||||
feel
|
||||
fight
|
||||
find
|
||||
fly
|
||||
forget
|
||||
forgive
|
||||
freeze
|
||||
get
|
||||
give
|
||||
go
|
||||
grow
|
||||
hang
|
||||
have
|
||||
hear
|
||||
hide
|
||||
hit
|
||||
hold
|
||||
hurt
|
||||
keep
|
||||
know
|
||||
lay
|
||||
lead
|
||||
learn
|
||||
leave
|
||||
lend
|
||||
let
|
||||
lie
|
||||
lose
|
||||
make
|
||||
mean
|
||||
meet
|
||||
pay
|
||||
put
|
||||
read
|
||||
ride
|
||||
ring
|
||||
rise
|
||||
run
|
||||
say
|
||||
see
|
||||
sell
|
||||
send
|
||||
show
|
||||
shut
|
||||
sing
|
||||
sit
|
||||
sleep
|
||||
speak
|
||||
spend
|
||||
stand
|
||||
swim
|
||||
take
|
||||
teach
|
||||
tear
|
||||
tell
|
||||
think
|
||||
throw
|
||||
understand
|
||||
wake
|
||||
wear
|
||||
win
|
||||
write
|
||||
has
|
||||
@@ -1,274 +0,0 @@
|
||||
<?php
|
||||
// Thanks to http://www.eval.ca/articles/php-toPlural (MIT license)
|
||||
// http://dev.rubyonrails.org/browser/trunk/activesupport/lib/active_support/inflections.rb (MIT license)
|
||||
// http://www.fortunecity.com/bally/durrus/153/gramch13.html
|
||||
// http://www2.gsu.edu/~wwwesl/egw/crump.htm
|
||||
//
|
||||
// Changes (12/17/07)
|
||||
// Major changes
|
||||
// --
|
||||
// Fixed irregular noun algorithm to use regular expressions just like the original Ruby source.
|
||||
// (this allows for things like fireman -> firemen
|
||||
// Fixed the order of the singular array, which was backwards.
|
||||
//
|
||||
// Minor changes
|
||||
// --
|
||||
// Removed incorrect pluralization rule for /([^aeiouy]|qu)ies$/ => $1y
|
||||
// Expanded on the list of exceptions for *o -> *oes, and removed rule for buffalo -> buffaloes
|
||||
// Removed dangerous singularization rule for /([^f])ves$/ => $1fe
|
||||
// Added more specific rules for singularizing lives, wives, knives, sheaves, loaves, and leaves and thieves
|
||||
// Added exception to /(us)es$/ => $1 rule for houses => house and blouses => blouse
|
||||
// Added excpetions for feet, geese and teeth
|
||||
// Added rule for deer -> deer
|
||||
//
|
||||
// Changed by Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
// added is_singular static method
|
||||
// translation to Brazilian portugues pt-BR
|
||||
//
|
||||
// Changes:
|
||||
// Removed rule for virus -> viri
|
||||
// Added rule for potato -> potatoes
|
||||
// Added rule for *us -> *uses
|
||||
|
||||
class Inflect
|
||||
{
|
||||
static $plural = array(
|
||||
'/(.+[aeiou])ão$/' => "$1ões",
|
||||
'/(.+[aeiou][a-z])ão$/' => "$1ães",
|
||||
'/(.+[rs])$/' => "$1es",
|
||||
'/(.+[aeou])l$/' => "$1is",
|
||||
'/(.+[áéíóúâô][a-z]{1,2})il$/' => "$1eis",
|
||||
'/(.+i)l$/' => "$1s",
|
||||
'/(.+)z$/' => "$1ses",
|
||||
'/(.+)m$/' => "$1ns",
|
||||
'/([aeiou])$/' => "$1s",
|
||||
'/(.+x)$/' => "$1"
|
||||
);
|
||||
|
||||
static $singular = array(
|
||||
'/(.+[aeiou])ões$/' => "$1ão",
|
||||
'/(.+[aeiou][a-z])ães$/' => "$1ão",
|
||||
'/(.+r)es$/' => "$1",
|
||||
'/(.+)ses$/' => "$1z",
|
||||
'/(.+s)es$/' => "$1",
|
||||
'/(.+[aeou])is$/' => "$1l",
|
||||
'/(.+[áéíóúâô][a-z]{1,2})eis$/' => "$1il",
|
||||
'/(.+i)s$/' => "$1l",
|
||||
'/(.+)ns$/' => "$1m",
|
||||
'/([aeiouãõéíóúâôê])s$/' => "$1",
|
||||
'/(.+x)$/' => "$1"
|
||||
);
|
||||
|
||||
static $female= Array(
|
||||
'/([aeiou][a-z]{1,2})ão$/' => "$1ona",
|
||||
'/([aeiou])ão$/' => "$1oa",
|
||||
'/o$/' => "a",
|
||||
'/e$/' => "a",
|
||||
'/or$/' => "ora",
|
||||
'/om$/' => "oa",
|
||||
'/m$/' => "m",
|
||||
);
|
||||
|
||||
static $male= Array(
|
||||
'/([aeiou][a-z]{1,2})ona$/' => "$1ão",
|
||||
'/([aeiou])oa$/' => "$1ão",
|
||||
'/ora$/' => "or",
|
||||
'/([aeiou][a-z]{1,2})a$/' => "$1o",
|
||||
'/a$/' => "e"
|
||||
);
|
||||
|
||||
static $genreSpecific= Array(
|
||||
'cônsul' => 'consulesa',
|
||||
'visconde' => 'viscondessa',
|
||||
'homem' => 'mulher'
|
||||
'poeta' => 'poetisa',
|
||||
'bode' => 'cabra',
|
||||
'boi' => 'vaca',
|
||||
'burro' => 'besta',
|
||||
'cão' => 'cadela',
|
||||
'carneiro' => 'ovelha',
|
||||
'cavaleiro' => 'amazona',
|
||||
'frade' => 'freira',
|
||||
'veado' => 'cerva',
|
||||
'zangão' => 'abelha',
|
||||
'ateu' => 'atéia',
|
||||
'ator' => 'atriz',
|
||||
'avô' => 'avó',
|
||||
'embaixador' => 'embaixatriz',
|
||||
'judeu' => 'judia',
|
||||
'maestro' => 'maestrina',
|
||||
'marajá' => 'marani',
|
||||
'réu' => 'ré',
|
||||
'sultão' => 'sultana'
|
||||
);
|
||||
|
||||
static $irregular = array(
|
||||
'move' => 'moves',
|
||||
'freguês'=> 'fregueses'
|
||||
);
|
||||
|
||||
static $uncountable = array(
|
||||
'óculos',
|
||||
'oculos',
|
||||
'átlas',
|
||||
'atlas',
|
||||
'binoculos',
|
||||
'calças',
|
||||
'lápis',
|
||||
'lapis',
|
||||
'vírus',
|
||||
'virus'
|
||||
);
|
||||
|
||||
/**
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
* @method is_singular
|
||||
* @return boolean
|
||||
* @param String $string
|
||||
*/
|
||||
public static function is_singular( $string )
|
||||
{
|
||||
// if it is uncountable, then, it may be treated as a singular
|
||||
if(in_array($string, Inflect::$uncountable))
|
||||
return true;
|
||||
// let's check for irregular forms
|
||||
if(in_array($string, array_keys(Inflect::$irregular)))
|
||||
return true;
|
||||
// now, let's see if the word isn't the plural from a irregular form
|
||||
// still faster than running all the plural forms, I bet
|
||||
elseif(in_array($string, Inflect::$irregular))
|
||||
return false;
|
||||
// ok, if the word reached here, it diserves some care
|
||||
// let's finally check if it matches with any plural rule
|
||||
foreach(self::$plural as $pattern => $result)
|
||||
{
|
||||
if(preg_match( $pattern, $string))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function toPlural( $string )
|
||||
{
|
||||
// save some time in the case that singular and plural are the same
|
||||
if ( in_array( strtolower( $string ), self::$uncountable ) )
|
||||
return $string;
|
||||
|
||||
// check for irregular singular forms
|
||||
foreach ( self::$irregular as $pattern => $result )
|
||||
{
|
||||
$pattern = '/' . $pattern . '$/i';
|
||||
|
||||
if ( preg_match( $pattern, $string ) )
|
||||
return preg_replace( $pattern, $result, $string);
|
||||
}
|
||||
|
||||
// check for matches using regular expressions
|
||||
foreach ( self::$plural as $pattern => $result )
|
||||
{
|
||||
if ( preg_match( $pattern, $string ) )
|
||||
return preg_replace( $pattern, $result, $string );
|
||||
}
|
||||
return preg_replace('/$/', '$1s', $string);
|
||||
return $string;
|
||||
}
|
||||
|
||||
public static function toSingular( $string )
|
||||
{
|
||||
// save some time in the case that singular and plural are the same
|
||||
if ( in_array( strtolower( $string ), self::$uncountable ) )
|
||||
return $string;
|
||||
|
||||
// check for irregular plural forms
|
||||
foreach ( self::$irregular as $result => $pattern )
|
||||
{
|
||||
$pattern = '/' . $pattern . '$/i';
|
||||
|
||||
if ( preg_match( $pattern, $string ) )
|
||||
return preg_replace( $pattern, $result, $string);
|
||||
}
|
||||
|
||||
// check for matches using regular expressions
|
||||
foreach ( self::$singular as $pattern => $result )
|
||||
{
|
||||
if ( preg_match( $pattern, $string ) )
|
||||
return preg_replace( $pattern, $result, $string );
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
public static function toPlural_if($count, $string)
|
||||
{
|
||||
if ($count == 1)
|
||||
return "1 $string";
|
||||
else
|
||||
return $count . " " . self::toPlural($string);
|
||||
}
|
||||
|
||||
public static function toFemale($string)
|
||||
{
|
||||
// first, we gotta see if it is a word with specific genre change
|
||||
if(array_key_exists($string, self::$genreSpecific))
|
||||
return self::$genreSpecific[$string];
|
||||
|
||||
// check for matches using regular expressions
|
||||
foreach(self::$female as $pattern => $result)
|
||||
{
|
||||
if(preg_match( $pattern, $string))
|
||||
return preg_replace($pattern, $result, $string);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
public static function toMale($string)
|
||||
{
|
||||
|
||||
// first, we gotta see if it is a word with specific genre change
|
||||
foreach ( self::$genreSpecific as $pattern => $result )
|
||||
{
|
||||
$pattern = '/' . $pattern . '$/i';
|
||||
if(preg_match($pattern, $string))
|
||||
return preg_replace($pattern, $result, $string);
|
||||
}
|
||||
|
||||
// check for matches using regular expressions
|
||||
foreach(self::$male as $pattern => $result)
|
||||
{
|
||||
if(preg_match( $pattern, $string))
|
||||
return preg_replace($pattern, $result, $string);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
public static function isFemale($string)
|
||||
{
|
||||
// it is a female from the specific list
|
||||
if(in_array($string, self::$genreSpecific))
|
||||
return true;
|
||||
// if it is a male kay, in the specific list
|
||||
if(array_key_exists($string, self::$genreSpecific))
|
||||
return false;
|
||||
// ok, now let's see if it is a female by touching it!
|
||||
foreach(self::$female as $pattern => $result)
|
||||
{
|
||||
if(preg_match($pattern, $string))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+4
-1
@@ -1,4 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace pt;
|
||||
|
||||
/**
|
||||
* This class provides a list of instructtions
|
||||
* which define when a word should be ignored,
|
||||
@@ -33,7 +36,7 @@
|
||||
public static function loadIgnoreList()
|
||||
{
|
||||
if(!file_exists('ignore.list'))
|
||||
$fR= fopen(Mind::$langPath.Mind::$l10n->name.'/ignore.list', 'rb');
|
||||
$fR= fopen(\Mind::$langPath.\Mind::$l10n->name.'/ignore.list', 'rb');
|
||||
else
|
||||
$fR= fopen('ignore.list', 'rb');
|
||||
self::$ignoreList= Array();
|
||||
@@ -13,6 +13,8 @@
|
||||
* let me know :)
|
||||
*/
|
||||
|
||||
namespace pt;
|
||||
|
||||
/**
|
||||
* This class should inflect words for different idioms
|
||||
* changing its genre and number
|
||||
@@ -21,7 +23,7 @@
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
* @package cortex.analyst
|
||||
*/
|
||||
class Inflect implements inflection
|
||||
class Inflect implements \inflection
|
||||
{
|
||||
static $plural = array(
|
||||
'/^a$/i' => "a",
|
||||
@@ -141,14 +143,14 @@ class Inflect implements inflection
|
||||
public static function isSingular( $string )
|
||||
{
|
||||
// if it is uncountable, then, it may be treated as a singular
|
||||
if(in_array($string, Inflect::$uncountable))
|
||||
if(in_array($string, self::$uncountable))
|
||||
return true;
|
||||
// let's check for irregular forms
|
||||
if(in_array($string, array_keys(Inflect::$irregular)))
|
||||
if(in_array($string, array_keys(self::$irregular)))
|
||||
return true;
|
||||
// now, let's see if the word isn't the plural from a irregular form
|
||||
// still faster than running all the plural forms, I bet
|
||||
elseif(in_array($string, Inflect::$irregular))
|
||||
elseif(in_array($string, self::$irregular))
|
||||
return false;
|
||||
// ok, if the word reached here, it diserves some care
|
||||
// let's finally check if it matches with any plural rule
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
namespace pt;
|
||||
/**
|
||||
* This class should identify verbs
|
||||
* NOTICE that its goals is about the present/future words...
|
||||
@@ -171,7 +172,7 @@ class Verbalizer {
|
||||
public static function loadVerbs()
|
||||
{
|
||||
if(!file_exists('verbs.list'))
|
||||
$fR= fopen(Mind::$langPath.Mind::$l10n->name.'/verbs.list', 'rb');
|
||||
$fR= fopen(\Mind::$langPath.\Mind::$l10n->name.'/verbs.list', 'rb');
|
||||
else
|
||||
$fR= fopen('verbs.list', 'rb');
|
||||
self::$verbs= Array();
|
||||
+1
-1
@@ -9,6 +9,6 @@
|
||||
<root>
|
||||
<none>nada,nenhum,zero,0,nenhuma</none>
|
||||
<one>um,uma,1,algum,alguma</one>
|
||||
<many>um,uma,uns,alguns,umas,algumas,muito,muita,muitos,vários,muitas,várias,diversos,diversas,n,m,x</many>
|
||||
<many>uns,alguns,umas,algumas,muito,muita,muitos,vários,muitas,várias,diversos,diversas,n,m,x</many>
|
||||
<or>ou,até,/</or>
|
||||
</root>
|
||||
@@ -0,0 +1,6 @@
|
||||
SVS
|
||||
SQVS
|
||||
SVNONS
|
||||
SVNS
|
||||
SQVNONS
|
||||
SQVNS
|
||||
@@ -24,4 +24,4 @@ database_addr=localhost
|
||||
database_port=5432
|
||||
; and here, the user and password
|
||||
database_user=root
|
||||
dataase_pwd=root
|
||||
database_pwd=root
|
||||
|
||||
@@ -55,6 +55,9 @@ EOT
|
||||
Mind::write('currentProjectRequiredTip');
|
||||
return false;
|
||||
}
|
||||
|
||||
Mind::$lexer= new Lexer();
|
||||
|
||||
$srcs= Mind::$currentProject['sources'];
|
||||
$main= file_get_contents($srcs.'/main.mnd');
|
||||
|
||||
@@ -62,7 +65,6 @@ EOT
|
||||
if(!Mind::$lexer->sweep($main))
|
||||
return false;
|
||||
// keep substantives and verbs on their canonical form
|
||||
// on male singular
|
||||
if(!Mind::$canonic->sweep())
|
||||
return false;
|
||||
// mark specific tokens
|
||||
@@ -73,9 +75,6 @@ EOT
|
||||
// itself
|
||||
if(!Mind::$syntaxer->sweep())
|
||||
return false;
|
||||
// removes the tokens, added before
|
||||
//if(!Mind::tokenizer::clear($main))
|
||||
return false;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
+5
-71
@@ -6,23 +6,8 @@
|
||||
* and also some permissions, starting some environmental
|
||||
* variables, such as language for localization
|
||||
*/
|
||||
session_start();
|
||||
define('_CONSOLE_LINE_LENGTH_', 80);
|
||||
require(_MINDSRC_.'/mind3rd/API/classes/Mind.php');
|
||||
require(_MINDSRC_.'/mind3rd/API/utils/header.php');
|
||||
|
||||
if(!Mind::isInstalled())
|
||||
{
|
||||
include(_MINDSRC_.'/wizard/installation-1.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once(_MINDSRC_.'/mind3rd/API/external/Symfony/Component/Console/Shell.php');
|
||||
require_once(_MINDSRC_.'/mind3rd/API/external/Symfony/Component/Console/Application.php');
|
||||
require_once(_MINDSRC_.'/mind3rd/API/external/Symfony/Component/Console/Command/Command.php');
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
|
||||
$app= new Symfony\Component\Console\Application('mind');
|
||||
$app->addCommands(Array(
|
||||
new RunTest(),
|
||||
@@ -36,16 +21,18 @@
|
||||
new SetUse()
|
||||
));
|
||||
|
||||
// setting the general helperSet
|
||||
$helperSet= false;
|
||||
$helperSet = ($helperSet) ?: new Symfony\Component\Console\Helper\HelperSet();
|
||||
$helperSet= ($helperSet) ?: new Symfony\Component\Console\Helper\HelperSet();
|
||||
$app->setHelperSet($helperSet);
|
||||
|
||||
|
||||
if(isset($_SERVER['argv']))
|
||||
{
|
||||
$params= $_SERVER['argv'];
|
||||
array_shift($params);
|
||||
}
|
||||
|
||||
// Instantiating the main Mind class
|
||||
$_MIND= new Mind();
|
||||
|
||||
/* let's load the plugins, if they are allowed */
|
||||
@@ -64,60 +51,7 @@
|
||||
}
|
||||
$d->close();
|
||||
}
|
||||
|
||||
Mind::$lexer= new Lexer();
|
||||
|
||||
function __autoload($what)
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
$what= preg_replace("/[ '\"\.\/]/", '', $what);
|
||||
|
||||
if(file_exists(_MINDSRC_.'/mind3rd/API/programs/'.$what.'.php'))
|
||||
{
|
||||
include(_MINDSRC_.'/mind3rd/API/programs/'.$what.'.php');
|
||||
return true;
|
||||
}
|
||||
if(strpos($what, '\\')>=0)
|
||||
{
|
||||
$what= explode('\\', $what);
|
||||
$what= array_pop($what);
|
||||
}
|
||||
$dirs= Array(
|
||||
_MINDSRC_.'/mind3rd/API/external/Symfony/Component/Console/Input/',
|
||||
_MINDSRC_.'/mind3rd/API/external/Symfony/Component/Console/Output/',
|
||||
_MINDSRC_.'/mind3rd/API/external/Symfony/Component/Console/Command/',
|
||||
_MINDSRC_.'/mind3rd/API/external/Symfony/Component/Console/Helper/',
|
||||
_MINDSRC_.'/mind3rd/API/cortex/Lexer/',
|
||||
_MINDSRC_.'/mind3rd/API/interfaces/',
|
||||
_MINDSRC_.'/mind3rd/API/programs/',
|
||||
_MINDSRC_.'/mind3rd/API/L10N/',
|
||||
_MINDSRC_.'/mind3rd/API/classes/',
|
||||
_MINDSRC_.'/mind3rd/API/cortex/tokenizer/',
|
||||
_MINDSRC_.'/mind3rd/API/cortex/canonic/',
|
||||
_MINDSRC_.'/mind3rd/API/cortex/syntaxer/'
|
||||
);
|
||||
for($i=0; $i<sizeof($dirs); $i++)
|
||||
{
|
||||
if(file_exists($dirs[$i].$what.'.php'))
|
||||
{
|
||||
require_once($dirs[$i].$what.'.php');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// let's check if it is a language
|
||||
$langPath= _MINDSRC_.'/mind3rd/API/languages/'.$_MIND->defaults['default_human_languageName'].'/'.$what.'.php';
|
||||
if(file_exists($langPath))
|
||||
{
|
||||
require_once($langPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
echo " [ERROR] Class not found: ".$what."\n";
|
||||
exit;
|
||||
return false;
|
||||
}
|
||||
|
||||
if($_REQ['env']=='shell')
|
||||
include('shell.php');
|
||||
else
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
require_once(_MINDSRC_.'/mind3rd/API/external/Symfony/Component/Console/Shell.php');
|
||||
require_once(_MINDSRC_.'/mind3rd/API/external/Symfony/Component/Console/Application.php');
|
||||
require_once(_MINDSRC_.'/mind3rd/API/external/Symfony/Component/Console/Command/Command.php');
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
session_start();
|
||||
define('_CONSOLE_LINE_LENGTH_', 80);
|
||||
require(_MINDSRC_.'/mind3rd/API/classes/Mind.php');
|
||||
|
||||
if(!Mind::isInstalled())
|
||||
{
|
||||
//include(_MINDSRC_.'/wizard/installation-1.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
function __autoload($what)
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
$what= preg_replace("/[ '\"\.\/]/", '', $what);
|
||||
$what= str_replace('\\', '/', $what);
|
||||
|
||||
if(file_exists(_MINDSRC_.'/mind3rd/API/programs/'.$what.'.php'))
|
||||
{
|
||||
include(_MINDSRC_.'/mind3rd/API/programs/'.$what.'.php');
|
||||
return true;
|
||||
}
|
||||
if(strpos($what, '\\')>=0)
|
||||
{
|
||||
$what= explode('\\', $what);
|
||||
$what= array_pop($what);
|
||||
}
|
||||
$dirs= Array(
|
||||
_MINDSRC_.'/mind3rd/API/external/',
|
||||
_MINDSRC_.'/mind3rd/API/cortex/Lexer/',
|
||||
_MINDSRC_.'/mind3rd/API/interfaces/',
|
||||
_MINDSRC_.'/mind3rd/API/programs/',
|
||||
_MINDSRC_.'/mind3rd/API/L10N/',
|
||||
_MINDSRC_.'/mind3rd/API/classes/',
|
||||
_MINDSRC_.'/mind3rd/API/cortex/tokenizer/',
|
||||
_MINDSRC_.'/mind3rd/API/cortex/canonic/',
|
||||
_MINDSRC_.'/mind3rd/API/cortex/syntaxer/',
|
||||
_MINDSRC_.'/mind3rd/API/cortex/analyst/',
|
||||
_MINDSRC_.'/mind3rd/API/languages/'
|
||||
);
|
||||
for($i=0; $i<sizeof($dirs); $i++)
|
||||
{
|
||||
if(file_exists($dirs[$i].$what.'.php'))
|
||||
{
|
||||
require_once($dirs[$i].$what.'.php');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// let's check if it is a language
|
||||
$langPath= _MINDSRC_.'/mind3rd/API/languages/'.$_MIND->defaults['default_human_languageName'].'/'.$what.'.php';
|
||||
if(file_exists($langPath))
|
||||
{
|
||||
require_once($langPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
echo " [ERROR] Class not found: ".$what."\n";
|
||||
return false;
|
||||
}
|
||||
Arquivo binário não exibido.
externo
+2
-2
@@ -2,8 +2,8 @@
|
||||
; it should represent your preferences about how mind should behave
|
||||
;
|
||||
; the default idiom
|
||||
default_human_language=ptBR
|
||||
default_human_languageName=pt-BR
|
||||
default_human_language=pt
|
||||
default_human_languageName=pt
|
||||
; default timezone
|
||||
timezone=America/Sao_paulo
|
||||
; the default programming language
|
||||
|
||||
externo
+9
@@ -10,6 +10,9 @@ abstract class UnixSetup extends Setup{
|
||||
public static $header = '#!/usr/bin/env php';
|
||||
public static $content= '';
|
||||
|
||||
/**
|
||||
* Creates the mind file, at bin directory
|
||||
*/
|
||||
public function createExecFile()
|
||||
{
|
||||
self::$content= '<?php
|
||||
@@ -17,6 +20,7 @@ abstract class UnixSetup extends Setup{
|
||||
$_REQ["env"]= "shell";
|
||||
define("_MINDSRC_", "'.getcwd().'");
|
||||
require("'.getcwd().'/mind3rd/API/utils.php");';
|
||||
|
||||
echo " starting the installation...\n";
|
||||
echo " creating the file...\n";
|
||||
shell_exec("sudo touch /bin/mind");
|
||||
@@ -30,6 +34,11 @@ abstract class UnixSetup extends Setup{
|
||||
echo shell_exec("sudo chmod 777 /bin/mind");
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs the program to be used in command line
|
||||
* or http.
|
||||
* It uses an inherited method, createDatabase
|
||||
*/
|
||||
public function install(){
|
||||
self::createExecFile();
|
||||
self::createDatabase();
|
||||
|
||||
externo
+9
@@ -10,12 +10,21 @@ abstract class WinSetup extends Setup{
|
||||
public static $header = '';
|
||||
public static $content= '';
|
||||
|
||||
/**
|
||||
* *SHOULD* create the file to use the program throught
|
||||
* command line, on windows
|
||||
*/
|
||||
public function createExecFile()
|
||||
{
|
||||
self::$content= '';
|
||||
// TODO: any good soul to help with it?
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs the program to be used in command line
|
||||
* or http.
|
||||
* It uses an inherited method, createDatabase
|
||||
*/
|
||||
public function install(){
|
||||
self::createExecFile();
|
||||
self::createDatabase();
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
; to use in your application
|
||||
;
|
||||
; The idiom is the human language you want to use
|
||||
idiom=pt-br
|
||||
idiom=pt
|
||||
; The technology you specify here, will be used as
|
||||
; the backend of your application
|
||||
; this will be the name of the model you want to apply
|
||||
@@ -24,4 +24,4 @@ database_addr=localhost
|
||||
database_port=5432
|
||||
; and here, the user and password
|
||||
database_user=root
|
||||
dataase_pwd=root
|
||||
database_pwd=root
|
||||
Referência em uma Nova Issue
Bloquear um usuário