コード例 #1
0
 public static function mapByInflectionRank($ifs)
 {
     $result = array();
     foreach ($ifs as $if) {
         $inflection = Inflection::get_by_id($if->inflectionId);
         if (!array_key_exists($inflection->rank, $result)) {
             $result[$inflection->rank] = array();
         }
         $result[$inflection->rank][] = $if;
     }
     return $result;
 }
コード例 #2
0
function matchInflections($inflIdDescrMap)
{
    $result = array();
    $inflections = Inflection::loadAll();
    foreach ($inflections as $rInfl) {
        foreach ($inflIdDescrMap as $cId => $cDescr) {
            if ($rInfl->description == $cDescr) {
                $result[$rInfl->id] = $cId;
            }
        }
        if (!array_key_exists($rInfl->id, $result)) {
            die("Could not find mapping for {$rInfl->id} ({rInfl->description})\n");
        }
    }
    return $result;
}
コード例 #3
0
ファイル: inflection.php プロジェクト: rintaun/PGModel
<?php

require_once 'tap.php';
require_once '../inflection.php';
require_once '../exceptions.php';
$tests = 5;
$test_plur = array(array('equipment', 'equipment', 'uncountable'), array('mouse', 'mice', 'irregular - suffix as word'), array('doormouse', 'doormice', 'irregular - suffix as suffix'), array('ox', 'oxen', 'irregular'), array('vortex', 'vortices', 'irregular - ix/ex'), array('calf', 'calves', 'irregular - f  => ves'), array('knife', 'knives', 'irregular - fe => ves'), array('echo', 'echoes', 'irregular - o  => oes'), array('larva', 'larvae', 'irregular - a  => ae'), array('alumnus', 'alumni', 'irregular - us => i'), array('addendum', 'addenda', 'irregular - um => a'), array('analysis', 'analyses', 'irregular - is => es'), array('some_person', 'some_people', 'separates words'), array('solliloquy', 'solliloquys', 'regular - ends in [vowel]y'), array('symphony', 'symphonies', 'regular - ends in ' . '[consonant]y'), array('quiz', 'quizzes', 'regular - ends in [vowel]z'), array('church', 'churches', 'regular - ends in s-like ' . 'sound'), array('cow', 'cows', 'regular'));
$test_sing = array(array('fish', 'fish', 'uncountable'), array('lice', 'louse', 'irregular - suffix as word'), array('barklice', 'barklouse', 'irregular - suffix as suffix'), array('children', 'child', 'irregular'), array('vortices', 'vortex', 'irregular - ix/ex'), array('wolves', 'wolf', 'irregular - ves => f'), array('wives', 'wife', 'irregular - ves => fe'), array('vertebrae', 'vertebra', 'irregular - ae  => a'), array('nuclei', 'nucleus', 'irregular - i   => us'), array('errata', 'erratum', 'irregular - um  => a'), array('hypotheses', 'hypothesis', 'irregular - es  => is'), array('back_teeth', 'back_tooth', 'separates words'), array('solliloquys', 'solliloquy', 'regular - ends in [vowel]y'), array('harmonies', 'harmony', 'regular - ends in [cosonant]ies'), array('boxes', 'box', 'regular - ends in s-like sound'), array('slips', 'slip', 'regular'));
# plan our tests
$tests += count($test_plur) + count($test_sing);
plan($tests);
// test the pluralize() method
foreach ($test_plur as $t) {
    list($s, $p, $m) = $t;
    $m = sprintf('pluralize("%s") - %s', $s, $m);
    is(Inflection::pluralize($s), $p, $m);
}
// test the singularize() method
foreach ($test_sing as $t) {
    list($p, $s, $m) = $t;
    $m = sprintf('singularize("%s") - %s', $p, $m);
    is(Inflection::singularize($p), $s, $m);
}
// test the camelize() method
is(Inflection::camelize('test_camelize'), 'TestCamelize', 'camelize("test_camelize") - upper-cases a standard string');
raises(array('Inflection', 'camelize'), array('Test_camelize'), 'AmbiguousInflectionException', 'camelize("Test_camelize") - throws error with multiple results');
// test the decamelize() method
is(Inflection::decamelize('TestDeCamelize'), 'test_de_camelize', 'decamelize("TestDeCamelize") - lower-cases a standard string');
is(Inflection::decamelize('TestABDeCamelize'), 'test_ab_de_camelize', 'decamelize("TestABDeCamelize") - lower-cases an abbreviated string');
is(Inflection::camelize('test_ab_de_camelize'), 'TestABDeCamelize', 'camelize("test_ab_de_camelize") - caches reverse of abbreviated ' . 'strings');
コード例 #4
0
<?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)
{
コード例 #5
0
ファイル: Lexem.php プロジェクト: florinp/dexonline
 /**
  * Called when the model type of a lexem changes from V/VT to something else.
  * Only deletes long infinitives that do not have their own definitions.
  */
 public function deleteLongInfinitive()
 {
     $infl = Inflection::loadLongInfinitive();
     $this->_deleteDependentModels($infl->id, 'F', array('107', '113'));
 }
コード例 #6
0
function loadParticiplesForVerbModel($modelNumber, $participleNumber)
{
    $infl = Inflection::loadParticiple();
    return Model::factory('Lexem')->table_alias('part')->join('InflectedForm', 'part.formNoAccent = i.formNoAccent', 'i')->join('Lexem', 'i.lexemId = infin.id', 'infin')->select('part.*')->where('infin.modelType', 'VT')->where('infin.modelNumber', $modelNumber)->where('i.inflectionId', $infl->id)->where('part.modelType', 'A')->where('part.modelNumber', $participleNumber)->order_by_asc('part.formNoAccent')->find_many();
}
コード例 #7
0
ファイル: basic.php プロジェクト: Zarganwar/inflection
<?php

require_once __DIR__ . '/../src/Inflection.php';
$inflection = new Inflection();
$inflected = $inflection->inflect('desítková soustava');
print "Je potřeba znát " . $inflected[4] . PHP_EOL;
// Je potřeba znát desítkovou soustavu
コード例 #8
0
ファイル: flexiuni.php プロジェクト: florinp/dexonline
util_assertModerator(PRIV_LOC);
$submitButton = util_getRequestParameter('submitButton');
$inflectionIds = util_getRequestParameter('inflectionIds');
$newDescription = util_getRequestParameter('newDescription');
$newModelType = util_getRequestParameter('newModelType');
$deleteInflectionId = util_getRequestParameter('deleteInflectionId');
if ($deleteInflectionId) {
    $infl = Inflection::get_by_id($deleteInflectionId);
    $infl->delete();
    util_redirect('flexiuni');
}
if ($submitButton) {
    // Re-rank the inflections according to the order in $inflectionIds
    $modelTypeMap = array();
    foreach ($inflectionIds as $inflId) {
        $infl = Inflection::get_by_id($inflId);
        $rank = array_key_exists($infl->modelType, $modelTypeMap) ? $modelTypeMap[$infl->modelType] + 1 : 1;
        $modelTypeMap[$infl->modelType] = $rank;
        $infl->rank = $rank;
        $infl->save();
    }
    // Add a new inflection if one is given
    if ($newDescription) {
        $infl = Model::factory('Inflection')->create();
        $infl->description = $newDescription;
        $infl->modelType = $newModelType;
        $infl->rank = $modelTypeMap[$newModelType] + 1;
        $infl->save();
    }
    util_redirect('flexiuni');
}
コード例 #9
0
 /**
  * @dataProvider providerNames
  */
 public function testInflectionNames($name, $env, $expected)
 {
     $inflected = $this->inflection->inflect($name, $env);
     $this->assertSame($expected, $inflected);
 }
コード例 #10
0
ファイル: benchmark.php プロジェクト: Zarganwar/inflection
<?php

$loader = (require __DIR__ . '/vendor/autoload.php');
$sumTimes = 0;
$count = 0;
$words = explode(' ', 'Tato verze dokáže skloňovat i jednoduchá sousloví, jako např. "anaerobní bakterie", "čtyřdobý spalovací motor", nebo "moje slovo", byly odstraněny některé chyby. Nefungují sousloví obsahující druhý pád, spojky a příslovce. Převážná většina slov se vyskloňuje spisovně, případy kdy se vygeneruje nepřesný (hovorový, málo frekventovaný) nebo dokonce nesprávný tvar jsou přesto dosud četné. U slov mužského rodu by bylo obtížné bez poměrně rozsáhlého slovníku rozlišit, zda se má použít životné nebo neživotné skloňování (někdy to také závisí na kontextu), proto je zde potřebný zásah uživatele. Kromě životného a neživotného skloňování by v některých případech bylo třeba rozlišit osobní a neosobní skloňování. Ve verzi 0.97 byla opravena některá nedořešená slova, uživateli byla dána možnost vynutit si změnu rodu, což může být užitečné např. při pokusu o skloňování příjmení. V takovém případě se však zvyšuje pravděpodobnost chyb nebo nepřesností. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod');
for ($i = 0; $i < 10; $i++) {
    $start = microtime(TRUE);
    $lib = new Inflection();
    foreach ($words as $word) {
        $lib->inflect($word);
    }
    $duration = microtime(TRUE) - $start;
    echo count($words) . " words, \t";
    echo number_format($duration, 3) . " seconds, \t";
    echo number_format(memory_get_peak_usage(TRUE) / 1000000.0, 3) . " MB\n";
    $sumTimes += $duration;
    $count++;
}
echo "---------------\n";
$avg = $sumTimes / $count;
echo 'Avg duration:   ' . number_format($avg, 3) . " seconds\n";
コード例 #11
0
ファイル: simple.php プロジェクト: Zarganwar/inflection
<?php

$loader = (require __DIR__ . '/vendor/autoload.php');
$lib = new Inflection();
array_shift($argv);
foreach ($argv as $word) {
    var_dumP($lib->inflect($word));
}
コード例 #12
0
ファイル: lexemEdit.php プロジェクト: florinp/dexonline
function validate($lexem, $original, $variantIds, $meanings)
{
    if (!$lexem->form) {
        FlashMessage::add('Forma nu poate fi vidă.');
    }
    $numAccents = mb_substr_count($lexem->form, "'");
    // Note: we allow multiple accents for lexems like hárcea-párcea
    if ($numAccents && $lexem->noAccent) {
        FlashMessage::add('Ați indicat că lexemul nu necesită accent, dar forma conține un accent.');
    } else {
        if (!$numAccents && !$lexem->noAccent) {
            FlashMessage::add('Adăugați un accent sau debifați câmpul "Necesită accent".');
        }
    }
    foreach ($lexem->getLexemModels() as $lm) {
        $hasS = false;
        $hasP = false;
        for ($i = 0; $i < mb_strlen($lm->restriction); $i++) {
            $c = StringUtil::getCharAt($lm->restriction, $i);
            if ($c == 'T' || $c == 'U' || $c == 'I') {
                if ($lm->modelType != 'V' && $lm->modelType != 'VT') {
                    FlashMessage::add("Restricția <b>{$c}</b> se aplică numai verbelor");
                }
            } else {
                if ($c == 'S') {
                    if ($lm->modelType == 'I' || $lm->modelType == 'T') {
                        FlashMessage::add("Restricția <b>S</b> nu se aplică modelului {$lm->modelType}");
                    }
                    $hasS = true;
                } else {
                    if ($c == 'P') {
                        if ($lm->modelType == 'I' || $lm->modelType == 'T') {
                            FlashMessage::add("Restricția <b>P</b> nu se aplică modelului {$lm->modelType}");
                        }
                        $hasP = true;
                    } else {
                        FlashMessage::add("Restricția <b>{$c}</b> este incorectă.");
                    }
                }
            }
        }
        if ($hasS && $hasP) {
            FlashMessage::add("Restricțiile <b>S</b> și <b>P</b> nu pot coexista.");
        }
        $ifs = $lm->generateInflectedForms();
        if (!is_array($ifs)) {
            $infl = Inflection::get_by_id($ifs);
            FlashMessage::add(sprintf("Nu pot genera flexiunea '%s' conform modelului %s%s", htmlentities($infl->description), $lm->modelType, $lm->modelNumber));
        }
    }
    $variantOf = Lexem::get_by_id($lexem->variantOfId);
    if ($variantOf && !goodForVariantJson($meanings)) {
        FlashMessage::add("Acest lexem este o variantă a lui {$variantOf} și nu poate avea el însuși sensuri. " . "Este permis doar un sens, fără conținut, pentru indicarea surselor și a registrelor de folosire.");
    }
    if ($variantOf && !empty($variantIds)) {
        FlashMessage::add("Acest lexem este o variantă a lui {$variantOf} și nu poate avea el însuși variante.");
    }
    if ($variantOf && $variantOf->id == $lexem->id) {
        FlashMessage::add("Lexemul nu poate fi variantă a lui însuși.");
    }
    foreach ($variantIds as $variantId) {
        $variant = Lexem::get_by_id($variantId);
        if ($variant->id == $lexem->id) {
            FlashMessage::add('Lexemul nu poate fi variantă a lui însuși.');
        }
        if ($variant->variantOfId && $variant->variantOfId != $lexem->id) {
            $other = Lexem::get_by_id($variant->variantOfId);
            FlashMessage::add("\"{$variant}\" este deja marcat ca variantă a lui \"{$other}\".");
        }
        $variantVariantCount = Model::factory('Lexem')->where('variantOfId', $variant->id)->count();
        if ($variantVariantCount) {
            FlashMessage::add("\"{$variant}\" are deja propriile lui variante.");
        }
        $variantMeanings = Model::factory('Meaning')->where('lexemId', $variant->id)->find_many();
        if (!goodForVariant($variantMeanings)) {
            FlashMessage::add("\"{$variant}\" are deja propriile lui sensuri.");
        }
    }
    if ($lexem->structStatus == Lexem::STRUCT_STATUS_DONE && $original->structStatus != Lexem::STRUCT_STATUS_DONE && !util_isModerator(PRIV_EDIT)) {
        FlashMessage::add("Doar moderatorii pot marca structurarea drept terminată. Vă rugăm să folosiți valoarea „așteaptă moderarea”.");
    }
    return FlashMessage::getMessage() == null;
}
コード例 #13
0
        $lexem->deleteLongInfinitive();
    }
    $lexem->save();
    // There are two reasons to regenerate the paradigm: the model has changed
    // or the form has changed. It's easier to do it every time.
    $lexem->regenerateParadigm();
    log_userLog("Edited lexem {$lexem->id} ({$lexem->form})");
    util_redirect("lexemEdit.php?lexemId={$lexem->id}");
}
$definitions = Definition::loadByLexemId($lexem->id);
$searchResults = SearchResult::mapDefinitionArray($definitions);
$definitionLexem = mb_strtoupper(AdminStringUtil::internalize($lexem->form, false));
// Generate new inflected forms, but do not overwrite the old ones.
$ifs = $lexem->generateParadigm();
if (!is_array($ifs)) {
    $infl = Inflection::get_by_id($ifs);
    if (!$errorMessage) {
        $errorMessage = "Nu pot genera flexiunea '" . htmlentities($infl->description) . "' " . "conform modelului {$lexem->modelType}{$lexem->modelNumber}.";
    }
} else {
    $ifMap = InflectedForm::mapByInflectionRank($ifs);
    smarty_assign('ifMap', $ifMap);
    smarty_assign('searchResults', $searchResults);
}
$models = FlexModel::loadByType($lexem->modelType);
$sources = LexemSources::getSourceArrayChecked($lexem->source);
$sourceNames = LexemSources::getNamesOfSources($lexem->source);
$canEditForm = !$lexem->isLoc || util_isModerator(PRIV_LOC);
smarty_assign('lexem', $lexem);
smarty_assign('sources', $sources);
smarty_assign('sourceNames', $sourceNames);