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