From 50a422464e1601f287c9f3744800d5c39e37717d Mon Sep 17 00:00:00 2001 From: Andriy Chaika Date: Sat, 2 Jul 2011 14:23:03 +0300 Subject: [PATCH] =?UTF-8?q?[0.3.1]=20[UKR]=20=D0=A0=D0=B0=D1=81=D0=BF?= =?UTF-8?q?=D0=BE=D0=B7=D0=BD=D0=B0=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=84?= =?UTF-8?q?=D0=B0=D0=BC=D0=B8=D0=BB=D0=B8=D0=B8=20=D0=B8=D0=BC=D1=8F=20?= =?UTF-8?q?=D0=BE=D1=82=D1=87=D0=B5=D1=81=D1=82=D0=B2=D0=B0=20END?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Library/NCL.NameCase.ua.php | 8 +- Tests/AutoTest/Endings/BatchTester.php | 113 +++++++++++++-------- Tests/AutoTest/Endings/EndingsCompiler.php | 1 + 3 files changed, 74 insertions(+), 48 deletions(-) diff --git a/Library/NCL.NameCase.ua.php b/Library/NCL.NameCase.ua.php index 1c5bbc0..973eacc 100644 --- a/Library/NCL.NameCase.ua.php +++ b/Library/NCL.NameCase.ua.php @@ -780,7 +780,7 @@ class NCLNameCaseUa extends NCLNameCaseCore implements NCLNameCaseInterface } //Похоже на имя - if (in_array($LastThree, array('тин')) or in_array($LastFour, array('ьмич', 'юбов'))) + if (in_array($LastThree, array('тин' /*{endings_sirname3}*/)) or in_array($LastFour, array('ьмич', 'юбов', 'івна', 'явка', 'орив', 'кіян' /*{endings_sirname4}*/))) { $first+=0.5; } @@ -792,17 +792,17 @@ class NCLNameCaseUa extends NCLNameCaseCore implements NCLNameCaseInterface } //похоже на фамилию - if (in_array($LastTwo, array('ов', 'ін', 'ев', 'єв', 'ий', 'ин', 'ой', 'ко', 'ук', 'як', 'ца', 'их', 'ик', 'ун', 'ок', 'ша', 'ая', 'га', 'єк', 'аш', 'ив', 'юк', 'ус', 'це', 'ак', 'бр', 'яр', 'іл', 'ів', 'ич', 'сь', 'ей', 'нс', 'яс', 'ер', 'ай', 'ян', 'ах', 'ць', 'ющ', 'іс', 'ач', 'уб', 'ох', 'юх','ут','ча','ул','вк','зь' /*{endings2}*/))) + if (in_array($LastTwo, array('ов', 'ін', 'ев', 'єв', 'ий', 'ин', 'ой', 'ко', 'ук', 'як', 'ца', 'их', 'ик', 'ун', 'ок', 'ша', 'ая', 'га', 'єк', 'аш', 'ив', 'юк', 'ус', 'це', 'ак', 'бр', 'яр', 'іл', 'ів', 'ич', 'сь', 'ей', 'нс', 'яс', 'ер', 'ай', 'ян', 'ах', 'ць', 'ющ', 'іс', 'ач', 'уб', 'ох', 'юх','ут','ча','ул','вк','зь', 'уц', 'їн' /*{endings_name2}*/))) { $second+=0.4; } - if (in_array($LastThree, array('ова', 'ева', 'єва', 'тих', 'рик', 'вач', 'аха', 'шен', 'мей', 'арь', 'вка', 'шир', 'бан', 'чий', 'іна', 'їна', 'ька', 'ань', 'ива', 'аль','ура','ран','ало','ола','кур','оба','оль','нта','зій','ґан','іло','шта', 'юпа', 'рна', 'бла', 'еїн', 'има', 'мар', 'кар', 'оха', 'чур', 'ниш', 'ета', 'тна', 'зур', 'нір', 'йма', 'орж', 'рба' /*{endings3}*/))) + if (in_array($LastThree, array('ова', 'ева', 'єва', 'тих', 'рик', 'вач', 'аха', 'шен', 'мей', 'арь', 'вка', 'шир', 'бан', 'чий', 'іна', 'їна', 'ька', 'ань', 'ива', 'аль','ура','ран','ало','ола','кур','оба','оль','нта','зій','ґан','іло','шта', 'юпа', 'рна', 'бла', 'еїн', 'има', 'мар', 'кар', 'оха', 'чур', 'ниш', 'ета', 'тна', 'зур', 'нір', 'йма', 'орж', 'рба', 'іла', 'лас', 'дід', 'роз', 'аба', 'лест', 'мара', 'обка', 'рока', 'сика', 'одна', 'нчар', 'вата', 'ндар', 'грій' /*{endings_name3}*/))) { $second+=0.4; } - if (in_array($LastFour, array('ьник', 'нчук', 'тник', 'кирь', 'ский', 'шена', 'шина', 'вина', 'нина' /*{endings4}*/))) + if (in_array($LastFour, array('ьник', 'нчук', 'тник', 'кирь', 'ский', 'шена', 'шина', 'вина', 'нина', 'гана', 'гана', 'хній', 'зюба', 'орош', 'орон', 'сило', 'руба' /*{endings_name4}*/))) { $second+=0.4; } diff --git a/Tests/AutoTest/Endings/BatchTester.php b/Tests/AutoTest/Endings/BatchTester.php index 0e8d19b..98ad884 100644 --- a/Tests/AutoTest/Endings/BatchTester.php +++ b/Tests/AutoTest/Endings/BatchTester.php @@ -9,73 +9,98 @@ require 'EndingsCompiler.php'; class BatchTester { + private $compiler; private $mode; - public $epsilon; - - public function __construct($mode) + + public function __construct($mode, $direction) { - copy('../../../Library/NCL.NameCase.core.php','compiled/NCL.NameCase.core.php'); - $testPHP = file_get_contents('../../Library/NameSplitUAname.php'); + copy('../../../Library/NCL.NameCase.core.php', 'compiled/NCL.NameCase.core.php'); + $testPHP = file_get_contents('../../Library/NameSplitUA' . $direction . '.php'); $testPHP = str_replace("require_once dirname(__FILE__) . '/../../Library/NCL.NameCase.ua.php';", "require_once dirname(__FILE__) . '/NCL.NameCase.ua.php';", $testPHP); file_put_contents('compiled/Test.php', $testPHP); - + $this->compiler = new EndingsCompiler($mode); $this->mode = $mode; $this->compiler->compile(); - + $this->epsilon = $this->runTest(); } - + public function testText($ending) { $this->compiler->compile($ending); - + return $this->runTest(); } - + public function runTest() { exec("phpunit compiled/Test.php", $output); - - preg_match_all('#Tests: ([\d]+), Assertions: ([\d]+), Failures: ([\d]+).#is', $output[count($output)-1], $found); - $tests = (float)$found[2][0]; - $bad = (float)$found[3][0]; - - //var_dump($tests); - //var_dump(($bad/$tests)); - // print_r($found); - //echo $bad." ".$tests; - return (1-($bad/$tests)); + + preg_match_all('#Tests: ([\d]+), Assertions: ([\d]+), Failures: ([\d]+).#is', $output[count($output) - 1], $found); + $tests = (float) $found[2][0]; + $bad = (float) $found[3][0]; + + return (1 - ($bad / $tests)); } + } -$good = array(); -$bad = array(); -$tester = new BatchTester('endings3'); +$direction = "sirname"; //sirname -$epsilon = $tester->epsilon; - -$endings = file('endings3.txt'); - -foreach ($endings as $ending) +for ($num = 2; $num <= 4; $num++) { - $persent = $tester->testText(trim($ending)); - echo trim($ending)." - ".$persent."\n"; - - if($persent==$epsilon) - { - $good[] = $ending; - } - else - { - $bad[] = $ending; - } -} + $good = array(); + $bad = array(); + $mode = 'endings_'.$direction . $num; + echo "\n===========\n{$mode}\n===========\n"; + $tester = new BatchTester($mode, $direction); -echo "\n\n GOOD"; -print_r($good); -echo "\n\n BAD"; -print_r($bad); + $epsilon = $tester->epsilon; + + $endings = file($mode . '.txt'); + + + $old = array(); + foreach ($endings as $ending) + { + if (mb_substr(trim($ending), 0, 1, 'utf-8') != '#') + { + $persent = $tester->testText(trim($ending)); + echo trim($ending) . " - " . $persent . "\n"; + + if ($persent >= $epsilon) + { + $good[] = trim($ending); + } + else + { + $bad[] = trim($ending); + } + } + else + { + $old[] = $ending; + } + } + + + $content = implode('', $old); + if ($good) + { + echo "\nGOOD \n"; + echo ", '" . implode("', '", $good) . "'"; + } + if ($bad) + { + echo "\nBAD \n"; + echo implode(" ", $bad); + $content .= '#'.implode("\n#", $bad); + } + //file_put_contens($mode . '.txt', '#'.implode("\n#", $bad)); + file_put_contents($mode . '.txt', $content); +} +echo "\n\n"; ?> diff --git a/Tests/AutoTest/Endings/EndingsCompiler.php b/Tests/AutoTest/Endings/EndingsCompiler.php index 9642fbd..d9e6fbc 100644 --- a/Tests/AutoTest/Endings/EndingsCompiler.php +++ b/Tests/AutoTest/Endings/EndingsCompiler.php @@ -17,6 +17,7 @@ class EndingsCompiler public function __construct($mode) { $this->template = file_get_contents($this->sourceFile); + $this->mode = $mode; } private function save()