Beispiel #1
0
 public static function create($form = null, $modelType = null, $modelNumber = null, $restriction = '')
 {
     $l = Model::factory('Lexem')->create();
     if ($form) {
         $l->form = $form;
         $l->formNoAccent = str_replace("'", '', $form);
         $l->formUtf8General = $l->formNoAccent;
         $l->reverse = StringUtil::reverse($l->formNoAccent);
     }
     $l->description = '';
     $l->tags = '';
     $l->source = '';
     $l->modelType = $modelType;
     $l->modelNumber = $modelNumber;
     $l->restriction = $restriction;
     $l->comment = '';
     $l->isLoc = false;
     $l->noAccent = false;
     return $l;
 }
Beispiel #2
0
                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}");
}
$reverseSuffix = StringUtil::reverse($suffix);
RecentLink::createOrUpdate("Etichetare asistată: -{$suffix}");
$numLabeled = Model::factory('Lexem')->table_alias('l')->join('LexemModel', 'lm.lexemId = l.id', 'lm')->where_not_equal('lm.modelType', 'T')->where_like('l.reverse', "{$reverseSuffix}%")->count();
// Collect all the models that appear in at least 5% of the already
// labeled lexems. Always select at least one model, in the unlikely case
// that no model has over 5%.
$models = array();
$hasInvariableModel = false;
$dbResult = db_execute("select canonical, modelNumber, count(*) as c " . "from Lexem " . "join LexemModel on lexemId = Lexem.id " . "join ModelType on modelType = code " . "where modelType != 'T' " . "and reverse like '{$reverseSuffix}%' " . "group by canonical, modelNumber " . "order by c desc", PDO::FETCH_ASSOC);
foreach ($dbResult as $row) {
    $modelType = $row['canonical'];
    $modelNumber = $row['modelNumber'];
    $count = $row['c'];
    if (!count($models) || $count / $numLabeled >= 0.05) {
        if ($modelType == 'V' || $modelType == 'VT') {
            $m = Model::factory('FlexModel')->where('modelType', 'V')->where('number', $modelNumber)->find_one();
 /**
  * @test
  */
 public function testReverse_Multibyte()
 {
     // 現在の実装のままだとテストが通らない
     $text = 'テスト';
     $this->assertThat(StringUtil::reverse($text), $this->equalTo('トステ'));
 }
 $parts = preg_split('/_/', $name);
 assert(count($parts) == 2);
 $lexemId = $parts[1];
 if (!array_key_exists($lexemId, $lexemMap)) {
     $lexemMap[$lexemId] = Lexem::get_by_id($lexemId);
 }
 $l = $lexemMap[$lexemId];
 switch ($parts[0]) {
     case 'caps':
         if (StringUtil::startsWith($l->form, "'")) {
             $l->form = "'" . AdminStringUtil::capitalize(mb_substr($l->form, 1));
         } else {
             $l->form = AdminStringUtil::capitalize($l->form);
         }
         $l->formNoAccent = str_replace("'", '', $l->form);
         $l->reverse = StringUtil::reverse($l->formNoAccent);
         break;
     case 'singular':
         $l->restriction = 'S';
         break;
     case 'plural':
         $l->restriction = 'P';
         break;
     case 'model':
         if ($value) {
             $m = Model::factory('FlexModel')->where_raw("concat(modelType, number) = '{$value}'")->find_one();
             if ($m) {
                 $oldModelType = $l->modelType;
                 $oldModelNumber = $l->modelNumber;
                 $l->modelType = $m->modelType;
                 $l->modelNumber = $m->number;
Beispiel #5
0
 public function save()
 {
     $this->formUtf8General = $this->formNoAccent;
     $this->reverse = StringUtil::reverse($this->formNoAccent);
     $this->charLength = mb_strlen($this->formNoAccent);
     $this->consistentAccent = strpos($this->form, "'") !== false ^ $this->noAccent;
     // It is important for empty fields to be null, not "".
     // This allows the admin report for lexems *with* comments to run faster.
     if ($this->comment == '') {
         $this->comment = null;
     }
     if (!$this->number) {
         $this->number = null;
     }
     parent::save();
 }
Beispiel #6
0
assertEquals('abcúùû', mb_strtolower('ABCÚÙÛ'));
assertEquals('ÿ', mb_strtolower('Ÿ'));
assertEquals('MAMA', mb_strtoupper('MAMA'));
assertEquals('MAMA', mb_strtoupper('MAmA'));
assertEquals('MAMA', mb_strtoupper('MAmA'));
assertEquals('MAMĂ', mb_strtoupper('MamĂ'));
assertEquals('MAMĂ', mb_strtoupper('maMă'));
assertEquals('ABCÚÙÛ', mb_strtoupper('abcúùû'));
assertEquals('Ÿ', mb_strtoupper('ÿ'));
// Check that we're using the right encoding
assertEquals(mb_strlen('íÍìÌîÎ'), 6);
assertEquals(mb_substr('íÍìÌîÎ', 3, 2), 'Ìî');
// Test string reversal
assertEquals('cba', StringUtil::reverse('abc'));
assertEquals('țșîâă', StringUtil::reverse('ăâîșț'));
assertEquals('ȚȘÎÂĂ', StringUtil::reverse('ĂÂÎȘȚ'));
// Check suffix removals
assertEquals(AdminStringUtil::removeKnownSuffixes(''), '');
assertEquals(AdminStringUtil::removeKnownSuffixes('mama'), 'mama');
assertEquals(AdminStringUtil::removeKnownSuffixes('farmaciei'), 'farmacie');
assertEquals(AdminStringUtil::removeKnownSuffixes('dealului'), 'deal');
assertEquals(AdminStringUtil::removeKnownSuffixes('dealul'), 'deal');
assertEquals(AdminStringUtil::removeKnownSuffixes('dealuri'), 'deal');
assertEquals(AdminStringUtil::removeKnownSuffixes('dealurilor'), 'deal');
assertEquals(AdminStringUtil::removeKnownSuffixes('copacilor'), 'copac');
assertEquals(AdminStringUtil::removeKnownSuffixes('bogată'), 'bogat');
assertEquals(AdminStringUtil::removeKnownSuffixes('bogate'), 'bogat');
assertEquals(AdminStringUtil::getLastWord(''), '');
assertEquals(AdminStringUtil::getLastWord('foo'), 'foo');
assertEquals(AdminStringUtil::getLastWord('foo bar'), 'bar');
assertEquals(AdminStringUtil::getLastWord('foo bar (@1@)'), 'bar');