Example #1
0
$hasInvariableModel = false;
$dbResult = db_execute("select canonical, modelNumber, count(*) as c " . "from Lexem " . "join LexemModel on lexemId = Lexem.id " . "join ModelType on modelType = code " . "where modelType != 'T' " . "and reverse like '{$reverseSuffix}%' " . "group by canonical, modelNumber " . "order by c desc", PDO::FETCH_ASSOC);
foreach ($dbResult as $row) {
    $modelType = $row['canonical'];
    $modelNumber = $row['modelNumber'];
    $count = $row['c'];
    if (!count($models) || $count / $numLabeled >= 0.05) {
        if ($modelType == 'V' || $modelType == 'VT') {
            $m = Model::factory('FlexModel')->where('modelType', 'V')->where('number', $modelNumber)->find_one();
            $models[] = $m;
            $models[] = FlexModel::create('VT', $modelNumber, '', $m->exponent);
        } else {
            if ($modelType == 'A' || $modelType == 'MF') {
                $m = Model::factory('FlexModel')->where('modelType', 'A')->where('number', $modelNumber)->find_one();
                $models[] = $m;
                $models[] = FlexModel::create('MF', $modelNumber, '', $m->exponent);
            } else {
                $models[] = Model::factory('FlexModel')->where('modelType', $modelType)->where('number', $modelNumber)->find_one();
            }
        }
        $hasInvariableModel = $hasInvariableModel || $modelType == 'I';
    }
}
// Always add the Invariable model
if (!$hasInvariableModel) {
    $models[] = Model::factory('FlexModel')->where('modelType', 'I')->where('number', '1')->find_one();
}
$modelTypes = array();
foreach ($models as $m) {
    $modelTypes[] = ModelType::get_by_code($m->modelType);
}
<?php

require_once "../../phplib/util.php";
$modelType = util_getRequestParameter('modelType');
$locVersion = util_getRequestParameter('locVersion');
if ($locVersion) {
    LocVersion::changeDatabase($locVersion);
}
$models = FlexModel::loadByType($modelType);
foreach ($models as $m) {
    print "{$m->id}\n{$m->number}\n{$m->exponent}\n";
}
Example #3
0
$lexemModelIds = util_getRequestParameter('lexemModelId');
$cloneButton = util_getRequestParameter('cloneButton');
$errorMessages = array();
if ($cloneButton) {
    // Disallow duplicate model numbers
    $m = FlexModel::loadCanonicalByTypeNumber($modelType, $newModelNumber);
    if ($m) {
        $errorMessages[] = "Modelul {$modelType}{$newModelNumber} există deja.";
    }
    if (!$newModelNumber) {
        $errorMessages[] = "Numărul modelului nu poate fi vid.";
    }
    if (!count($errorMessages)) {
        // Clone the model
        $model = Model::factory('FlexModel')->where('modelType', $modelType)->where('number', $modelNumber)->find_one();
        $cloneModel = FlexModel::create($modelType, $newModelNumber, "Clonat după {$modelType}{$modelNumber}", $model->exponent);
        $cloneModel->save();
        // Clone the model descriptions
        $mds = Model::factory('ModelDescription')->where('modelId', $model->id)->order_by_asc('inflectionId')->order_by_asc('variant')->order_by_asc('applOrder')->find_many();
        foreach ($mds as $md) {
            $newMd = Model::factory('ModelDescription')->create();
            $newMd->copyFrom($md);
            $newMd->modelId = $cloneModel->id;
            $newMd->save();
        }
        // Clone the participle model
        if ($modelType == 'V') {
            $pm = ParticipleModel::loadByVerbModel($modelNumber);
            $clonePm = Model::factory('ParticipleModel')->create();
            $clonePm->verbModel = $newModelNumber;
            $clonePm->adjectiveModel = $pm->adjectiveModel;
            $l = Lexem::create($m->exponent, $modelType, $m->number, '');
            $l->isLoc = true;
            $paradigm = getNewForms($l, $locVersion);
        }
        $lexems[] = $l;
        $paradigms[] = $paradigm;
    }
    smarty_assign('modelsToDisplay', $modelsToDisplay);
    smarty_assign('lexems', $lexems);
    smarty_assign('paradigms', $paradigms);
} else {
    smarty_assign('selectedLocVersion', $locVersions[0]->name);
    // LocVersion::changeDatabase($locVersion);
}
$modelTypes = ModelType::loadCanonical();
$models = FlexModel::loadByType($modelType ? $modelType : $modelTypes[0]->code);
smarty_assign('page_title', 'Modele de flexiune');
smarty_assign('locVersions', $locVersions);
smarty_assign('modelTypes', $modelTypes);
smarty_assign('models', $models);
smarty_displayCommonPageWithSkin('modele-flexiune.ihtml');
/*************************************************************************/
/**
 * Load the forms to display for a model when a lexem already exists. This code is specific to each LOC version.
 */
function getExistingForms($lexemId, $locVersion)
{
    if ($locVersion >= '5.0') {
        return InflectedForm::loadByLexemIdMapByInflectionRank($lexemId);
    } else {
        return InflectedForm::loadByLexemIdMapByInflectionId($lexemId);
                $p->save();
                $p->regenerateParadigm();
            }
        }
        $model->exponent = $newExponent;
        $model->description = $newDescription;
        $model->number = $newModelNumber;
        $model->save();
        util_redirect('../admin/index.php');
    }
    smarty_assign('lexems', $lexems);
    smarty_assign('regenForms', $regenForms);
    smarty_assign('regenTransforms', $regenTransforms);
}
if ($modelType == 'V') {
    smarty_assign('adjModels', FlexModel::loadByType('A'));
}
$inputValues = array();
foreach ($inflections as $infl) {
    $inputValues[$infl->id] = array();
    foreach ($newForms[$infl->id] as $form) {
        $inputValues[$infl->id][] = array('form' => $form, 'isLoc' => 1, 'recommended' => 1);
    }
}
if (!$previewButton && !$confirmButton) {
    RecentLink::createOrUpdate("Editare model: {$model}");
}
smarty_assign('inflections', $inflections);
smarty_assign('inflectionMap', Inflection::mapById($inflections));
smarty_assign('modelType', $modelType);
smarty_assign('modelNumber', $modelNumber);
Example #6
0
 public function regenerateLongInfinitive()
 {
     $infl = Inflection::loadLongInfinitive();
     $f107 = FlexModel::get_by_modelType_number('F', '107');
     $f113 = FlexModel::get_by_modelType_number('F', '113');
     // Iterate through all the participle forms of this Lexem
     foreach ($this->getLexemModels() as $lm) {
         $ifs = InflectedForm::get_all_by_lexemModelId_inflectionId($lm->id, $infl->id);
         foreach ($ifs as $if) {
             $model = StringUtil::endsWith($if->formNoAccent, 'are') ? $f113 : $f107;
             $lexem = Model::factory('Lexem')->select('l.*')->table_alias('l')->distinct()->join('LexemModel', 'l.id = lm.lexemId', 'lm')->where('l.formNoAccent', $if->formNoAccent)->where_raw("(lm.modelType = 'T' or (lm.modelType = 'F' and lm.modelNumber = '{$model->number}'))")->find_one();
             if ($lexem) {
                 $infLm = $lexem->getFirstLexemModel();
                 if ($infLm->modelType != 'F' || $infLm->modelNumber != $model->number || $inf->restriction != '') {
                     $infLm->modelType = 'F';
                     $infLm->modelNumber = $model->number;
                     $infLm->restriction = '';
                     if ($this->isLoc() && !$infLm->isLoc) {
                         $infLm->isLoc = true;
                         FlashMessage::add("Lexemul {$lexem->formNoAccent}, care nu era în LOC, a fost inclus automat în LOC.", 'info');
                     }
                     $lexem->deepSave();
                 }
             } else {
                 $lexem = Lexem::deepCreate($if->form, 'F', $model->number, '', $this->isLoc());
                 $lexem->deepSave();
                 // Also associate the new lexem with the same definitions as $this.
                 $ldms = LexemDefinitionMap::get_all_by_lexemId($this->id);
                 foreach ($ldms as $ldm) {
                     LexemDefinitionMap::associate($lexem->id, $ldm->definitionId);
                 }
                 FlashMessage::add("Am creat automat lexemul {$lexem->formNoAccent} (F{$model->number}) și l-am asociat cu toate definițiile verbului.", 'info');
             }
         }
     }
 }
Example #7
0
<?php

require_once "../../phplib/util.php";
util_assertModerator(PRIV_EDIT);
util_assertNotMirror();
$models = FlexModel::loadByType('A');
smarty_assign('recentLinks', RecentLink::loadForUser());
smarty_assign('canEditWotd', util_isModerator(PRIV_WOTD));
smarty_assign("allStatuses", util_getAllStatuses());
smarty_assign("allModeratorSources", Model::factory('Source')->where('canModerate', true)->order_by_asc('displayOrder')->find_many());
smarty_assign('modelTypes', ModelType::loadCanonical());
smarty_assign('models', $models);
smarty_displayWithoutSkin('admin/index.ihtml');
Example #8
0
 function generateInflectedForms()
 {
     if ($this->inflectedForms === null) {
         $lexem = $this->getLexem();
         $model = FlexModel::loadCanonicalByTypeNumber($this->modelType, $this->modelNumber);
         $inflIds = db_getArray("select distinct inflectionId from ModelDescription where modelId = {$model->id} order by inflectionId");
         try {
             $this->inflectedForms = array();
             foreach ($inflIds as $inflId) {
                 $if = $this->generateInflectedFormWithModel($lexem->form, $inflId, $model->id);
                 $this->inflectedForms = array_merge($this->inflectedForms, $if);
             }
         } catch (Exception $ignored) {
             // Make a note of the inflection we cannot generate
             $this->inflectedForms = $inflId;
         }
     }
     return $this->inflectedForms;
 }
Example #9
0
$models = array();
foreach ($lexem->getLexemModels() as $lm) {
    $models[] = FlexModel::loadByType($lm->modelType);
}
$stemLexemModel = LexemModel::create('T', 1);
SmartyWrap::assign('lexem', $lexem);
SmartyWrap::assign('lexemModels', $lexem->getLexemModels());
SmartyWrap::assign('stemLexemModel', $stemLexemModel);
SmartyWrap::assign('searchResults', $searchResults);
SmartyWrap::assign('definitionLexem', $definitionLexem);
SmartyWrap::assign('homonyms', Model::factory('Lexem')->where('formNoAccent', $lexem->formNoAccent)->where_not_equal('id', $lexem->id)->find_many());
SmartyWrap::assign('meaningTags', $meaningTags);
SmartyWrap::assign('modelTypes', Model::factory('ModelType')->order_by_asc('code')->find_many());
SmartyWrap::assign('models', $models);
SmartyWrap::assign('jsonSources', Source::getJson());
SmartyWrap::assign('modelsT', FlexModel::loadByType('T'));
SmartyWrap::assign('canEdit', $canEdit);
SmartyWrap::assign('structStatusNames', Lexem::$STRUCT_STATUS_NAMES);
SmartyWrap::addCss('jqueryui-smoothness', 'paradigm', 'select2', 'lexemEdit', 'windowEngine', 'textComplete');
SmartyWrap::addJs('jqueryui', 'select2', 'select2Dev', 'lexemEdit', 'windowEngine', 'cookie', 'modelDropdown', 'textComplete');
SmartyWrap::displayAdminPage('admin/lexemEdit.tpl');
/**************************************************************************/
// Populate lexem fields from request parameters.
function populate(&$lexem, &$original, $lexemForm, $lexemNumber, $lexemDescription, $lexemComment, $needsAccent, $hyphenations, $pronunciations, $variantOfId, $structStatus, $modelType, $modelNumber, $restriction, $lmTags, $isLoc, $sourceIds)
{
    $lexem->form = AdminStringUtil::formatLexem($lexemForm);
    $lexem->formNoAccent = str_replace("'", '', $lexem->form);
    $lexem->number = $lexemNumber;
    $lexem->description = AdminStringUtil::internalize($lexemDescription, false);
    $lexem->comment = trim(AdminStringUtil::internalize($lexemComment, false));
    // Sign appended comments
Example #10
0
$definitions = Definition::loadByLexemId($lexem->id);
$searchResults = SearchResult::mapDefinitionArray($definitions);
$definitionLexem = mb_strtoupper(AdminStringUtil::internalize($lexem->form, false));
// Generate new inflected forms, but do not overwrite the old ones.
$ifs = $lexem->generateParadigm();
if (!is_array($ifs)) {
    $infl = Inflection::get_by_id($ifs);
    if (!$errorMessage) {
        $errorMessage = "Nu pot genera flexiunea '" . htmlentities($infl->description) . "' " . "conform modelului {$lexem->modelType}{$lexem->modelNumber}.";
    }
} else {
    $ifMap = InflectedForm::mapByInflectionRank($ifs);
    smarty_assign('ifMap', $ifMap);
    smarty_assign('searchResults', $searchResults);
}
$models = FlexModel::loadByType($lexem->modelType);
$sources = LexemSources::getSourceArrayChecked($lexem->source);
$sourceNames = LexemSources::getNamesOfSources($lexem->source);
$canEditForm = !$lexem->isLoc || util_isModerator(PRIV_LOC);
smarty_assign('lexem', $lexem);
smarty_assign('sources', $sources);
smarty_assign('sourceNames', $sourceNames);
smarty_assign('searchResults', $searchResults);
smarty_assign('definitionLexem', $definitionLexem);
smarty_assign('homonyms', Model::factory('Lexem')->where('formNoAccent', $lexem->formNoAccent)->where_not_equal('id', $lexem->id)->find_many());
smarty_assign('suggestedLexems', loadSuggestions($lexem, 5));
smarty_assign('restrS', FlexStringUtil::contains($lexem->restriction, 'S'));
smarty_assign('restrP', FlexStringUtil::contains($lexem->restriction, 'P'));
smarty_assign('restrU', FlexStringUtil::contains($lexem->restriction, 'U'));
smarty_assign('restrI', FlexStringUtil::contains($lexem->restriction, 'I'));
smarty_assign('restrT', FlexStringUtil::contains($lexem->restriction, 'T'));
Example #11
0
                $p->save();
                $p->regenerateParadigm();
            }
        }
        $model->exponent = $newExponent;
        $model->description = $newDescription;
        $model->number = $newModelNumber;
        $model->save();
        util_redirect('../admin/index.php');
    }
    SmartyWrap::assign('lexemModels', $lexemModels);
    SmartyWrap::assign('regenForms', $regenForms);
    SmartyWrap::assign('regenTransforms', $regenTransforms);
}
if ($modelType == 'V') {
    SmartyWrap::assign('adjModels', FlexModel::loadByType('A'));
}
$inputValues = array();
foreach ($inflections as $infl) {
    $inputValues[$infl->id] = array();
    foreach ($newForms[$infl->id] as $form) {
        $inputValues[$infl->id][] = array('form' => $form, 'isLoc' => 1, 'recommended' => 1);
    }
}
if (!$previewButton && !$confirmButton) {
    RecentLink::createOrUpdate("Editare model: {$model}");
}
SmartyWrap::assign('inflections', $inflections);
SmartyWrap::assign('inflectionMap', Inflection::mapById($inflections));
SmartyWrap::assign('modelType', $modelType);
SmartyWrap::assign('adjModelType', ModelType::get_by_code('A'));
Example #12
0
 public function generateParadigm()
 {
     $model = FlexModel::loadCanonicalByTypeNumber($this->modelType, $this->modelNumber);
     // Select inflection IDs for this model
     $inflIds = db_getArray("select distinct inflectionId from ModelDescription where modelId = {$model->id} order by inflectionId");
     $ifs = array();
     foreach ($inflIds as $inflId) {
         $if = $this->generateInflectedFormWithModel($inflId, $model->id);
         if ($if === null) {
             return $inflId;
         }
         $ifs = array_merge($ifs, $if);
     }
     return $ifs;
 }
Example #13
0
             $l = lexemWithModel($l, 'I', 3);
             $l->deepSave();
         }
     } else {
         printf("Comanda 'c' este permisă doar pentru un singur lexem T1\n");
     }
 } else {
     // Parse the proposed lexem list
     $new = [];
     foreach (split(';', $line) as $chunk) {
         // Parse the lexem form (or ID) and model
         $parts = split('/', $chunk);
         $form = trim($parts[0]);
         if (count($parts) == 2) {
             list($modelType, $modelNumber) = parseModel(trim($parts[1]));
             if (!FlexModel::loadCanonicalByTypeNumber($modelType, $modelNumber)) {
                 $errors[] = "Modelul {$parts[1]} nu există.";
             }
         } else {
             $modelType = $modelNumber = null;
         }
         if (count($parts) > 2) {
             $errors[] = "Lexemul [{$chunk}] conține prea multe slashuri";
         }
         // Find or create a lexem with the given form/ID and model
         if (is_numeric($form)) {
             $l = Lexem::get_by_id($form);
             if ($l) {
                 $new[] = $l;
             } else {
                 $errors[] = "Nu există niciun lexem cu ID-ul {$form}";