Current file: D:\data\micmap\cgi-bin\dicfro\4.5\application\Model\Search\Jeanneau.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 1 / 1 CRAP
100.00%100.00%
100.00% 16 / 16
 
Model_Search_Jeanneau
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 16 / 16
 searchWord($word)
100.00%100.00%
100.00% 1 / 1 6
100.00%100.00%
100.00% 16 / 16


       1                 : <?php                                                                                                                         
       2                 :                                                                                                                               
       3                 : /**                                                                                                                           
       4                 :  * Dictionaries of Old French and Latin                                                                                       
       5                 :  *                                                                                                                            
       6                 :  * PHP 5                                                                                                                      
       7                 :  *                                                                                                                            
       8                 :  * @category   DicFro                                                                                                         
       9                 :  * @package    Model                                                                                                          
      10                 :  * @subpackage Search                                                                                                         
      11                 :  * @author     Michel Corne <mcorne@yahoo.com>                                                                                
      12                 :  * @copyright  2008-2010 Michel Corne                                                                                         
      13                 :  * @license    http://opensource.org/licenses/gpl-3.0.html GNU General Public License, version 3 (GPLv3)                      
      14                 :  * @link       http://www.micmap.org/dicfro                                                                                   
      15                 :  */                                                                                                                           
      16                 :                                                                                                                               
      17                 : require_once 'Base/String.php';                                                                                               
      18                 :                                                                                                                               
      19                 : /**                                                                                                                           
      20                 :  * Search the Jeanneau dictionary                                                                                             
      21                 :  *                                                                                                                            
      22                 :  * @category   DicFro                                                                                                         
      23                 :  * @package    Model                                                                                                          
      24                 :  * @subpackage Search                                                                                                         
      25                 :  * @author     Michel Corne <mcorne@yahoo.com>                                                                                
      26                 :  * @copyright  2008-2010 Michel Corne                                                                                         
      27                 :  * @license    http://opensource.org/licenses/gpl-3.0.html GNU General Public License, version 3 (GPLv3)                      
      28                 :  */                                                                                                                           
      29                 :                                                                                                                               
      30                 : class Model_Search_Jeanneau                                                                                                   
      31                 : {                                                                                                                             
      32                 :     /**                                                                                                                       
      33                 :      * Template of a page URL                                                                                                 
      34                 :      */                                                                                                                       
      35                 :     const URL_MULTI_PAGE = 'http://www.prima-elementa.fr/Dico-%s%02s.html#%s';                                                
      36                 :     const URL_SINGLE_PAGE = 'http://www.prima-elementa.fr/Dico-%s.htm#%s';                                                    
      37                 :                                                                                                                               
      38                 :     /**                                                                                                                       
      39                 :      * Mapping of the first letters of the top word of the pages                                                              
      40                 :      * @var array                                                                                                             
      41                 :      */                                                                                                                       
      42                 :     public $map = array(                                                                                                      
      43                 :         'a' => array('a', 'ac', 'ad', 'ado', 'ael', 'al', 'am', 'an', 'ap', 'ar', 'as', 'at'),                                
      44                 :         'b' => array('b'),                                                                                                    
      45                 :         'c' => array('ca', 'can', 'cas', 'ce', 'ch', 'cis', 'cle', 'cog', 'com', 'cona', 'cong', 'cont', 'cr', 'cuj'),        
      46                 :         'd' => array('da', 'ded', 'der', 'di', 'dir', 'dit', 'duo'),                                                          
      47                 :         'e' => array('e', 'eg', 'em', 'es', 'exb', 'exo', 'ext'),                                                             
      48                 :         'f' => array('fa', 'fe', 'fi', 'fl', 'fr', 'fu'),                                                                     
      49                 :         'g' => array('g'),                                                                                                    
      50                 :         'h' => array('h'),                                                                                                    
      51                 :         'i' => array('ia', 'imi', 'imu', 'ind', 'infi', 'inn', 'inst', 'inter', 'intes', 'invi'),                             
      52                 :         'j' => array('j'),                                                                                                    
      53                 :         'k' => array('k'),                                                                                                    
      54                 :         'l' => array('la', 'lau', 'lep', 'lob', 'luc'),                                                                       
      55                 :         'm' => array('ma', 'mam', 'me', 'mi', 'mo', 'mu'),                                                                    
      56                 :         'n' => array('na', 'ne', 'neo', 'ni', 'no', 'nu'),                                                                    
      57                 :         'o' => array('o', 'obn', 'obum', 'olo', 'or'),                                                                        
      58                 :         'p' => array('pa', 'pas', 'pen', 'perd', 'perm', 'pert', 'pie', 'po', 'pos', 'praeh', 'praet', 'pro', 'pron', 'prov'),
      59                 :         'q' => array('qua', 'que', 'qui', 'quo'),                                                                             
      60                 :         'r' => array('ra', 're', 'rel', 'ret', 'ri'),                                                                         
      61                 :         's' => array('sa', 'sc', 'se', 'si', 'so', 'sp', 'st', 'sua', 'suc', 'suo'),                                          
      62                 :         't' => array('ta', 'te', 'th', 'tom', 'tran', 'tro'),                                                                 
      63                 :         'u' => array('u', 'un', 'us', 'uti'),                                                                                 
      64                 :         'v' => array('va', 've', 'ves', 'vig', 'vo'),                                                                         
      65                 :         'x' => array('x'),                                                                                                    
      66                 :         'y' => array('x'),                                                                                                    
      67                 :         'z' => array('z'),                                                                                                    
      68                 :     );                                                                                                                        
      69                 :                                                                                                                               
      70                 :     /**                                                                                                                       
      71                 :      * Searches a word                                                                                                        
      72                 :      *                                                                                                                        
      73                 :      * @param  string $word the word to search                                                                                
      74                 :      * @return array  the word details                                                                                        
      75                 :      */                                                                                                                       
      76                 :     public function searchWord($word)                                                                                         
      77                 :     {                                                                                                                         
      78               2 :         $string = new Base_String;                                                                                            
      79                 :                                                                                                                               
      80               2 :         $word = $string->utf8toASCII($word);                                                                                  
      81               2 :         $word = strtolower($word);                                                                                            
      82                 :         // defaults empty word to "a"                                                                                         
      83                 :         $firstLetter = $word?                                                                                                 
      84               2 :             $word[0] :                                                                                                        
      85               2 :             'a';                                                                                                              
      86                 :                                                                                                                               
      87               2 :         if (isset($this->map[$firstLetter])) {                                                                                
      88                 :             // this is a valid letter                                                                                         
      89               2 :             $map = array_values($this->map[$firstLetter]);                                                                    
      90               2 :             $map = array_reverse($map, true);                                                                                 
      91                 :                                                                                                                               
      92               2 :             foreach($map as $number => $letters) {                                                                            
      93               2 :                 if ($word >= $letters) {                                                                                      
      94                 :                     // this is the page where the word is (possibly) located                                                  
      95                 :                     break;                                                                                                    
      96                 :                 }                                                                                                             
      97               2 :             }                                                                                                                 
      98                 :                                                                                                                               
      99               2 :             if (count($map) == 1) {                                                                                           
     100               1 :                 $location = sprintf(self::URL_SINGLE_PAGE, $firstLetter, $word);                                              
     101                 :             } else {                                                                                                          
     102               2 :                 $location = sprintf(self::URL_MULTI_PAGE, $firstLetter, ++$number, $word);                                    
     103                 :             }                                                                                                                 
     104                 :                                                                                                                               
     105                 :         } else {                                                                                                              
     106                 :             // this is an invalid letter, ex. "y"                                                                             
     107               1 :             $location = sprintf(self::URL_MULTI_PAGE, 'a', 1, '');                                                            
     108                 :         }                                                                                                                     
     109                 :                                                                                                                               
     110               2 :         return $location;                                                                                                     
     111                 :     }                                                                                                                         
     112                 : }                                                                                                                             
     113                 :                                                                                                                               

Generated by PHP_CodeCoverage 1.0.0 using PHP 5.3.3 and PHPUnit 3.5.0 at Wed Jan 4 16:32:24 UTC 2012.