Пример #1
0
 static function extractTransforms($from, $to, $isPronoun)
 {
     // Vowel count after the accent
     $accentPosFrom = self::findAccentPosition($from);
     $accentPosTo = self::findAccentPosition($to);
     // String position of the accent
     $accentIndexFrom = mb_strpos($from, "'");
     $accentIndexTo = mb_strpos($to, "'");
     if ($accentIndexTo !== false) {
         $accentedVowelTo = StringUtil::getCharAt($to, $accentIndexTo + 1);
     }
     $from = str_replace("'", '', $from);
     $to = str_replace("'", '', $to);
     $t = self::extractTransformsNoAccents($from, $to, $isPronoun);
     if ($t == null) {
         return null;
     }
     if (!count($t)) {
         $t[] = Transform::createOrLoad('', '');
     }
     if (!$accentPosFrom || !$accentPosTo) {
         $accentShift = UNKNOWN_ACCENT_SHIFT;
     } else {
         if ($accentIndexFrom == $accentIndexTo && mb_substr($from, 0, $accentIndexFrom + 1) == mb_substr($to, 0, $accentIndexTo + 1)) {
             // Compare the beginning of $from and $to, up to and including the
             // accented character. Note that we have already removed the accent,
             // so we only add 1 above, not 2.
             $accentShift = NO_ACCENT_SHIFT;
         } else {
             $accentShift = $accentPosTo;
             $t[] = $accentedVowelTo;
         }
     }
     $t[] = $accentShift;
     return $t;
 }
Пример #2
0
 foreach ($regenTransforms as $inflId => $transformMatrix) {
     db_execute("delete from ModelDescription where modelId = {$model->id} and inflectionId = {$inflId}");
     $variant = 0;
     foreach ($transformMatrix as $transforms) {
         $accentShift = array_pop($transforms);
         if ($accentShift != UNKNOWN_ACCENT_SHIFT && $accentShift != NO_ACCENT_SHIFT) {
             $accentedVowel = array_pop($transforms);
         } else {
             $accentedVowel = '';
         }
         $order = 0;
         $mds = array();
         for ($i = count($transforms) - 1; $i >= 0; $i--) {
             $t = $transforms[$i];
             // Make sure the transform has an ID.
             $t = Transform::createOrLoad($t->transfFrom, $t->transfTo);
             $md = Model::factory('ModelDescription')->create();
             $md->modelId = $model->id;
             $md->inflectionId = $inflId;
             $md->variant = $variant;
             $md->applOrder = $order++;
             $md->isLoc = false;
             $md->recommended = false;
             $md->transformId = $t->id;
             $md->accentShift = $accentShift;
             $md->vowel = $accentedVowel;
             $md->save();
         }
         $variant++;
     }
 }
Пример #3
0
        if (!text_validateAlphabet($form, "aăâbcdefghiîjklmnopqrsștțuvwxyz'")) {
            die("Illegal characters in form {$form}\n");
        }
        $transforms = text_extractTransforms($baseForm, $form, $model->modelType == 'P');
        assert(count($transforms) >= 2);
        // Split off the last transform: it indicates the accent shift
        $accentShift = array_pop($transforms);
        if ($accentShift != UNKNOWN_ACCENT_SHIFT && $accentShift != NO_ACCENT_SHIFT) {
            $accentedVowel = array_pop($transforms);
        } else {
            $accentedVowel = '';
        }
        //foreach ($transforms as $t) {
        //  print $t->toString() . ' ';
        //}
        //print "$accentShift\n";
        // Reverse the transforms array. At the same time, save the transforms.
        $newT = array();
        for ($i = count($transforms) - 1; $i >= 0; $i--) {
            $t = $transforms[$i];
            $newT[] = Transform::createOrLoad($t->from, $t->to);
        }
        $transforms = $newT;
        foreach ($transforms as $i => $t) {
            $md = ModelDescription::create($model->id, $inflId, $variant, $i, $t->id, $accentShift, $accentedVowel);
            $md->save();
        }
    }
    $numModels++;
}
print "{$numModels} models migrated from dmlr_models.\n";