updates to the Inflection class in pt-BR;

added tests to class inflaction pt-Br
Esse commit está contido em:
Felipe
2010-11-07 00:55:03 -02:00
commit 8e6b2b6d34
87 arquivos alterados com 280 adições e 1297 exclusões
@@ -0,0 +1,106 @@
<?php
require_once dirname(__FILE__) . '/../../../../../mind3rd/API/languages/pt-BR/Inflect.php';
/**
* Test class for Inflect.
* Generated by PHPUnit on 2010-11-06 at 23:55:39.
*/
class InflectTest extends PHPUnit_Framework_TestCase {
/**
* @var Inflect
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp() {
$this->object = new Inflect;
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown() {
}
public function testIs_singular() {
$this->assertTrue(Inflect::is_singular('homem'));
$this->assertFalse(Inflect::is_singular('homens'));
$this->assertFalse(Inflect::is_singular('caminhões'));
$this->assertTrue(Inflect::is_singular('caminhão'));
$this->assertFalse(Inflect::is_singular('pães'));
$this->assertTrue(Inflect::is_singular('pão'));
$this->assertFalse(Inflect::is_singular('carros'));
$this->assertTrue(Inflect::is_singular('atlas'));
}
public function testToPlural() {
$this->assertEquals(Inflect::toPlural('homem'), 'homens');
$this->assertEquals(Inflect::toPlural('caminhão'), 'caminhões');
$this->assertEquals(Inflect::toPlural('pão'), 'pães');
$this->assertEquals(Inflect::toPlural('carro'), 'carros');
$this->assertEquals(Inflect::toPlural('átlas'), 'átlas');
$this->assertEquals(Inflect::toPlural('óculos'), 'óculos');
$this->assertEquals(Inflect::toPlural('peão'), 'peões');
$this->assertEquals(Inflect::toPlural('aluna'), 'alunas');
}
public function testToSingular() {
$this->assertEquals(Inflect::toSingular('homens'), 'homem');
$this->assertEquals(Inflect::toSingular('caminhões'), 'caminhão');
$this->assertEquals(Inflect::toSingular('pães'), 'pão');
$this->assertEquals(Inflect::toSingular('carros'), 'carro');
$this->assertEquals(Inflect::toSingular('átlas'), 'átlas');
$this->assertEquals(Inflect::toSingular('óculos'), 'óculos');
$this->assertEquals(Inflect::toSingular('peões'), 'peão');
$this->assertEquals(Inflect::toSingular('alunas'), 'aluna');
}
public function testToFemale() {
$this->assertEquals(Inflect::toFemale('aluno'), 'aluna');
$this->assertEquals(Inflect::toFemale('réu'), 'ré');
$this->assertEquals(Inflect::toFemale('gato'), 'gata');
$this->assertEquals(Inflect::toFemale('leão'), 'leoa');
$this->assertEquals(Inflect::toFemale('chorão'), 'chorona');
$this->assertEquals(Inflect::toFemale('mestre'), 'mestra');
$this->assertEquals(Inflect::toFemale('doutor'), 'doutora');
}
/**
* @todo Implement testToMale().
*/
public function testToMale() {
$this->assertEquals(Inflect::toMale('aluna'), 'aluno');
$this->assertEquals(Inflect::toMale('ré'), 'réu');
$this->assertEquals(Inflect::toMale('gata'), 'gato');
$this->assertEquals(Inflect::toMale('leoa'), 'leão');
$this->assertEquals(Inflect::toMale('chorona'), 'chorão');
$this->assertEquals(Inflect::toMale('mestra'), 'mestre');
$this->assertEquals(Inflect::toMale('doutora'), 'doutor');
}
/**
* @todo Implement testIsFemale().
*/
public function testIsFemale() {
$this->assertTrue(Inflect::isFemale('mulher'));
$this->assertTrue(Inflect::isFemale('freira'));
$this->assertTrue(Inflect::isFemale('casa'));
$this->assertTrue(Inflect::isFemale('ré'));
$this->assertFalse(Inflect::isFemale('réu'));
$this->assertTrue(Inflect::isFemale('amorosa'));
$this->assertFalse(Inflect::isFemale('campeão'));
$this->assertFalse(Inflect::isFemale('chapél'));
$this->assertTrue(Inflect::isFemale('chorona'));
$this->assertTrue(Inflect::isFemale('pequenininha'));
}
}
?>
Arquivo executável → Arquivo normal
Ver Arquivo
+1 -1
Ver Arquivo
@@ -24,7 +24,7 @@ class ptBR {
}
public function __construct()
{
header('Content-type: text/html; charset=iso-8859-1');
//header('Content-type: text/html; charset=iso-8859-1');
$this->messages['programRequired'] = Mind::message("API: You must send the program name, to execute", '[Fail]', false);
$this->messages['loginRequired'] = Mind::message("Auth: Both login and password are required", '[Fail]', false);
$this->messages['passwordRequired'] = "I need a password for this user, please: ";
Arquivo executável → Arquivo normal
+3
Ver Arquivo
@@ -19,7 +19,10 @@
public static $triggers= Array();
public static $modelsDir= "";
public static $lexer;
public static $canonic;
public static $tokenizer;
public static $langPath= "";
public static $content= "";
/**
* This method returns or outputs messages using the L10N library
Arquivo executável → Arquivo normal
Ver Arquivo
+8 -2
Ver Arquivo
@@ -96,8 +96,9 @@ class Lexer
$fixed= str_replace($char, $token, $fixed);
}
$fixed= preg_replace("/\n/", $this->tokens[' '], $fixed);
$fixed= explode($this->tokens[' '], $fixed);
print_r($fixed);
$fixed= array_filter(explode($this->tokens[' '], $fixed));
Mind::$content= $fixed;
return sizeof(Mind::$content)>0? Mind::$content: false;
}
public function translateChars($str)
@@ -112,6 +113,7 @@ class Lexer
GLOBAL $_MIND;
$this->lang= Mind::$l10n->name;
$xml= simplexml_load_file(Mind::$langPath.$this->lang.'/lexics.xml');
include(Mind::$langPath.$this->lang.'/Inflect.php');
$this->validChars= (string)$xml->validchars->lower;
$this->validChars.= (string)$xml->validchars->upper;
$this->validChars.= (string)$xml->validchars->special;
@@ -124,6 +126,10 @@ class Lexer
$this->replacements[1]= (string)$xml->replacements->to;
$this->tokens[' ']= chr('176');
$this->tokens['.']= chr('176').'.'.chr('176');
// prepare it to the next step
Mind::$canonic= new Canonic();
}
}
?>
+38
Ver Arquivo
@@ -0,0 +1,38 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of Canonic
*
* @author felipe
*/
class Canonic extends Inflect{
public static function canonize($word)
{
if(!self::is_singular($word))
$word= self::toSingular($word);
if(self::isFemale($word))
$word= self::toMale($word);
echo $word."<br>";
}
public function sweep(Array $content)
{
array_map(function ($word)
{
Canonic::canonize($word);
},
$content);
print_r($content);
}
public function __construct()
{
}
}
?>
-188
Ver Arquivo
@@ -1,188 +0,0 @@
<?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
// Changes:
// Removed rule for virus -> viri
// Added rule for potato -> potatoes
// Added rule for *us -> *uses
class Inflect
{
static $plural = array(
'/(quiz)$/i' => "$1zes",
'/^(ox)$/i' => "$1en",
'/([m|l])ouse$/i' => "$1ice",
'/(matr|vert|ind)ix|ex$/i' => "$1ices",
'/(x|ch|ss|sh)$/i' => "$1es",
'/([^aeiouy]|qu)y$/i' => "$1ies",
'/(hive)$/i' => "$1s",
'/(?:([^f])fe|([lr])f)$/i' => "$1$2ves",
'/(shea|lea|loa|thie)f$/i' => "$1ves",
'/sis$/i' => "ses",
'/([ti])um$/i' => "$1a",
'/(tomat|potat|ech|her|vet)o$/i'=> "$1oes",
'/(bu)s$/i' => "$1ses",
'/(alias)$/i' => "$1es",
'/(octop)us$/i' => "$1i",
'/(ax|test)is$/i' => "$1es",
'/(us)$/i' => "$1es",
'/s$/i' => "s"
// '/$/' => "s"
);
static $singular = array(
'/(quiz)zes$/i' => "$1",
'/(matr)ices$/i' => "$1ix",
'/(vert|ind)ices$/i' => "$1ex",
'/^(ox)en$/i' => "$1",
'/(alias)es$/i' => "$1",
'/(octop|vir)i$/i' => "$1us",
'/(cris|ax|test)es$/i' => "$1is",
'/(shoe)s$/i' => "$1",
'/(o)es$/i' => "$1",
'/(bus)es$/i' => "$1",
'/([m|l])ice$/i' => "$1ouse",
'/(x|ch|ss|sh)es$/i' => "$1",
'/(m)ovies$/i' => "$1ovie",
'/(s)eries$/i' => "$1eries",
'/([^aeiouy]|qu)ies$/i' => "$1y",
'/([lr])ves$/i' => "$1f",
'/(tive)s$/i' => "$1",
'/(hive)s$/i' => "$1",
'/(li|wi|kni)ves$/i' => "$1fe",
'/(shea|loa|lea|thie)ves$/i'=> "$1f",
'/(^analy)ses$/i' => "$1sis",
'/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => "$1$2sis",
'/([ti])a$/i' => "$1um",
'/(n)ews$/i' => "$1ews",
'/(h|bl)ouses$/i' => "$1ouse",
'/(corpse)s$/i' => "$1",
'/(us)es$/i' => "$1",
'/s$/i' => ""
);
static $irregular = array(
'move' => 'moves',
'foot' => 'feet',
'goose' => 'geese',
'sex' => 'sexes',
'child' => 'children',
'man' => 'men',
'tooth' => 'teeth',
'person' => 'people'
);
static $uncountable = array(
'sheep',
'fish',
'deer',
'series',
'species',
'money',
'rice',
'information',
'equipment'
);
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 pluralize( $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 $string;
}
public static function singularize( $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 pluralize_if($count, $string)
{
if ($count == 1)
return "1 $string";
else
return $count . " " . self::pluralize($string);
}
}
-190
Ver Arquivo
@@ -1,190 +0,0 @@
<?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
class Inflect
{
static $plural = array(
'/(quiz)$/i' => "$1zes",
'/^(ox)$/i' => "$1en",
'/([m|l])ouse$/i' => "$1ice",
'/(matr|vert|ind)ix|ex$/i' => "$1ices",
'/(x|ch|ss|sh)$/i' => "$1es",
'/([^aeiouy]|qu)y$/i' => "$1ies",
'/(hive)$/i' => "$1s",
'/(?:([^f])fe|([lr])f)$/i' => "$1$2ves",
'/(shea|lea|loa|thie)f$/i' => "$1ves",
'/sis$/i' => "ses",
'/([ti])um$/i' => "$1a",
'/(tomat|potat|ech|her|vet)o$/i'=> "$1oes",
'/(bu)s$/i' => "$1ses",
'/(alias)$/i' => "$1es",
'/(octop)us$/i' => "$1i",
'/(ax|test)is$/i' => "$1es",
'/(us)$/i' => "$1es",
'/s$/i' => "s"
);
static $singular = array(
'/(quiz)zes$/i' => "$1",
'/(matr)ices$/i' => "$1ix",
'/(vert|ind)ices$/i' => "$1ex",
'/^(ox)en$/i' => "$1",
'/(alias)es$/i' => "$1",
'/(octop|vir)i$/i' => "$1us",
'/(cris|ax|test)es$/i' => "$1is",
'/(shoe)s$/i' => "$1",
'/(o)es$/i' => "$1",
'/(bus)es$/i' => "$1",
'/([m|l])ice$/i' => "$1ouse",
'/(x|ch|ss|sh)es$/i' => "$1",
'/(m)ovies$/i' => "$1ovie",
'/(s)eries$/i' => "$1eries",
'/([^aeiouy]|qu)ies$/i' => "$1y",
'/([lr])ves$/i' => "$1f",
'/(tive)s$/i' => "$1",
'/(hive)s$/i' => "$1",
'/(li|wi|kni)ves$/i' => "$1fe",
'/(shea|loa|lea|thie)ves$/i'=> "$1f",
'/(^analy)ses$/i' => "$1sis",
'/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => "$1$2sis",
'/([ti])a$/i' => "$1um",
'/(n)ews$/i' => "$1ews",
'/(h|bl)ouses$/i' => "$1ouse",
'/(corpse)s$/i' => "$1",
'/(us)es$/i' => "$1",
'/s$/i' => ""
);
static $irregular = array(
'move' => 'moves',
'foot' => 'feet',
'goose' => 'geese',
'sex' => 'sexes',
'child' => 'children',
'man' => 'men',
'tooth' => 'teeth',
'person' => 'people'
);
static $uncountable = array(
'sheep',
'fish',
'deer',
'series',
'species',
'money',
'rice',
'information',
'equipment'
);
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 pluralize( $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 singularize( $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 pluralize_if($count, $string)
{
if ($count == 1)
return "1 $string";
else
return $count . " " . self::pluralize($string);
}
}
-190
Ver Arquivo
@@ -1,190 +0,0 @@
<?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
class Inflect
{
static $plural = array(
'/(quiz)$/i' => "$1zes",
'/^(ox)$/i' => "$1en",
'/([m|l])ouse$/i' => "$1ice",
'/(matr|vert|ind)ix|ex$/i' => "$1ices",
'/(x|ch|ss|sh)$/i' => "$1es",
'/([^aeiouy]|qu)y$/i' => "$1ies",
'/(hive)$/i' => "$1s",
'/(?:([^f])fe|([lr])f)$/i' => "$1$2ves",
'/(shea|lea|loa|thie)f$/i' => "$1ves",
'/sis$/i' => "ses",
'/([ti])um$/i' => "$1a",
'/(tomat|potat|ech|her|vet)o$/i'=> "$1oes",
'/(bu)s$/i' => "$1ses",
'/(alias)$/i' => "$1es",
'/(octop)us$/i' => "$1i",
'/(ax|test)is$/i' => "$1es",
'/(us)$/i' => "$1es",
'/s$/i' => "s"
);
static $singular = array(
'/(quiz)zes$/i' => "$1",
'/(matr)ices$/i' => "$1ix",
'/(vert|ind)ices$/i' => "$1ex",
'/^(ox)en$/i' => "$1",
'/(alias)es$/i' => "$1",
'/(octop|vir)i$/i' => "$1us",
'/(cris|ax|test)es$/i' => "$1is",
'/(shoe)s$/i' => "$1",
'/(o)es$/i' => "$1",
'/(bus)es$/i' => "$1",
'/([m|l])ice$/i' => "$1ouse",
'/(x|ch|ss|sh)es$/i' => "$1",
'/(m)ovies$/i' => "$1ovie",
'/(s)eries$/i' => "$1eries",
'/([^aeiouy]|qu)ies$/i' => "$1y",
'/([lr])ves$/i' => "$1f",
'/(tive)s$/i' => "$1",
'/(hive)s$/i' => "$1",
'/(li|wi|kni)ves$/i' => "$1fe",
'/(shea|loa|lea|thie)ves$/i'=> "$1f",
'/(^analy)ses$/i' => "$1sis",
'/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => "$1$2sis",
'/([ti])a$/i' => "$1um",
'/(n)ews$/i' => "$1ews",
'/(h|bl)ouses$/i' => "$1ouse",
'/(corpse)s$/i' => "$1",
'/(us)es$/i' => "$1",
'/s$/i' => ""
);
static $irregular = array(
'move' => 'moves',
'foot' => 'feet',
'goose' => 'geese',
'sex' => 'sexes',
'child' => 'children',
'man' => 'men',
'tooth' => 'teeth',
'person' => 'people'
);
static $uncountable = array(
'sheep',
'fish',
'deer',
'series',
'species',
'money',
'rice',
'information',
'equipment'
);
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 pluralize( $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 singularize( $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 pluralize_if($count, $string)
{
if ($count == 1)
return "1 $string";
else
return $count . " " . self::pluralize($string);
}
}
-76
Ver Arquivo
@@ -1,76 +0,0 @@
<?php
header('Content-type: text/html; charset=utf-8');
$lang= 'pt-BR';
if($lang=='en')
{
include('en/Inflect.php');
echo Inflect::toPlural("truck");
echo "<br/>";
echo Inflect::toPlural("lady");
echo "<br/>";
echo Inflect::toPlural("shit");
echo "<br/>";
echo Inflect::toPlural("program");
echo "<br/>";
echo (Inflect::is_singular("fish")? 1:0)."<br/>";
echo (Inflect::is_singular("rice")? 1:0)."<br/>";
echo (Inflect::is_singular("foot")? 1:0)."<br/>";
echo (Inflect::is_singular("feet")? 1:0)."<br/>";
echo (Inflect::is_singular("truck")? 1:0)."<br/>";
echo (Inflect::is_singular("trucks")? 1:0)."<br/>";
echo (Inflect::is_singular("house")? 1:0)."<br/>";
echo (Inflect::is_singular("houses")? 1:0)."<br/>";
}
else
{
include('pt-BR/Inflect.php');
echo Inflect::toSingular('gatos').' -> '.Inflect::toPlural("gato")."<br/>";
echo Inflect::toSingular('itens').' -> '.Inflect::toPlural("item")."<br/>";
echo Inflect::toSingular('álbuns').' -> '.Inflect::toPlural("álbum")."<br/>";
echo Inflect::toSingular('aldeões').' -> '.Inflect::toPlural("aldeão")."<br/>";
echo Inflect::toSingular('alemães').' -> '.Inflect::toPlural("alemão")."<br/>";
echo Inflect::toSingular('irmãos').' -> '.Inflect::toPlural("irmão")."<br/>";
echo Inflect::toSingular('irmãs').' -> '.Inflect::toPlural("irmã")."<br/>";
echo Inflect::toSingular('colheres').' -> '.Inflect::toPlural("colher")."<br/>";
echo Inflect::toSingular('albatroses').' -> '.Inflect::toPlural("albatroz")."<br/>";
echo Inflect::toSingular('fregueses').' -> '.Inflect::toPlural("fregues")."<br/>";
echo Inflect::toSingular('freguesas').' -> '.Inflect::toPlural("freguesa")."<br/>";
echo Inflect::toSingular('clímax').' -> '.Inflect::toPlural("clímax")."<br/>";
echo Inflect::toSingular('varais').' -> '.Inflect::toPlural("varal")."<br/>";
echo Inflect::toSingular('túneis').' -> '.Inflect::toPlural("túnel")."<br/>";
echo Inflect::toSingular('barris').' -> '.Inflect::toPlural("barril")."<br/>";
echo Inflect::toSingular('fásseis').' -> '.Inflect::toPlural("fóssil")."<br/>";
echo Inflect::toSingular('projéteis').' -> '.Inflect::toPlural("projétil")."<br/>";
echo Inflect::toSingular('bares').' -> '.Inflect::toPlural("bar")."<br/>";
echo "<hr/>";
echo Inflect::toFemale('gato').' -> '.Inflect::toMale("gata")."<br/>";
echo Inflect::toFemale('leão').' -> '.Inflect::toMale("leoa")."<br/>";
echo Inflect::toFemale('chorão').' -> '.Inflect::toMale("chorona")."<br/>";
echo Inflect::toFemale('mijão').' -> '.Inflect::toMale("mijona")."<br/>";
echo Inflect::toFemale('doutor').' -> '.Inflect::toMale("doutora")."<br/>";
echo Inflect::toFemale('mestre').' -> '.Inflect::toMale("mestra")."<br/>";
echo Inflect::toFemale('réu').' -> '.Inflect::toMale("ré")."<br/>";
echo "<hr/>";
echo 'irmão -> '.(Inflect::isFemale('irmão')?1:0)."<br/>";
echo 'irmã -> '.(Inflect::isFemale('irmã')?1:0)."<br/>";
echo 'ré -> '.(Inflect::isFemale('ré')?1:0)."<br/>";
echo 'réu -> '.(Inflect::isFemale('réu')?1:0)."<br/>";
echo 'carro -> '.(Inflect::isFemale('carro')?1:0)."<br/>";
echo 'casa -> '.(Inflect::isFemale('casa')?1:0)."<br/>";
echo 'mulher -> '.(Inflect::isFemale('mulher')?1:0)."<br/>";
echo 'homem -> '.(Inflect::isFemale('homem')?1:0)."<br/>";
echo 'carro -> '.(Inflect::isFemale('carro')?1:0)."<br/>";
}
@@ -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;
}
}
@@ -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;
}
}
externo Arquivo executável → Arquivo normal
Ver Arquivo
externo Arquivo executável → Arquivo normal
Ver Arquivo
externo Arquivo executável → Arquivo normal
Ver Arquivo
Ver Arquivo
Ver Arquivo
Ver Arquivo
Ver Arquivo
externo Arquivo executável → Arquivo normal
Ver Arquivo
Ver Arquivo
externo Arquivo executável → Arquivo normal
Ver Arquivo
externo Arquivo executável → Arquivo normal
Ver Arquivo
externo Arquivo executável → Arquivo normal
Ver Arquivo
externo Arquivo executável → Arquivo normal
Ver Arquivo
externo Arquivo executável → Arquivo normal
Ver Arquivo
Ver Arquivo
Ver Arquivo
Ver Arquivo
externo Arquivo executável → Arquivo normal
Ver Arquivo
externo Arquivo executável → Arquivo normal
Ver Arquivo
Ver Arquivo
externo Arquivo executável → Arquivo normal
Ver Arquivo
externo Arquivo executável → Arquivo normal
Ver Arquivo
Ver Arquivo
Ver Arquivo
externo Arquivo executável → Arquivo normal
Ver Arquivo
externo Arquivo executável → Arquivo normal
Ver Arquivo
Ver Arquivo
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
+118 -96
Ver Arquivo
@@ -1,83 +1,87 @@
<?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
/*
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:
Felip 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 :)
*/
/**
* 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>
*/
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"
'/^a$/i' => "a",
'/^ao$/i' => "aos",
'/^o$/i' => "os",
'/(.+[aeiouãõéíóúâôênh])ão$/i' => "$1ões",
'/(.+[aeiou][a-z])ão$/i' => "$1ães",
'/([cp])ão$/i' => "$1ães",
'/(.+[rs])$/i' => "$1es",
'/(.+[aeou])l$/i' => "$1is",
'/(.+[áéíóúâô][a-z]{1,2})il$/i' => "$1eis",
'/(.+i)l$/i' => "$1s",
'/(.+)z$/i' => "$1ses",
'/(.+)m$/i' => "$1ns",
'/([aeiou])$/i' => "$1s",
'/(.+x)$/i' => "$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"
'/^aos$/i' => "ao",
'/^os$/i' => "o",
'/(.+)ões$/i' => "$1ão",
'/([aeiouãõéíóúâôêpnh])ães$/i' => "$1ão",
'/([cph])ães$/i' => "$1ão",
'/(.+[a-z])ães$/i' => "$1ão",
'/(.+[aeiouãõéíóúâôê][a-z])ães$/i' => "$1ão",
'/(.+r)es$/i' => "$1",
'/(.+)ses$/i' => "$1z",
'/(.+s)es$/i' => "$1",
'/(.+[aeou])is$/i' => "$1l",
'/(.+[áéíóúâô][a-z]{1,2})eis$/i' => "$1il",
'/(.+i)s$/i' => "$1l",
'/(.+)ns$/i' => "$1m",
'/([aeiouãõéíóúâôê])s$/i' => "$1",
'/(.+x)$/i' => "$1"
);
static $female= Array(
'/([aeiou][a-z]{1,2})ão$/' => "$1ona",
'/([aeiou])ão$/' => "$1oa",
'/o$/' => "a",
'/e$/' => "a",
'/or$/' => "ora",
'/om$/' => "oa",
'/m$/' => "m"
'/([aeiouãõéíóúâôê][a-z]{1,2})ão$/i' => "$1ona",
'/([aeiouãõéíóúâôê])ão$/i' => "$1oa",
'/o$/i' => "a",
'/e$/i' => "a",
'/or$/i' => "ora",
'/om$/i' => "oa",
'/m$/i' => "m",
'/l$/i' => "l"
);
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"
'/([aeiouãõéíóúâôê][a-z]{1,2})ona$/i' => "$1ão",
'/([aeiouãõéíóúâôê])oa$/i' => "$1ão",
'/ora$/i' => "or",
'/([aeiouãõéíóúâôê][a-z]{1,2})a$/i' => "$1o",
'/a$/i' => "e"
);
static $genreSpecific= Array(
'ele' => 'ela',
'eles' => 'elas',
'cônsul' => 'consulesa',
'visconde' => 'viscondessa',
'homem' => 'mulher',
@@ -103,12 +107,15 @@ class Inflect
);
static $irregular = array(
'move' => 'moves',
'freguês'=> 'fregueses'
);
static $uncountable = array(
'óculos',
'para',
'do',
'de',
'da',
'oculos',
'átlas',
'atlas',
@@ -119,7 +126,7 @@ class Inflect
'vírus',
'virus'
);
/**
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
* @method is_singular
@@ -140,7 +147,8 @@ class Inflect
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)
foreach(self::$singular as $pattern => $result)
{
if(preg_match( $pattern, $string))
{
@@ -150,6 +158,12 @@ class Inflect
return true;
}
/**
* 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
@@ -175,6 +189,13 @@ class Inflect
return $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
@@ -200,14 +221,13 @@ class Inflect
return $string;
}
public static function toPlural_if($count, $string)
{
if ($count == 1)
return "1 $string";
else
return $count . " " . self::toPlural($string);
}
/**
* Chenges the genre of a word to female
*
* @method toFemale
* @param String $string
* @return String
*/
public static function toFemale($string)
{
// first, we gotta see if it is a word with specific genre change
@@ -220,20 +240,20 @@ class Inflect
if(preg_match( $pattern, $string))
return preg_replace($pattern, $result, $string);
}
return $string;
}
/**
* Changes the genre of a word to male
*
* @method toMale
* @param String $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);
}
if($k= array_search($string, self::$genreSpecific))
return $k;
// check for matches using regular expressions
foreach(self::$male as $pattern => $result)
@@ -241,12 +261,22 @@ class Inflect
if(preg_match( $pattern, $string))
return preg_replace($pattern, $result, $string);
}
return $string;
}
/**
* Verifies whether the given word is female or not
*
* @method isFemale
* @param String $string
* @return String
*/
public static function isFemale($string)
{
// let's avoid any preposition
if(in_array($string, self::$uncountable))
return false;
// it is a female from the specific list
if(in_array($string, self::$genreSpecific))
return true;
@@ -263,12 +293,4 @@ class Inflect
}
return true;
}
}
}
+3 -1
Ver Arquivo
@@ -61,9 +61,11 @@ EOT
// search for special/unknown characters
if(!Mind::$lexer->sweep($main))
return false;
if(!Mind::$canonic->sweep(Mind::$content))
return false;
// mark specific tokens
//if(!Mind::tokenizer::sweep($main))
return false;
// return false;
// keep substantives and verbs on their canonical form
// on male singular, for example
//if(!Mind::canonic::sweep($main))
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
externo Arquivo executável → Arquivo normal
Ver Arquivo
externo Arquivo executável → Arquivo normal
Ver Arquivo
externo Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
+1 -4
Ver Arquivo
@@ -1,4 +1 @@
AéH*§x
Ç § =
asd
asdq
os
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
+1 -1
Ver Arquivo
@@ -1,5 +1,5 @@
copy.src.files=false
copy.src.target=/var/www/mind
index.file=mind
index.file=index.php
run.as=LOCAL
url=http://localhost/mind/
Arquivo executável → Arquivo normal
Ver Arquivo
Arquivo executável → Arquivo normal
+1
Ver Arquivo
@@ -4,4 +4,5 @@ source.encoding=UTF-8
src.dir=.
tags.asp=false
tags.short=true
test.src.dir=Tests
web.root=.
Arquivo executável → Arquivo normal
Ver Arquivo