[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 namespace Wamania\Snowball\Stemmer; 4 5 use voku\helper\UTF8; 6 7 /** 8 * 9 * @link http://snowball.tartarus.org/algorithms/romanian/stemmer.html 10 * @author wamania 11 * 12 */ 13 class Romanian extends Stem 14 { 15 /** 16 * All Romanian vowels 17 */ 18 protected static $vowels = array('a', 'ă', 'â', 'e', 'i', 'î', 'o', 'u'); 19 20 /** 21 * {@inheritdoc} 22 */ 23 public function stem($word) 24 { 25 // we do ALL in UTF-8 26 if (!UTF8::is_utf8($word)) { 27 throw new \Exception('Word must be in UTF-8'); 28 } 29 30 $this->word = UTF8::strtolower($word); 31 32 $this->plainVowels = implode('', self::$vowels); 33 34 // First, i and u between vowels are put into upper case (so that they are treated as consonants). 35 $this->word = preg_replace('#(['.$this->plainVowels.'])u(['.$this->plainVowels.'])#u', '$1U$2', $this->word); 36 $this->word = preg_replace('#(['.$this->plainVowels.'])i(['.$this->plainVowels.'])#u', '$1I$2', $this->word); 37 38 $this->rv(); 39 $this->r1(); 40 $this->r2(); 41 42 $this->step0(); 43 44 $word1 = $this->word; 45 $word2 = $this->word; 46 47 do { 48 $word1 = $this->word; 49 $this->step1(); 50 } while ($this->word != $word1); 51 52 $this->step2(); 53 54 // Do step 3 if no suffix was removed either by step 1 or step 2. 55 if ($word2 == $this->word) { 56 $this->step3(); 57 } 58 59 $this->step4(); 60 $this->finish(); 61 62 return $this->word; 63 } 64 65 /** 66 * Step 0: Removal of plurals (and other simplifications) 67 * Search for the longest among the following suffixes, and, if it is in R1, perform the action indicated. 68 * @return boolean 69 */ 70 private function step0() 71 { 72 // ul ului 73 // delete 74 if ( ($position = $this->search(array('ul', 'ului'))) !== false) { 75 if ($this->inR1($position)) { 76 $this->word = UTF8::substr($this->word, 0, $position); 77 } 78 return true; 79 } 80 81 // aua 82 // replace with a 83 if ( ($position = $this->search(array('aua'))) !== false) { 84 if ($this->inR1($position)) { 85 $this->word = preg_replace('#(aua)$#u', 'a', $this->word); 86 } 87 return true; 88 } 89 90 // ea ele elor 91 // replace with e 92 if ( ($position = $this->search(array('ea', 'ele', 'elor'))) !== false) { 93 if ($this->inR1($position)) { 94 $this->word = preg_replace('#(ea|ele|elor)$#u', 'e', $this->word); 95 } 96 return true; 97 } 98 99 // ii iua iei iile iilor ilor 100 // replace with i 101 if ( ($position = $this->search(array('ii', 'iua', 'iei', 'iile', 'iilor', 'ilor'))) !== false) { 102 if ($this->inR1($position)) { 103 $this->word = preg_replace('#(ii|iua|iei|iile|iilor|ilor)$#u', 'i', $this->word); 104 } 105 return true; 106 } 107 108 // ile 109 // replace with i if not preceded by ab 110 if ( ($position = $this->search(array('ile'))) !== false) { 111 if ($this->inR1($position)) { 112 $before = UTF8::substr($this->word, ($position-2), 2); 113 114 if ($before != 'ab') { 115 $this->word = preg_replace('#(ile)$#u', 'i', $this->word); 116 } 117 } 118 return true; 119 } 120 121 // atei 122 // replace with at 123 if ( ($position = $this->search(array('atei'))) != false) { 124 if ($this->inR1($position)) { 125 $this->word = preg_replace('#(atei)$#u', 'at', $this->word); 126 } 127 return true; 128 } 129 130 // aţie aţia 131 // replace with aţi 132 if ( ($position = $this->search(array('aţie', 'aţia'))) !== false) { 133 if ($this->inR1($position)) { 134 $this->word = preg_replace('#(aţie|aţia)$#u', 'aţi', $this->word); 135 } 136 return true; 137 } 138 139 return false; 140 } 141 142 /** 143 * Step 1: Reduction of combining suffixes 144 * Search for the longest among the following suffixes, and, if it is in R1, preform the replacement action indicated. 145 * Then repeat this step until no replacement occurs. 146 * @return boolean 147 */ 148 private function step1() 149 { 150 // abilitate abilitati abilităi abilităţi 151 // replace with abil 152 if ( ($position = $this->search(array('abilitate', 'abilitati', 'abilităi', 'abilităţi'))) !== false) { 153 if ($this->inR1($position)) { 154 $this->word = preg_replace('#(abilitate|abilitati|abilităi|abilităţi)$#u', 'abil', $this->word); 155 } 156 return true; 157 } 158 159 // ibilitate 160 // replace with ibil 161 if ( ($position = $this->search(array('ibilitate'))) !== false) { 162 if ($this->inR1($position)) { 163 $this->word = preg_replace('#(ibilitate)$#u', 'ibil', $this->word); 164 } 165 return true; 166 } 167 168 // ivitate ivitati ivităi ivităţi 169 // replace with iv 170 if ( ($position = $this->search(array('ivitate', 'ivitati', 'ivităi', 'ivităţi'))) !== false) { 171 if ($this->inR1($position)) { 172 $this->word = preg_replace('#(ivitate|ivitati|ivităi|ivităţi)$#u', 'iv', $this->word); 173 } 174 return true; 175 } 176 177 // icitate icitati icităi icităţi icator icatori iciv iciva icive icivi icivă ical icala icale icali icală 178 // replace with ic 179 if ( ($position = $this->search(array( 180 'icitate', 'icitati', 'icităi', 'icităţi', 'icatori', 'icator', 'iciva', 181 'icive', 'icivi', 'icivă', 'icala', 'icale', 'icali', 'icală', 'iciv', 'ical'))) !== false) { 182 if ($this->inR1($position)) { 183 $this->word = preg_replace('#(icitate|icitati|icităi|icităţi|cator|icatori|iciva|icive|icivi|icivă|icala|icale|icali|icală|ical|iciv)$#u', 'ic', $this->word); 184 } 185 return true; 186 } 187 188 // ativ ativa ative ativi ativă aţiune atoare ator atori ătoare ător ători 189 // replace with at 190 if ( ($position = $this->search(array('ativa', 'ative', 'ativi', 'ativă', 'ativ', 'aţiune', 'atoare', 'atori', 'ătoare', 'ători', 'ător', 'ator'))) !== false) { 191 if ($this->inR1($position)) { 192 $this->word = preg_replace('#(ativa|ative|ativi|ativă|ativ|aţiune|atoare|atori|ătoare|ători|ător|ator)$#u', 'at', $this->word); 193 } 194 return true; 195 } 196 197 // itiv itiva itive itivi itivă iţiune itoare itor itori 198 // replace with it 199 if ( ($position = $this->search(array('itiva', 'itive', 'itivi', 'itivă', 'itiv', 'iţiune', 'itoare', 'itori', 'itor'))) !== false) { 200 if ($this->inR1($position)) { 201 $this->word = preg_replace('#(itiva|itive|itivi|itivă|itiv|iţiune|itoare|itori|itor)$#u', 'it', $this->word); 202 } 203 return true; 204 } 205 206 return false; 207 } 208 209 /** 210 * Step 2: Removal of 'standard' suffixes 211 * Search for the longest among the following suffixes, and, if it is in R2, perform the action indicated. 212 * @return boolean 213 */ 214 private function step2() 215 { 216 // atori itate itati, ităţi, abila abile abili abilă, ibila ibile ibili ibilă 217 // anta, ante, anti, antă, ator, ibil, oasa oasă oase, ităi, abil 218 // osi oşi ant ici ică iva ive ivi ivă ata ată ati ate, ata ată ati ate uta ută uti ute, ita ită iti ite ica ice 219 // at, os, iv, ut, it, ic 220 // delete 221 if ( ($position = $this->search(array( 222 'atori', 'itate', 'itati', 'ităţi', 'abila', 'abile', 'abili', 'abilă', 'ibila', 'ibile', 'ibili', 'ibilă', 223 'anta', 'ante', 'anti', 'antă', 'ator', 'ibil', 'oasa', 'oasă', 'oase', 'ităi', 'abil', 224 'osi', 'oşi', 'ant', 'ici', 'ică', 'iva', 'ive', 'ivi', 'ivă', 'ata', 'ată', 'ati', 'ate', 'ata', 'ată', 225 'ati', 'ate', 'uta', 'ută', 'uti', 'ute', 'ita', 'ită', 'iti', 'ite', 'ica', 'ice', 226 'at', 'os', 'iv', 'ut', 'it', 'ic' 227 ))) !== false) { 228 if ($this->inR2($position)) { 229 $this->word = UTF8::substr($this->word, 0, $position); 230 } 231 return true; 232 } 233 234 // iune iuni 235 // delete if preceded by ţ, and replace the ţ by t. 236 if ( ($position = $this->search(array('iune', 'iuni'))) !== false) { 237 if ($this->inR2($position)) { 238 $before = $position - 1; 239 $letter = UTF8::substr($this->word, $before, 1); 240 if ($letter == 'ţ') { 241 $this->word = UTF8::substr($this->word, 0, $position); 242 $this->word = preg_replace('#(ţ)$#u', 't', $this->word); 243 } 244 } 245 return true; 246 } 247 248 // ism isme ist ista iste isti istă işti 249 // replace with ist 250 if ( ($position = $this->search(array('isme', 'ism', 'ista', 'iste', 'isti', 'istă', 'işti', 'ist'))) !== false) { 251 if ($this->inR2($position)) { 252 $this->word = preg_replace('#(isme|ism|ista|iste|isti|istă|işti|ist)$#u', 'ist', $this->word); 253 } 254 return true; 255 } 256 257 return false; 258 } 259 260 /** 261 * Step 3: Removal of verb suffixes 262 * Do step 3 if no suffix was removed either by step 1 or step 2. 263 * @return boolean 264 */ 265 private function step3() 266 { 267 // are ere ire âre ind ând indu ându eze ească ez ezi ează esc eşti 268 // eşte ăsc ăşti ăşte am ai au eam eai ea eaţi eau iam iai ia iaţi 269 // iau ui aşi arăm arăţi ară uşi urăm urăţi ură işi irăm irăţi iră âi 270 // âşi ârăm ârăţi âră asem aseşi ase aserăm aserăţi aseră isem iseşi ise 271 // iserăm iserăţi iseră âsem âseşi âse âserăm âserăţi âseră usem useşi use userăm userăţi useră 272 // delete if preceded in RV by a consonant or u 273 if ( ($position = $this->searchIfInRv(array( 274 'userăţi', 'iserăţi', 'âserăţi', 'aserăţi', 275 'userăm', 'iserăm', 'âserăm', 'aserăm', 276 'iseră', 'âseşi', 'useră', 'âseră', 'useşi', 'iseşi', 'aseră', 'aseşi', 'ârăţi', 'irăţi', 'urăţi', 'arăţi', 'ească', 277 'usem', 'âsem', 'isem', 'asem', 'ârăm', 'urăm', 'irăm', 'arăm', 'iaţi', 'eaţi', 'ăşte', 'ăşti', 'eşte', 'eşti', 'ează', 'ându', 'indu', 278 'âse', 'use', 'ise', 'ase', 'âră', 'iră', 'işi', 'ură', 'uşi', 'ară', 'aşi', 'âşi', 'iau', 'iai', 'iam', 'eau', 'eai', 'eam', 'ăsc', 279 'are', 'ere', 'ire', 'âre', 'ind', 'ând', 'eze', 'ezi', 'esc', 280 'âi', 'ui', 'ia', 'ea', 'au', 'ai', 'am', 'ez' 281 ))) !== false) { 282 if ($this->inRv($position)) { 283 $before = $position - 1; 284 if ($this->inRv($before)) { 285 $letter = UTF8::substr($this->word, $before, 1); 286 287 if ( (!in_array($letter, self::$vowels)) || ($letter == 'u') ) { 288 $this->word = UTF8::substr($this->word, 0, $position); 289 } 290 } 291 } 292 return true; 293 } 294 295 296 297 // ăm aţi em eţi im iţi âm âţi seşi serăm serăţi seră sei se sesem seseşi sese seserăm seserăţi seseră 298 // delete 299 if ( ($position = $this->searchIfInRv(array( 300 'seserăm', 'seserăţi', 'seseră', 'seseşi', 'sesem', 'serăţi', 'serăm', 'seşi', 'sese', 'seră', 301 'aţi', 'eţi', 'iţi', 'âţi', 'sei', 'se', 'ăm', 'âm', 'em', 'im' 302 ))) !== false) { 303 if ($this->inRv($position)) { 304 $this->word = UTF8::substr($this->word, 0, $position); 305 } 306 return true; 307 } 308 } 309 310 /** 311 * Step 4: Removal of final vowel 312 */ 313 private function step4() 314 { 315 // Search for the longest among the suffixes "a e i ie ă " and, if it is in RV, delete it. 316 if ( ($position = $this->search(array('a', 'ie', 'e', 'i', 'ă'))) !== false) { 317 if ($this->inRv($position)) { 318 $this->word = UTF8::substr($this->word, 0, $position); 319 } 320 } 321 322 return true; 323 } 324 325 /** 326 * Finally 327 * Turn I, U back into i, u 328 */ 329 private function finish() 330 { 331 // Turn I, U back into i, u 332 $this->word = UTF8::str_replace(array('I', 'U'), array('i', 'u'), $this->word); 333 } 334 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |