I18N_Arabic
[ class tree: I18N_Arabic ] [ index: I18N_Arabic ] [ all elements ]

Source for file Gender.php

Documentation is available at Gender.php

  1. <?php
  2. /**
  3.  * ----------------------------------------------------------------------
  4.  *  
  5.  * Copyright (c) 2006-2013 Khaled Al-Sham'aa.
  6.  *  
  7.  * http://www.ar-php.org
  8.  *  
  9.  * PHP Version 5
  10.  *  
  11.  * ----------------------------------------------------------------------
  12.  *  
  13.  * LICENSE
  14.  *
  15.  * This program is open source product; you can redistribute it and/or
  16.  * modify it under the terms of the GNU Lesser General Public License (LGPL)
  17.  * as published by the Free Software Foundation; either version 3
  18.  * of the License, or (at your option) any later version.
  19.  *  
  20.  * This program is distributed in the hope that it will be useful,
  21.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23.  * GNU Lesser General Public License for more details.
  24.  *  
  25.  * You should have received a copy of the GNU Lesser General Public License
  26.  * along with this program.  If not, see <http://www.gnu.org/licenses/lgpl.txt>.
  27.  *  
  28.  * ----------------------------------------------------------------------
  29.  *  
  30.  * Class Name: Arabic Gender Guesser
  31.  *  
  32.  * Filename:   Gender.php
  33.  *  
  34.  * Original    Author(s): Khaled Al-Sham'aa <khaled@ar-php.org>
  35.  *  
  36.  * Purpose:    This class attempts to guess the gender of Arabic names
  37.  *  
  38.  * ----------------------------------------------------------------------
  39.  *
  40.  * Arabic Gender Guesser
  41.  *
  42.  * This PHP class attempts to guess the gender of Arabic names.
  43.  * 
  44.  * Arabic nouns are either masculine or feminine. Usually when referring to a male,
  45.  * a masculine noun is usually used and when referring to a female, a feminine noun
  46.  * is used. In most cases the feminine noun is formed by adding a special characters
  47.  * to the end of the masculine noun. Its not just nouns referring to people that
  48.  * have gender. Inanimate objects (doors, houses, cars, etc.) is either masculine or
  49.  * feminine. Whether an inanimate noun is masculine or feminine is mostly
  50.  * arbitrary.
  51.  * 
  52.  * Example:
  53.  * <code>
  54.  *   include('./I18N/Arabic.php');
  55.  *   $obj = new I18N_Arabic('Gender');
  56.  *      
  57.  *   echo "$name ";
  58.  * 
  59.  *   if ($obj->isFemale($name) == true) {
  60.  *      echo '(Female)';
  61.  *   }else{
  62.  *      echo '(Male)';
  63.  *   }
  64.  * </code>
  65.  *             
  66.  * @category  I18N
  67.  * @package   I18N_Arabic
  68.  * @author    Khaled Al-Sham'aa <khaled@ar-php.org>
  69.  * @copyright 2006-2013 Khaled Al-Sham'aa
  70.  *    
  71.  * @license   LGPL <http://www.gnu.org/licenses/lgpl.txt>
  72.  * @link      http://www.ar-php.org
  73.  */
  74.  
  75. // New in PHP V5.3: Namespaces
  76. // namespace I18N\Arabic;
  77. // 
  78. // $obj = new I18N\Arabic\Gender();
  79. // 
  80. // use I18N\Arabic;
  81. // $obj = new Arabic\Gender();
  82. //
  83. // use I18N\Arabic\Gender as Gender;
  84. // $obj = new Gender();
  85.  
  86. /**
  87.  * This PHP class attempts to guess the gender of Arabic names
  88.  *  
  89.  * @category  I18N
  90.  * @package   I18N_Arabic
  91.  * @author    Khaled Al-Sham'aa <khaled@ar-php.org>
  92.  * @copyright 2006-2013 Khaled Al-Sham'aa
  93.  *    
  94.  * @license   LGPL <http://www.gnu.org/licenses/lgpl.txt>
  95.  * @link      http://www.ar-php.org
  96.  */ 
  97. {
  98.     /**
  99.      * Loads initialize values
  100.      *
  101.      * @ignore
  102.      */         
  103.     public function __construct()
  104.     {
  105.     }
  106.  
  107.     /**
  108.      * Check if Arabic word is feminine
  109.      *          
  110.      * @param string $str Arabic word you would like to check if it is
  111.      *                     feminine
  112.      *                    
  113.      * @return boolean Return true if input Arabic word is feminine
  114.      * @author Khaled Al-Sham'aa <khaled@ar-php.org>
  115.      */
  116.     public static function isFemale($str)
  117.     {
  118.         $female false;
  119.         
  120.         $words explode(' '$str);
  121.         $str   $words[0];
  122.  
  123.         $str str_replace(array('أ','إ','آ')'ا'$str);
  124.  
  125.         $last       mb_substr($str-11'UTF-8');
  126.         $beforeLast mb_substr($str-21'UTF-8');
  127.  
  128.         if ($last == 'ة' || $last == 'ه' || $last == 'ى' || $last == 'ا' 
  129.             || ($last == 'ء' && $beforeLast == 'ا')
  130.         {
  131.  
  132.             $female true;
  133.         elseif (preg_match("/^[اإ].{2}ا.$/u"$str
  134.             || preg_match("/^[إا].ت.ا.+$/u"$str)
  135.         {
  136.             // الأسماء على وزن إفتعال و إفعال
  137.             $female true;
  138.         else {
  139.             // List of the most common irregular Arabic female names
  140.             $names file(dirname(__FILE__).'/data/female.txt');
  141.             $names array_map('trim'$names);
  142.  
  143.             if (array_search($str$names0{
  144.                 $female true;
  145.             }
  146.         }
  147.  
  148.         return $female;
  149.     }
  150. }

Documentation generated on Mon, 14 Jan 2013 17:48:44 +0100 by phpDocumentor 1.4.0