Exemplo n.º 1
0
 // Now load the affected lexems. For each lexem, inflection and transform
 // list, generate a new form.
 $lexems = Lexem::loadByCanonicalModel($modelType, $modelNumber);
 $regenForms = array();
 foreach ($lexems as $l) {
     $regenRow = array();
     foreach ($regenTransforms as $inflId => $variants) {
         $regenRow[$inflId] = array();
         foreach ($variants as $transforms) {
             $accentShift = array_pop($transforms);
             if ($accentShift != UNKNOWN_ACCENT_SHIFT && $accentShift != NO_ACCENT_SHIFT) {
                 $accentedVowel = array_pop($transforms);
             } else {
                 $accentedVowel = '';
             }
             $result = FlexStringUtil::applyTransforms($l->form, $transforms, $accentShift, $accentedVowel);
             $regenRow[$inflId][] = $result;
             if (!$result && count($errorMessage) <= 20) {
                 $errorMessage[] = "Nu pot calcula una din formele lexemului " . htmlentities($l->form) . ".";
             }
         }
     }
     $regenForms[] = $regenRow;
 }
 // Now load the affected adjectives if the participle model changed
 if ($participleNumber != $newParticipleNumber) {
     $participleParadigms = array();
     $participles = loadParticiplesForVerbModel($modelNumber, $participleNumber);
     foreach ($participles as $p) {
         $p->modelNumber = $newParticipleNumber;
         $ifs = $p->generateParadigm();
Exemplo n.º 2
0
 public function generateInflectedFormWithModel($form, $inflId, $modelId)
 {
     if (!ConstraintMap::validInflection($inflId, $this->restriction)) {
         return array();
     }
     $ifs = array();
     $mds = Model::factory('ModelDescription')->where('modelId', $modelId)->where('inflectionId', $inflId)->order_by_asc('variant')->order_by_asc('applOrder')->find_many();
     $start = 0;
     while ($start < count($mds)) {
         // Identify all the md's that differ only by the applOrder
         $end = $start + 1;
         while ($end < count($mds) && $mds[$end]->applOrder != 0) {
             $end++;
         }
         $inflId = $mds[$start]->inflectionId;
         $accentShift = $mds[$start]->accentShift;
         $vowel = $mds[$start]->vowel;
         // Apply all the transforms from $start to $end - 1.
         $variant = $mds[$start]->variant;
         $recommended = $mds[$start]->recommended;
         // Load the transforms
         $transforms = array();
         for ($i = $end - 1; $i >= $start; $i--) {
             $transforms[] = Transform::get_by_id($mds[$i]->transformId);
         }
         $result = FlexStringUtil::applyTransforms($form, $transforms, $accentShift, $vowel);
         if (!$result) {
             throw new Exception();
         }
         $ifs[] = InflectedForm::create($result, $this->id, $inflId, $variant, $recommended);
         $start = $end;
     }
     return $ifs;
 }
Exemplo n.º 3
0
assertEquals("c'asă", FlexStringUtil::placeAccent("casă", 2, ''));
assertEquals("casă", FlexStringUtil::placeAccent("casă", 3, ''));
assertEquals("ap'ă", FlexStringUtil::placeAccent("apă", 1, ''));
assertEquals("'apă", FlexStringUtil::placeAccent("apă", 2, ''));
assertEquals("apă", FlexStringUtil::placeAccent("apă", 3, ''));
assertEquals("'a", FlexStringUtil::placeAccent("a", 1, ''));
assertEquals("a", FlexStringUtil::placeAccent("a", 2, ''));
assertEquals("șa'ibă", FlexStringUtil::placeAccent("șaibă", 2, ''));
assertEquals("ș'aibă", FlexStringUtil::placeAccent("șaibă", 3, ''));
assertEquals("ș'aibă", FlexStringUtil::placeAccent("șaibă", 2, 'a'));
assertEquals("ș'aibă", FlexStringUtil::placeAccent("șaibă", 3, 'a'));
assertEquals("șa'ibă", FlexStringUtil::placeAccent("șaibă", 2, 'i'));
assertEquals("șa'ibă", FlexStringUtil::placeAccent("șaibă", 3, 'i'));
assertEquals("unfuckingbelievable", FlexStringUtil::insert("unbelievable", "f*****g", 2));
assertEquals("abcdef", FlexStringUtil::insert("cdef", "ab", 0));
assertEquals("abcdef", FlexStringUtil::insert("abcd", "ef", 4));
assertEquals('mamă      ', AdminStringUtil::padRight('mamă', 10));
assertEquals('mama      ', AdminStringUtil::padRight('mama', 10));
assertEquals('ăâîșț   ', AdminStringUtil::padRight('ăâîșț', 8));
assertEquals('ăâîșț', AdminStringUtil::padRight('ăâîșț', 5));
assertEquals('ăâîșț', AdminStringUtil::padRight('ăâîșț', 3));
assertEqualArrays(array('c', 'a', 'r'), AdminStringUtil::unicodeExplode('car'));
assertEqualArrays(array('ă', 'a', 'â', 'ș', 'ț'), AdminStringUtil::unicodeExplode('ăaâșț'));
assertEqualArrays(array(1, 5, 10), util_intersectArrays(array(1, 3, 5, 7, 9, 10), array(1, 2, 4, 5, 6, 8, 10)));
assertEqualArrays(array(), util_intersectArrays(array(2, 4, 6, 8), array(1, 3, 5, 7)));
assert(!Lock::release('test'));
assert(!Lock::exists('test'));
assert(Lock::acquire('test'));
assert(Lock::exists('test'));
assert(!Lock::acquire('test'));
assert(Lock::release('test'));
Exemplo n.º 4
0
$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'));
smarty_assign('modelTypes', Model::factory('ModelType')->order_by_asc('code')->find_many());
smarty_assign('models', $models);
smarty_assign('canEditForm', $canEditForm);
smarty_assign('allStatuses', util_getAllStatuses());
smarty_assign('errorMessage', $errorMessage);
smarty_assign('recentLinks', RecentLink::loadForUser());
smarty_displayWithoutSkin('admin/lexemEdit.ihtml');
function validate($lexem)
{
    if (!$lexem->form) {
        return 'Forma nu poate fi vidă.';
    }
    $numAccents = mb_substr_count($lexem->form, "'");
    // Note: we allow multiple accents for lexems like hárcea-párcea
    if ($numAccents && $lexem->noAccent) {