} $l = lexemWithModel($l, 'I', 3); $l->deepSave(); } } else { printf("Comanda 'c' este permisă doar pentru un singur lexem T1\n"); } } else { // Parse the proposed lexem list $new = []; foreach (split(';', $line) as $chunk) { // Parse the lexem form (or ID) and model $parts = split('/', $chunk); $form = trim($parts[0]); if (count($parts) == 2) { list($modelType, $modelNumber) = parseModel(trim($parts[1])); if (!FlexModel::loadCanonicalByTypeNumber($modelType, $modelNumber)) { $errors[] = "Modelul {$parts[1]} nu există."; } } else { $modelType = $modelNumber = null; } if (count($parts) > 2) { $errors[] = "Lexemul [{$chunk}] conține prea multe slashuri"; } // Find or create a lexem with the given form/ID and model if (is_numeric($form)) { $l = Lexem::get_by_id($form); if ($l) { $new[] = $l; } else {
function parseWordField($word, $modelType, $modelNo, $restr) { $word = trim($word); // Look for a slash not included in brackets $len = mb_strlen($word); $parCount = 0; $i = 0; $found = false; while ($i < $len && !$found) { $c = text_getCharAt($word, $i); if ($c == '[' || $c == '(') { $parCount++; } else { if ($c == ']' || $c == ')') { $parCount--; } } if ($c == '/' && !$parCount) { $found = true; } else { $i++; } } if ($found) { $r1 = parseWordField(mb_substr($word, 0, $i), $modelType, $modelNo, $restr); $r2 = parseWordField(mb_substr($word, $i + 1), $modelType, $modelNo, $restr); return array_merge($r1, $r2); } if (text_endsWith($word, ']')) { $pos = mb_strrpos($word, '['); assert($pos !== false); $extra = mb_substr($word, $pos); $results = parseWordField(mb_substr($word, 0, $pos), $modelType, $modelNo, $restr); assert(count($results)); appendExtra($results[count($results) - 1], $extra); return $results; } if (text_endsWith($word, ')')) { $pos = mb_strrpos($word, '('); assert($pos !== false); $extra = mb_substr($word, $pos); $results = parseWordField(mb_substr($word, 0, $pos), $modelType, $modelNo, $restr); assert(count($results)); // See if $extra contains a model number. If so, use it on the last model. list($modelType, $modelNo, $restr) = parseModel($extra); if ($modelType && $modelNo) { $results[count($results) - 1]->modelType = $modelType; $results[count($results) - 1]->modelNumber = $modelNo; $results[count($results) - 1]->restriction = $restr; } appendExtra($results[count($results) - 1], $extra); // If $extra dictates a part of speech, apply it to all the lexems if (text_contains($extra, 's.f.inv.') || text_contains($extra, 's.f. în expr.') || text_contains($extra, 's.m.inv.') || text_contains($extra, 's.n.inv.') || text_contains($extra, 'adj.inv.') || text_contains($extra, 'adv.') || text_contains($extra, 'conj.') || text_contains($extra, 'prep.') || text_contains($extra, 'interj.')) { foreach ($results as $l) { $l->modelType = 'I'; $l->modelNumber = '1'; $l->restriction = ''; } } return $results; } $parts = split(',', $word); if (count($parts) >= 2) { $results = array(); foreach ($parts as $part) { $results = array_merge($results, parseWordField($part, $modelType, $modelNo, $restr)); } return $results; } $extra = text_contains($word, '-') ? $word : ''; $word = str_replace('-', '', $word); $len = mb_strlen($word); $found = false; for ($i = 0; $i < $len && !$found; $i++) { $c = text_getCharAt($word, $i); if (text_isLowercase($c)) { $found = true; $word = text_insert($word, "'", $i); } } $word = text_unicodeToLower($word); $l = Lexem::create($word, $modelType, $modelNo, $restr); appendExtra($l, $extra); $l->isLoc = true; return array($l); }