function getLexem() { if ($this->lexem === null) { $this->lexem = Lexem::get_by_id($this->lexemId); } return $this->lexem; }
function getTitle() { if ($this->lexem === null) { $this->lexem = Lexem::get_by_id($this->lexemeId); } return $this->lexem ? $this->lexem->formNoAccent : ''; }
public static function associate($lexemId, $definitionId) { // The definition and the lexem should exist $definition = Definition::get_by_id($definitionId); $lexem = Lexem::get_by_id($lexemId); if (!$definition || !$lexem) { return; } // The association itself should not exist. $ldm = Model::factory('LexemDefinitionMap')->where('lexemId', $lexemId)->where('definitionId', $definitionId)->find_one(); if (!$ldm) { $ldm = LexemDefinitionMap::create($lexemId, $definitionId); $ldm->save(); } }
define('TYPE_SHOW_NO_VERBS', 'declinare'); $cuv = util_getRequestParameter('cuv'); $lexemId = util_getRequestParameter('lexemId'); $ajax = util_getRequestParameter('ajax'); $type = util_getRequestParameter('type'); $searchType = SEARCH_INFLECTED; $arr = StringUtil::analyzeQuery($cuv); $hasDiacritics = session_user_prefers(Preferences::FORCE_DIACRITICS) || $arr[0]; // LexemId search if ($lexemId) { $searchType = SEARCH_LEXEM_ID; SmartyWrap::assign('lexemId', $lexemId); if (!StringUtil::validateAlphabet($lexemId, '0123456789')) { $lexemId = ''; } $lexem = Lexem::get_by_id($lexemId); if ($lexem) { $lexems = array($lexem); $cuv = $lexem->formNoAccent; } else { $lexems = array(); $cuv = NULL; } } if ($lexemId) { SmartyWrap::assign('paradigmLink', util_getWwwRoot() . "lexem/{$cuv}/{$lexemId}/paradigma"); } else { SmartyWrap::assign('paradigmLink', util_getWwwRoot() . "definitie/{$cuv}/paradigma"); } if ($cuv) { $cuv = StringUtil::cleanupQuery($cuv);
<?php require_once "../../phplib/util.php"; util_assertModerator(PRIV_EDIT); util_assertNotMirror(); $suffix = util_getRequestParameter('suffix'); $submitButton = util_getRequestParameter('submitButton'); if ($submitButton) { foreach ($_REQUEST as $name => $modelId) { if (StringUtil::startsWith($name, 'lexem_')) { $parts = preg_split('/_/', $name); assert(count($parts) == 2); assert($parts[0] == 'lexem'); $lexem = Lexem::get_by_id($parts[1]); if ($modelId) { $parts = preg_split('/_/', $modelId); assert(count($parts) == 2); $lm = $lexem->getFirstLexemModel(); $lm->modelType = $parts[0]; $lm->modelNumber = $parts[1]; $lm->restriction = util_getRequestParameter('restr_' . $lexem->id); $lm->save(); $lm->regenerateParadigm(); } else { $lexem->comment = util_getRequestParameter('comment_' . $lexem->id); $lexem->save(); } } } util_redirect("bulkLabel.php?suffix={$suffix}"); }
if ($l->comment) { $l->comment = $value; } break; case 'delete': case 'deleteConfirm': $deleteMap[$l->id] = array_key_exists($l->id, $deleteMap) ? $deleteMap[$l->id] + 1 : 1; break; } } } // Delete lexems foreach ($deleteMap as $lId => $value) { if ($value == 2) { // Checked and confirmed $l = Lexem::get_by_id($lId); $l->delete(); } } // Now save the ones that can be saved and present errors for the others foreach ($lexemMap as $id => $l) { if (!array_key_exists($id, $errorMap) && !array_key_exists($id, $deleteMap)) { $l->save(); $lm = $l->getFirstLexemModel(); $lm->save(); $lm->regenerateParadigm(); } } } $deSource = Source::get_by_shortName('DE'); $lexems = Model::factory('Lexem')->table_alias('l')->select('l.*')->distinct()->join('LexemModel', 'l.id = lm.lexemId', 'lm')->join('LexemDefinitionMap', 'l.id = ldm.lexemId', 'ldm')->join('Definition', 'ldm.definitionId = d.id', 'd')->where('d.status', Definition::ST_ACTIVE)->where('d.sourceId', $deSource->id)->where('lm.isLoc', 0)->where_like('l.formNoAccent', "{$prefix}%")->where('l.verifSp', 0)->where_not_equal('lm.modelType', 'SP')->order_by_asc('l.formNoAccent')->limit(100)->find_many();
public function updateVariants($variantIds) { foreach ($variantIds as $variantId) { $variant = Lexem::get_by_id($variantId); $variant->variantOfId = $this->id; $variant->save(); } // Delete variants no longer in the list if ($variantIds) { $lexemsToClear = Model::factory('Lexem')->where('variantOfId', $this->id)->where_not_in('id', $variantIds)->find_many(); } else { $lexemsToClear = self::get_all_by_variantOfId($this->id); } foreach ($lexemsToClear as $l) { $l->variantOfId = null; $l->save(); } }
/** * Search engine friendly URLs used for the search page: * 1) http://dexonline.ro/definitie[-<sursa>]/<cuvânt>[/<defId>][/paradigma] * 2) http://dexonline.ro/lexem[-<sursa>]/<cuvânt>[/<lexemId>][/paradigma] * 3) http://dexonline.ro/text[-<sursa>]/<text> * Links of the old form (search.php?...) can only come via the search form and should not contain lexemId / definitionId. */ function util_redirectToFriendlyUrl($cuv, $lexemId, $sourceUrlName, $text, $showParadigm, $xml, $all) { if (strpos($_SERVER['REQUEST_URI'], '/search.php?') === false) { return; // The url is already friendly. } if ($xml) { return; } $cuv = urlencode($cuv); $sourceUrlName = urlencode($sourceUrlName); $sourcePart = $sourceUrlName ? "-{$sourceUrlName}" : ''; $paradigmPart = $showParadigm ? '/paradigma' : ''; $allPart = $all && !$showParadigm ? '/expandat' : ''; if ($text) { $url = "text{$sourcePart}/{$cuv}"; } else { if ($lexemId) { $l = Lexem::get_by_id($lexemId); if (!$l) { util_redirect(util_getWwwRoot()); } $url = "lexem{$sourcePart}/{$l->formNoAccent}/{$l->id}/{$paradigmPart}"; } else { $url = "definitie{$sourcePart}/{$cuv}{$paradigmPart}"; } } util_redirect(util_getWwwRoot() . $url . $allPart); }
require_once "../../phplib/util.php"; util_assertModerator(PRIV_EDIT); util_assertNotMirror(); util_hideEmptyRequestParameters(); 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; } }
<?php require_once "../../phplib/util.php"; util_assertModerator(PRIV_EDIT); util_assertNotMirror(); $id1 = util_getRequestParameter('id1'); $id2 = util_getRequestParameter('id2'); $l1 = Lexem::get_by_id($id1); $l2 = Lexem::get_by_id($id2); $defs = Definition::loadByLexemId($l1->id); foreach ($defs as $def) { LexemDefinitionMap::associate($l2->id, $def->id); } $l1->delete(); util_redirect("lexemEdit.php?lexemId={$l2->id}");
} else { if ($modelType) { $whereClause = "modelType = '{$modelType}' and restriction like '%P%'"; } else { $whereClause = '(modelType = "T") or (modelType in ("M", "F", "N") and restriction like "%P%")'; } } $dbResult = db_execute("select * from Lexem where {$whereClause} order by formNoAccent", PDO::FETCH_ASSOC); $lexems = array(); foreach ($dbResult as $row) { $lexem = Model::factory('Lexem')->create($row); $matches = array(); $ifs = InflectedForm::get_all_by_formNoAccent($lexem->formNoAccent); foreach ($ifs as $if) { if (in_array($if->inflectionId, $PLURAL_INFLECTIONS) && $if->lexemId != $lexem->id) { $matches[] = Lexem::get_by_id($if->lexemId); } } $lexem->matches = $matches; if (count($lexem->matches)) { $lexem->ifs = InflectedForm::loadByLexemId($lexem->id); // When a plural LOC lexem is merged into a non-LOC singular, we end up losing some word forms from LOC. // Therefore, we have to add the singular lexem to LOC as well. Matei says it is ok to expand LOC this way. $srcIfs = loadIfArrayByLexemId($lexem->id); foreach ($lexem->matches as $match) { $destIfs = loadIfArrayByLexemId($match->id); $addedForms = array(); $lostForms = array(); if ($lexem->isLoc && !$match->isLoc) { // Forms that are going to be added to LOC foreach ($destIfs as $destIf) {
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}"); } }
} 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(); } } } } } } } } }
<?php require_once '../../phplib/util.php'; $visualId = util_getRequestParameter('visualId'); $page = util_getRequestParameter('page'); $limit = util_getRequestParameter('rows'); $usage = util_getRequestParameter('usage'); $resp = array(); $tags = array(); if ($usage == 'table') { $total = Model::factory('VisualTag')->where('imageId', $visualId)->count(); $lines = Model::factory('VisualTag')->where('imageId', $visualId)->limit($limit)->offset(($page - 1) * $limit)->find_many(); } else { if ($usage == 'gallery') { $image = Visual::get_by_id($visualId); $dims = array('width' => $image->width, 'height' => $image->height); $lines = VisualTag::get_all_by_imageId($visualId); } } foreach ($lines as $line) { $row = Lexem::get_by_id($line->lexemeId); $tags[] = array('id' => $line->id, 'label' => $line->label, 'textX' => $line->textXCoord, 'textY' => $line->textYCoord, 'imgX' => $line->imgXCoord, 'imgY' => $line->imgYCoord, 'lexeme' => !empty($row) ? $row->formUtf8General : ''); } if ($usage == 'table') { $resp = array('total' => ceil($total / $limit), 'page' => $page, 'records' => $total, 'rows' => $tags); } else { if ($usage == 'gallery') { $resp = array('dims' => $dims, 'tags' => $tags); } } echo json_encode($resp);
if ($fileName) { $v = Visual::get_by_path($fileName); if (!$v) { $v = Visual::createFromFile($fileName); } util_redirect("?id={$v->id}"); } $v = Visual::get_by_id($id); if ($saveButton) { $v->lexemeId = $lexemId; $v->revised = $revised; $v->save(); util_redirect("?id={$v->id}"); } if ($addTagButton) { $vt = Model::factory('VisualTag')->create(); $vt->imageId = $v->id; $vt->lexemeId = $tagLexemId; $vt->label = $tagLabel; $vt->textXCoord = $textXCoord; $vt->textYCoord = $textYCoord; $vt->imgXCoord = $imgXCoord; $vt->imgYCoord = $imgYCoord; $vt->save(); util_redirect("?id={$v->id}"); } SmartyWrap::assign('visual', $v); SmartyWrap::assign('lexem', Lexem::get_by_id($v->lexemeId)); SmartyWrap::addCss('jqueryui-smoothness', 'jcrop', 'select2', 'jqgrid', 'jqueryui', 'gallery'); SmartyWrap::addJs('jquery', 'jqueryui', 'jcrop', 'visualTag', 'select2', 'select2Dev', 'jqgrid', 'gallery'); SmartyWrap::displayAdminPage('admin/visualTag.tpl');
<?php require_once "../phplib/util.php"; $form = util_getRequestParameter('form'); $locVersion = util_getRequestParameter('locVersion'); $locVersions = pref_getLocVersions(); if ($locVersion && $form) { LocVersion::changeDatabase($locVersion); $form = StringUtil::cleanupQuery($form); smarty_assign('page_title', 'Verificare LOC: ' . $form); $ifs = loadLoc($form); $lexems = array(); $inflections = array(); foreach ($ifs as $if) { $lexems[] = Lexem::get_by_id($if->lexemId); $inflections[] = Inflection::get_by_id($if->inflectionId); } smarty_assign('form', $form); smarty_assign('selectedLocVersion', $locVersion); smarty_assign('ifs', $ifs); smarty_assign('lexems', $lexems); smarty_assign('inflections', $inflections); } else { smarty_assign('selectedLocVersion', $locVersions[1]->name); smarty_assign('page_title', 'Căutare formă flexionară în LOC ' . $form); } setlocale(LC_ALL, "ro_RO.utf8"); smarty_assign('locVersions', $locVersions); smarty_displayCommonPageWithSkin('scrabble-flexiune.ihtml'); function loadLoc($cuv) {
<?php require_once "../../phplib/util.php"; $id = util_getRequestParameter('id'); $m = Meaning::get_by_id($id); $l = Lexem::get_by_id($m->lexemId); $results = array('lexem' => $l->formNoAccent, 'breadcrumb' => $m->breadcrumb, 'htmlRep' => $m->htmlRep); print json_encode($results);
// This is nowhere near perfect, but it's a decent approximation for starters. // Gives each lexem a frequency between 0.00 and 1.00 // Stop words defined in stringUtil.php get 1.00 // Other lexems get frequencies distributed uniformly between 0.01 and 1.00 based on their percentile rankings in the full text index. require_once '../phplib/util.php'; ini_set('max_execution_time', '3600'); ini_set('memory_limit', '256M'); assert_options(ASSERT_BAIL, 1); log_scriptLog('Running rebuildLexemFrequencies.php.'); log_scriptLog('Setting frequency to 1.00 for manual stop words'); foreach (StringUtil::$STOPWORDS as $sw) { $lexems = Lexem::get_all_by_formNoAccent($sw); foreach ($lexems as $l) { $l->frequency = 1.0; $l->save(); } } log_scriptLog("Scanning full text index"); $dbResult = db_execute("select lexemId from FullTextIndex group by lexemId order by count(*)"); $numLexems = $dbResult->rowCount(); $i = 0; foreach ($dbResult as $row) { $lexem = Lexem::get_by_id($row[0]); $lexem->frequency = round($i / $numLexems + 0.005, 2); $lexem->save(); $i++; if ($i % 10000 == 0) { log_scriptLog("{$i} of {$numLexems} labeled"); } } log_scriptLog('rebuildLexemFrequencies.php completed successfully');
<?php require_once "../../phplib/util.php"; $id = util_getRequestParameter('id'); $l = Lexem::get_by_id($id); print json_encode((string) $l);