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 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(); } }
$definition->lexicon = AdminStringUtil::extractLexicon($definition); } if ($lexemNames) { $lexems = array(); $lexemIds = array(); $ldms = array(); foreach ($lexemNames as $lexemName) { $lexemName = trim($lexemName); if ($lexemName) { $matches = Lexem::loadByExtendedName($lexemName); if (count($matches) >= 1) { foreach ($matches as $match) { if (!in_array($match->id, $lexemIds)) { $lexemIds[] = $match->id; $lexems[] = $match; $ldms[] = LexemDefinitionMap::create($match->id, $definitionId); } } } else { $hasErrors = true; FlashMessage::add("Lexemul <i>" . htmlentities($lexemName) . "</i> nu există. Folosiți lista de sugestii pentru a-l corecta."); $lexems[] = Lexem::create($lexemName, 0, '', ''); // We won't be needing $ldms since there is an error. } } } } else { $lexems = Model::factory('Lexem')->select('Lexem.*')->join('LexemDefinitionMap', 'Lexem.id = lexemId')->where('definitionId', $definitionId)->find_many(); } if ($commentContents) { if (!$comment) {
} } } 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;