Example #1
0
function parseToCodePoints($word)
{
    $word_array = explode_telugu(json_encode($word));
    $i = 0;
    $logical_chars = array();
    $ch_buffer = array();
    while ($i < count($word_array)) {
        $current_ch = $word_array[$i++];
        $ch_buffer[count($ch_buffer)] = $current_ch;
        if ($i == count($word_array)) {
            $logical_chars[count($logical_chars)] = $ch_buffer;
            continue;
        }
        $next_ch = $word_array[$i];
        if (isDependent($next_ch)) {
            $ch_buffer[count($ch_buffer)] = $next_ch;
            $i++;
            $logical_chars[count($logical_chars)] = $ch_buffer;
            $ch_buffer = array();
            continue;
        }
        if (isHalant($current_ch)) {
            if (isConsonant($next_ch)) {
                if ($i < count($word_array)) {
                    continue;
                }
                $ch_buffer[count($ch_buffer)] = $current_ch;
            }
            $logical_chars[count($logical_chars)] = $ch_buffer;
            $ch_buffer = array();
            continue;
        } else {
            if (isConsonant($current_ch)) {
                if (isHalant($next_ch) || isDependentVowel($next_ch)) {
                    if ($i < count($word_array)) {
                        continue;
                    }
                    $ch_buffer[count($ch_buffer)] = $current_ch;
                }
                $logical_chars[count($logical_chars)] = $ch_buffer;
                $ch_buffer = array();
                continue;
            } else {
                if (isVowel($current_ch)) {
                    if (isDependentVowel($next_ch)) {
                        $ch_buffer[count($ch_buffer)] = $next_ch;
                        $i++;
                    }
                    $logical_chars[count($logical_chars)] = $ch_buffer;
                    $ch_buffer = array();
                    continue;
                }
            }
        }
        $logical_chars[count($logical_chars)] = $ch_buffer;
        $ch_buffer = array();
    }
    return $logical_chars;
}
Example #2
0
    $index = 0;
    for ($index = 0; $index < strlen($word); $index = $index + 1) {
        if (isVowel($word[$index])) {
            return $index;
        }
    }
}
// HLAVNI CAST
// kazde slovo zpracovavame zvlast
foreach ($wordArray as $word) {
    $wrongChars = array(".", ",", "?", "!", " ");
    // ze slova odstranime nepovolene znaky
    foreach ($wrongChars as $char) {
        $word = str_replace($char, "", $word);
    }
    if (isConsonant($word[0])) {
        // zacina-li samohlaskou, presuneme cast slova po prvni souhlasku
        // na konec a pridema -ay
        $firstPart = substr($word, getVowelIndex($word));
        $secondPart = substr($word, 0, getVowelIndex($word));
        $modifiedword = $firstPart . $secondPart . "ay ";
    } elseif (isVowel($word[0])) {
        // zacina-li souhlaskou, pridame pouze -yay
        $modifiedword = $word . 'yay ';
    } else {
        // zacina-li cislici nebo nekterym z dalsich nepovolenych znaku
        // nahradim slovo ERROR
        $modifiedword = 'ERRORword ';
    }
    // vysledek skladame z transforomovanych slov
    $answer = $answer . $modifiedword;