예제 #1
0
 /**
  * Define a short syllable in a word as either (a) a vowel followed by a non-vowel other than w, x or Y and preceded by a non-vowel,
  *  or * (b) a vowel at the beginning of the word followed by a non-vowel.
  *
  *  So rap, trap, entrap end with a short syllable, and ow, on, at are classed as short syllables.
  *  But uproot, bestow, disturb do not end with a short syllable.
  */
 private function searchShortSyllabe($from, $nbLetters)
 {
     $length = Utf8::strlen($this->word);
     if ($from < 0) {
         $from = $length + $from;
     }
     if ($from < 0) {
         $from = 0;
     }
     // (a) is just for beginning of the word
     if ($nbLetters == 2 && $from != 0) {
         return false;
     }
     $first = Utf8::substr($this->word, $from, 1);
     $second = Utf8::substr($this->word, $from + 1, 1);
     if ($nbLetters == 2) {
         if (in_array($first, self::$vowels) && !in_array($second, self::$vowels)) {
             return true;
         }
     }
     $third = Utf8::substr($this->word, $from + 2, 1);
     if (!in_array($first, self::$vowels) && in_array($second, self::$vowels) && !in_array($third, array_merge(self::$vowels, array('x', 'Y', 'w')))) {
         return true;
     }
     return false;
 }
예제 #2
0
 /**
  * Used by spanish, italian, portuguese, etc (but not by french)
  *
  * If the second letter is a consonant, RV is the region after the next following vowel,
  * or if the first two letters are vowels, RV is the region after the next consonant,
  * and otherwise (consonant-vowel case) RV is the region after the third letter.
  * But RV is the end of the word if these positions cannot be found.
  */
 protected function rv()
 {
     $length = Utf8::strlen($this->word);
     $this->rv = '';
     $this->rvIndex = $length;
     if ($length < 3) {
         return true;
     }
     $first = Utf8::substr($this->word, 0, 1);
     $second = Utf8::substr($this->word, 1, 1);
     // If the second letter is a consonant, RV is the region after the next following vowel,
     if (!in_array($second, static::$vowels)) {
         for ($i = 2; $i < $length; $i++) {
             $letter = Utf8::substr($this->word, $i, 1);
             if (in_array($letter, static::$vowels)) {
                 $this->rvIndex = $i + 1;
                 $this->rv = Utf8::substr($this->word, $i + 1);
                 return true;
             }
         }
     }
     // or if the first two letters are vowels, RV is the region after the next consonant,
     if (in_array($first, static::$vowels) && in_array($second, static::$vowels)) {
         for ($i = 2; $i < $length; $i++) {
             $letter = Utf8::substr($this->word, $i, 1);
             if (!in_array($letter, static::$vowels)) {
                 $this->rvIndex = $i + 1;
                 $this->rv = Utf8::substr($this->word, $i + 1);
                 return true;
             }
         }
     }
     // and otherwise (consonant-vowel case) RV is the region after the third letter.
     if (!in_array($first, static::$vowels) && in_array($second, static::$vowels)) {
         $this->rv = Utf8::substr($this->word, 3);
         $this->rvIndex = 3;
         return true;
     }
 }
예제 #3
0
 /**
  *  If the word begins with two vowels, RV is the region after the third letter,
  *  otherwise the region after the first vowel not at the beginning of the word,
  *  or the end of the word if these positions cannot be found.
  *  (Exceptionally, par, col or tap, at the begining of a word is also taken to define RV as the region to their right.)
  */
 protected function rv()
 {
     $length = Utf8::strlen($this->word);
     $this->rv = '';
     $this->rvIndex = $length;
     if ($length < 3) {
         return true;
     }
     // If the word begins with two vowels, RV is the region after the third letter
     $first = Utf8::substr($this->word, 0, 1);
     $second = Utf8::substr($this->word, 1, 1);
     if (in_array($first, self::$vowels) && in_array($second, self::$vowels)) {
         $this->rv = Utf8::substr($this->word, 3);
         $this->rvIndex = 3;
         return true;
     }
     // (Exceptionally, par, col or tap, at the begining of a word is also taken to define RV as the region to their right.)
     $begin3 = Utf8::substr($this->word, 0, 3);
     if (in_array($begin3, array('par', 'col', 'tap'))) {
         $this->rv = Utf8::substr($this->word, 3);
         $this->rvIndex = 3;
         return true;
     }
     //  otherwise the region after the first vowel not at the beginning of the word,
     for ($i = 1; $i < $length; $i++) {
         $letter = Utf8::substr($this->word, $i, 1);
         if (in_array($letter, self::$vowels)) {
             $this->rv = Utf8::substr($this->word, $i + 1);
             $this->rvIndex = $i + 1;
             return true;
         }
     }
     return false;
 }