$ldms = array(); foreach ($lexemNames as $lexemName) { $lexemName = addslashes(AdminStringUtil::formatLexem($lexemName)); if ($lexemName) { $matches = Lexem::loadByExtendedName($lexemName); if (count($matches) >= 1) { foreach ($matches as $match) { LexemDefinitionMap::associate($match->id, $definition->id); log_userLog("Associating with lexem {$match->id} ({$match->form})"); } } else { // Create a new lexem. $lexem = Lexem::create($lexemName, 'T', '1', ''); $lexem->save(); $lexem->regenerateParadigm(); LexemDefinitionMap::associate($lexem->id, $definition->id); log_userLog("Created lexem {$lexem->id} ({$lexem->form})"); } } } FlashMessage::add('Definiția a fost trimisă. Un moderator o va examina în scurt timp. Vă mulțumim!', 'info'); util_redirect('contribuie'); } } else { smarty_assign('sourceId', session_getDefaultContribSourceId()); } smarty_assign('contribSources', Model::factory('Source')->where('canContribute', true)->order_by_asc('displayOrder')->find_many()); smarty_assign('page_title', 'Contribuie cu definiții'); smarty_assign('suggestNoBanner', true); smarty_displayCommonPageWithSkin('contribuie.ihtml'); /**************************************************************************/
$parts = split('-', $normText); foreach ($parts as $part) { $lexems = Lexem::searchWordlists($part, true); if (!count($lexems)) { print "Creez lexemul [{$part}]\n"; $lexem = Lexem::create($part, 'T', '1', ''); $lexem->comment = 'Creat pentru despărțirea în cuvinte a unui ' . 'alt lexem'; $lexem->save(); $lexem->id = db_getLastInsertedId(); $lexem->regenerateParadigm(); $lexems[] = $lexem; } // Now associate every lexem with every definition foreach ($defs as $defAssoc) { foreach ($lexems as $lexemAssoc) { LexemDefinitionMap::associate($lexemAssoc->id, $defAssoc->id); } } } foreach ($defs as $fixDef) { $fixFirstAt = strpos($fixDef->internalRep, '@'); $fixSecondAt = strpos($fixDef->internalRep, '@', $fixFirstAt + 1); assert($fixFirstAt === 0); assert($fixSecondAt !== false); $fixText = trim(substr($fixDef->internalRep, $fixFirstAt + 1, $fixSecondAt - $fixFirstAt - 1)); if (!text_contains($fixText, '-') && !text_contains($fixText, ' ') && str_replace('-', '', $normText) == text_unicodeToLower(text_removeAccents($fixText))) { $prevPos = 0; while (($pos = mb_strpos($normText, '-', $prevPos)) !== false) { $fixText = text_insert($fixText, '-', $pos); $prevPos = $pos + 1; }
$lexems = Lexem::populateFromDbResult(mysql_query($query)); // Skip cases like angstrom - angström or etate (F117) - etate (F117S) $allFormsEqual = true; foreach ($lexems as $l) { $allFormsEqual &= $l->form == $lexems[0]->form && $l->extra == $lexems[0]->extra && $l->restriction == $lexems[0]->restriction; } if (!$allFormsEqual) { print "{$l->form} ({$l->modelType}{$l->modelNumber})\n"; continue; } print "{$form} ({$modelType}{$modelNumber})\n"; $isLoc = false; foreach ($lexems as $i => $l) { print " {$l->form} ({$l->modelType}{$l->modelNumber}) " . "D:[{$l->description}] " . "R:[{$l->restriction}] " . "E:[{$l->extra}] " . "P:[{$l->parseInfo}] " . "C:[{$l->comment}] " . "A:[{$l->noAccent}]\n"; if ($l->form != $lexems[0]->form || $l->unaccented != $lexems[0]->unaccented || $l->reverse != $lexems[0]->reverse || $l->description != $lexems[0]->description || $l->modelType != $lexems[0]->modelType || $l->modelNumber != $lexems[0]->modelNumber || $l->restriction != $lexems[0]->restriction || $l->extra != $lexems[0]->extra || $l->parseInfo != $lexems[0]->parseInfo || $l->comment != $lexems[0]->comment || $l->noAccent != $lexems[0]->noAccent) { die("Difference! ***********************************************\n"); } $ldms = LexemDefinitionMap::loadByLexemId($l->id); foreach ($ldms as $ldm) { LexemDefinitionMap::associate($lexems[0]->id, $ldm->definitionId); } $isLoc |= $l->isLoc; if ($i) { $l->delete(); } } if ($isLoc != $lexems[0]->isLoc) { $lexems[0]->isLoc = $isLoc; $lexems[0]->save(); } }
public function cloneLexem() { $clone = $this->parisClone(); $clone->description = $this->description ? "CLONĂ {$this->description}" : "CLONĂ"; $clone->verifSp = false; $clone->structStatus = self::STRUCT_STATUS_NEW; $lm = Model::factory('LexemModel')->create(); $lm->displayOrder = 1; $lm->modelType = 'T'; $lm->modelNumber = '1'; $lm->restriction = ''; $lm->tags = ''; $lm->isLoc = false; $lm->setLexem($clone); $clone->setLexemModels(array($lm)); $clone->deepSave(); // Clone the definition list $ldms = LexemDefinitionMap::get_all_by_lexemId($this->id); foreach ($ldms as $ldm) { LexemDefinitionMap::associate($clone->id, $ldm->definitionId); } // Clone the root meanings $meanings = Model::factory('Meaning')->where('lexemId', $this->id)->where('parentId', 0)->find_many(); foreach ($meanings as $m) { $m->cloneMeaning($clone->id, 0); } return $clone; }
DebugInfo::disable(); $modelType = util_getRequestParameterWithDefault('modelType', 'M'); $submitButton = util_getRequestParameter('submitButton'); if ($submitButton) { $lexemsToDelete = array(); foreach ($_REQUEST as $name => $value) { if (StringUtil::startsWith($name, 'merge_') && $value) { $parts = preg_split('/_/', $name); assert(count($parts) == 3); assert($parts[0] == 'merge'); $src = Lexem::get_by_id($parts[1]); $dest = Lexem::get_by_id($parts[2]); // Merge $src into $dest $defs = Definition::loadByLexemId($src->id); foreach ($defs as $def) { LexemDefinitionMap::associate($dest->id, $def->id); } // Add $dest to LOC if $src is in LOC if ($src->isLoc() && !$dest->isLoc()) { $lm = $dest->getFirstLexemModel(); $lm->isLoc = true; $lm->save(); } // Delay the deletion because we might have to merge $src with other lexems. $lexemsToDelete[] = $src; } } foreach ($lexemsToDelete as $lexem) { $lexem->delete(); } util_redirect("mergeLexems.php?modelType={$modelType}");
<?php require_once '../../phplib/util.php'; assert_options(ASSERT_BAIL, 1); debug_off(); // When a T1 lexems with the save form as another, non-T1 lexem, delete the // T1 lexem. $dbResult = mysql_query("select distinct l1.* from lexems l1, lexems l2 " . "where l1.lexem_forma = l2.lexem_forma " . "and l1.lexem_model_type = 'T' " . "and l2.lexem_model_type != 'T'"); $fixed = 0; while (($dbRow = mysql_fetch_assoc($dbResult)) != null) { $l = Lexem::createFromDbRow($dbRow); $homonyms = $l->loadHomonyms(); $ldms = LexemDefinitionMap::loadByLexemId($l->id); print "{$l->id} ({$l->form} {$l->modelType}{$l->modelNumber}) :: "; foreach ($homonyms as $h) { print "{$h->id} ({$h->form} {$h->modelType}{$h->modelNumber}) "; foreach ($ldms as $ldm) { LexemDefinitionMap::associate($h->id, $ldm->definitionId); } } $l->delete(); print "\n"; $fixed++; } print "Fixed {$fixed} lexems.\n";
function _cloneLexem($lexem) { $clone = Lexem::create($lexem->form, 'T', 1, ''); $clone->comment = $lexem->comment; $clone->description = $lexem->description ? "CLONĂ {$lexem->description}" : "CLONĂ"; $clone->noAccent = $lexem->noAccent; $clone->save(); // Clone the definition list $ldms = LexemDefinitionMap::get_all_by_lexemId($lexem->id); foreach ($ldms as $ldm) { LexemDefinitionMap::associate($clone->id, $ldm->definitionId); } $clone->regenerateParadigm(); return $clone; }
function handleLexemActions() { $lexemId = util_getRequestParameter('lexemId'); $lexem = Lexem::get_by_id($lexemId); $associateDefinitionId = util_getRequestParameter('associateDefinitionId'); if ($associateDefinitionId) { LexemDefinitionMap::associate($lexem->id, $associateDefinitionId); util_redirect("lexemEdit.php?lexemId={$lexem->id}"); } $dissociateDefinitionId = util_getRequestParameter('dissociateDefinitionId'); if ($dissociateDefinitionId) { LexemDefinitionMap::dissociate($lexem->id, $dissociateDefinitionId); util_redirect("lexemEdit.php?lexemId={$lexem->id}"); } $createDefinition = util_getRequestParameter('createDefinition'); $miniDefTarget = util_getRequestParameter('miniDefTarget'); if ($createDefinition) { $def = Model::factory('Definition')->create(); $def->userId = session_getUserId(); $def->sourceId = Source::get_by_shortName('Neoficial')->id; $def->lexicon = $lexem->formNoAccent; $def->internalRep = '@' . mb_strtoupper(AdminStringUtil::internalize($lexem->form, false)) . '@ v. @' . $miniDefTarget . '.@'; $def->htmlRep = AdminStringUtil::htmlize($def->internalRep, $def->sourceId); $def->status = Definition::ST_ACTIVE; $def->save(); LexemDefinitionMap::associate($lexem->id, $def->id); util_redirect("lexemEdit.php?lexemId={$lexem->id}"); } $deleteLexem = util_getRequestParameter('deleteLexem'); if ($deleteLexem) { $homonyms = Model::factory('Lexem')->where('formNoAccent', $lexem->formNoAccent)->where_not_equal('id', $lexem->id)->find_many(); $lexem->delete(); SmartyWrap::assign('lexem', $lexem); SmartyWrap::assign('homonyms', $homonyms); SmartyWrap::displayAdminPage('admin/lexemDeleted.tpl'); exit; } $cloneLexem = util_getRequestParameter('cloneLexem'); if ($cloneLexem) { $newLexem = $lexem->cloneLexem(); log_userLog("Cloned lexem {$lexem->id} ({$lexem->form}), new id is {$newLexem->id}"); util_redirect("lexemEdit.php?lexemId={$newLexem->id}"); } $mergeLexem = util_getRequestParameter('mergeLexem'); $mergeLexemId = util_getRequestParameter('mergeLexemId'); if ($mergeLexem) { $other = Lexem::get_by_id($mergeLexemId); if ($lexem->form != $other->form) { FlashMessage::add('Nu pot unifica lexemele deoarece accentele diferă. Rezolvați diferența și încercați din nou.'); util_redirect("lexemEdit.php?lexemId={$lexem->id}"); } $defs = Definition::loadByLexemId($lexem->id); foreach ($defs as $def) { LexemDefinitionMap::associate($other->id, $def->id); } // Add lexem models from $lexem to $other if the form is the same. Exclude T-type models. $displayOrder = count($other->getLexemModels()); foreach ($lexem->getLexemModels() as $lm) { if ($lm->modelType != 'T' && !$other->hasModel($lm->modelType, $lm->modelNumber)) { $lm->lexemId = $other->id; $lm->displayOrder = ++$displayOrder; $lm->save(); } } // Add meanings from $lexem to $other and renumber their displayOrder and breadcrumb // displayOrders are generated sequentially regardless of level. // Breadcrumbs follow levels so only their first part changes. $counter = Model::factory('Meaning')->where('lexemId', $other->id)->count(); $numRoots = Model::factory('Meaning')->where('lexemId', $other->id)->where('parentId', 0)->count(); $meanings = Model::factory('Meaning')->where('lexemId', $lexem->id)->order_by_asc('displayOrder')->find_many(); foreach ($meanings as $m) { $m->lexemId = $other->id; $m->displayOrder = ++$counter; $parts = explode('.', $m->breadcrumb, 2); $parts[0] += $numRoots; $m->breadcrumb = implode('.', $parts); $m->save(); } // Add images and image tags from $lexem to $other $visuals = Visual::get_all_by_lexemeId($lexem->id); foreach ($visuals as $v) { $v->lexemeId = $other->id; $v->save(); } $visualTags = VisualTag::get_all_by_lexemeId($lexem->id); foreach ($visualTags as $vt) { $vt->lexemeId = $other->id; $vt->save(); } $lexem->delete(); util_redirect("lexemEdit.php?lexemId={$other->id}"); } }
$preserveCommentUser = util_getRequestParameter('preserveCommentUser'); $refreshButton = util_getRequestParameter('but_refresh'); $acceptButton = util_getRequestParameter('but_accept'); $moveButton = util_getRequestParameter('but_move'); $hasErrors = false; if (!$definitionId) { return; } if (!($definition = Definition::get_by_id($definitionId))) { return; } $comment = Model::factory('Comment')->where('definitionId', $definitionId)->where('status', ST_ACTIVE)->find_one(); $commentUser = $comment ? User::get_by_id($comment->userId) : null; $oldInternalRep = $definition->internalRep; if ($associateLexemId) { LexemDefinitionMap::associate($associateLexemId, $definitionId); util_redirect("definitionEdit.php?definitionId={$definitionId}"); } if ($internalRep) { $errors = array(); $definition->internalRep = AdminStringUtil::internalizeDefinition($internalRep, $sourceId); $definition->htmlRep = AdminStringUtil::htmlize($definition->internalRep, $sourceId, $errors); if (!empty($errors)) { $hasErrors = true; foreach ($errors as $error) { FlashMessage::add($error); } } } if (isset($status)) { $definition->status = (int) $status;
public function regenerateLongInfinitive() { $infl = Inflection::loadLongInfinitive(); $ifs = Model::factory('InflectedForm')->where('lexemId', $this->id)->where('inflectionId', $infl->id)->find_many(); $f107 = Model::factory('FlexModel')->where('modelType', 'F')->where('number', '107')->find_one(); $f113 = Model::factory('FlexModel')->where('modelType', 'F')->where('number', '113')->find_one(); foreach ($ifs as $if) { $model = StringUtil::endsWith($if->formNoAccent, 'are') ? $f113 : $f107; // Load an existing lexem only if it has one of the models F113, F107 or T1. Otherwise create a new lexem. $lexems = Lexem::get_all_by_formNoAccent($if->formNoAccent); $lexem = null; foreach ($lexems as $l) { if ($l->modelType == 'T' || $l->modelType == 'F' && $l->modelNumber == $model->number) { $lexem = $l; } else { if ($this->isLoc && !$l->isLoc) { FlashMessage::add("Lexemul {$l->formNoAccent} ({$l->modelType}{$l->modelNumber}), care nu este în LOC, nu a fost modificat.", 'info'); } } } if ($lexem) { $lexem->modelType = 'F'; $lexem->modelNumber = $model->number; $lexem->restriction = ''; if ($this->isLoc && !$lexem->isLoc) { $lexem->isLoc = $this->isLoc; FlashMessage::add("Lexemul {$lexem->formNoAccent}, care nu era în LOC, a fost inclus automat în LOC.", 'info'); } $lexem->noAccent = false; $lexem->save(); } else { $lexem = Lexem::create($if->form, 'F', $model->number, ''); $lexem->isLoc = $this->isLoc; $lexem->save(); // 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{$lexem->modelNumber}) și l-am asociat cu toate definițiile verbului.", 'info'); } $lexem->regenerateParadigm(); } }
$ldms = LexemDefinitionMap::deleteByDefinitionId($d->id); foreach ($new as $l) { // Update the lexem models if necessary if (!$l->id) { $l->deepSave(); } else { if (!$l->getFirstLexemModel()->id) { $original = Lexem::get_by_id($l->id); foreach ($original->getLexemModels() as $lm) { $lm->delete(); // This will also delete LexemSources and InflectedForms } $l->deepSave(); } } LexemDefinitionMap::associate($l->id, $d->id); } // If any of the original lexems are now unassociated with any definitions, // offer to delete them. foreach ($lexems as $l) { $l = Lexem::get_by_id($l->id); // force a refresh $ldms = LexemDefinitionMap::get_all_by_lexemId($l->id); if (!count($ldms) && !$l->isLoc()) { $delete = myReadline("Șterg lexemul neasociat {$l}? [D/n] "); if ($delete != 'n') { $l->delete(); } } } }
if ($verbose) { echo "\t\tReusing lexem {$lexem->id} ({$lexem->form})\n"; } } else { if ($verbose) { echo "\t\tCreating a new lexem for name {$name}\n"; } if (!$dryrun) { // Create a new lexem. $lexem = Lexem::create($name, 'T', '1', ''); $lexem->save(); $lexem->regenerateParadigm(); if ($verbose) { echo "\t\tCreated lexem {$lexem->id} ({$lexem->form})\n"; } } } // procedura de asociere a definiției cu lexemul de mai sus foreach ($ldms as $map) { if ($verbose) { echo "\t\tAssociate lexem {$name} ({$lexem->id}) to definition ({$map->definitionId})\n"; } if (!$dryrun) { LexemDefinitionMap::associate($lexem->id, $map->definitionId); } } } if ($verbose) { echo "\n"; } }
foreach ($parts as $part) { $part = trim($part); if (!$part || in_array($part, $stopWords)) { // Skip common words continue; } print '['; $baseForms = Lexem::searchWordlists($part, true); if (!count($baseForms)) { $baseForm = Lexem::create($part, 'T', '1', ''); $baseForm->comment = "Provine din despărțirea lexemului [{$l->form}]"; $baseForm->noAccent = true; $baseForm->save(); $baseForm->id = db_getLastInsertedId(); $baseForm->regenerateParadigm(); $baseForms[] = $baseForm; } // Associate every definition with every lexem foreach ($baseForms as $baseForm) { print $baseForm->form . ' '; foreach ($defs as $def) { LexemDefinitionMap::associate($baseForm->id, $def->id); } } print ']'; } print "\n"; } $l->delete(); } print "Seen {$seen} lexems.\n";