Пример #1
0
function associateLongInfinitivesAndParticiples()
{
    $lexems = Lexem::loadUnassociated();
    $numMatched = 0;
    foreach ($lexems as $l) {
        $matched = false;
        $wordlist = WordList::loadByUnaccented($l->unaccented);
        foreach ($wordlist as $wl) {
            if ($wl->inflectionId == 50 || $wl->inflectionId == 52) {
                $verb = Lexem::load($wl->lexemId);
                print "{$l->unaccented} :: {$verb->unaccented}\n";
                $matched = true;
                $ldms = LexemDefinitionMap::loadByLexemId($verb->id);
                foreach ($ldms as $ldm) {
                    $existingLdm = LexemDefinitionMap::load($l->id, $ldm->definitionId);
                    if (!$existingLdm) {
                        $newLdm = LexemDefinitionMap::create($l->id, $ldm->definitionId);
                        $newLdm->save();
                    }
                }
            }
        }
        if ($matched) {
            $numMatched++;
        }
    }
    print "Matched {$numMatched} of " . count($lexems) . " total lexems.\n";
}
 public static function deleteByLexemId($lexemId)
 {
     $ldms = LexemDefinitionMap::get_all_by_lexemId($lexemId);
     foreach ($ldms as $ldm) {
         Definition::updateModDate($ldm->definitionId);
         $ldm->delete();
     }
 }
Пример #3
0
 $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;
         }
Пример #4
0
        $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');
/**************************************************************************/
Пример #5
0
 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;
 }
Пример #6
0
    $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();
    }
}
Пример #7
0
<?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";
Пример #8
0
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}");
Пример #9
0
<?php

/**
 * This script deletes spammy definitions sent in bulk
 **/
require_once __DIR__ . '/../phplib/util.php';
$defs = Model::factory('Definition')->where('userId', 0)->where('status', ST_PENDING)->where_like('internalRep', '%[url=%')->find_many();
foreach ($defs as $def) {
    print sprintf("Deleting ID = %d, rep = %s\n", $def->id, StringUtil::shortenString($def->internalRep, 100));
    $defId = $def->id;
    $def->delete();
    db_execute("delete from Typo where definitionId = {$defId}");
    // TODO: This code replicates code in definitionEdit.php
    // If by deleting this definition, any associated lexems become unassociated, delete them
    $ldms = LexemDefinitionMap::get_all_by_definitionId($defId);
    db_execute("delete from LexemDefinitionMap where definitionId = {$defId}");
    foreach ($ldms as $ldm) {
        $l = Lexem::get_by_id($ldm->lexemId);
        $otherLdms = LexemDefinitionMap::get_all_by_lexemId($l->id);
        if (!$l->isLoc && !count($otherLdms)) {
            $l->delete();
        }
    }
}
print sprintf("Deleted %d definitions\n", count($defs));
Пример #10
0
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}");
    }
}
Пример #11
0
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;
}
Пример #12
0
 public function delete()
 {
     if ($this->id) {
         if ($this->modelType == 'VT') {
             $this->deleteParticiple($this->modelNumber);
         }
         if ($this->modelType == 'VT' || $this->modelType == 'V') {
             $this->deleteLongInfinitive();
         }
         LexemDefinitionMap::deleteByLexemId($this->id);
         InflectedForm::deleteByLexemId($this->id);
     }
     parent::delete();
 }
Пример #13
0
            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";
    }
}
Пример #14
0
                }
            }
        }
        if ($d->lexicon) {
            $lexems = Lexem::loadByUnaccented($d->lexicon);
            if (!count($lexems)) {
                $lexem = Lexem::create($d->lexicon, 'T', '1', '');
                $lexem->save();
                $lexem->id = db_getLastInsertedId();
                $lexem->regenerateParadigm();
                $lexems[] = $lexem;
            }
            $d->save();
            $d->id = db_getLastInsertedId();
            foreach ($lexems as $l) {
                $ldm = LexemDefinitionMap::create($l->id, $d->id);
                $ldm->save();
            }
        } else {
            print "Skipping [{$d->internalRep}]\n";
        }
    }
    if (++$linesSeen % 1000 == 0) {
        print "{$linesSeen} lines seen.\n";
    }
}
print "Skipped {$skipped} existing definitions\n";
/***************************************************************************/
function parseArguments()
{
    global $argv;
Пример #15
0
        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";