mirror of
https://github.com/retailcrm/NameCaseLib.git
synced 2024-12-05 03:16:06 +03:00
[0.4] Небольшие исправления, новые тесты для украинского языка.
This commit is contained in:
parent
f5363c0a94
commit
6612b942d5
@ -716,7 +716,7 @@ class NCLNameCaseUa extends NCLNameCaseCore implements NCLNameCaseInterface
|
||||
}
|
||||
|
||||
//Исключения
|
||||
if ($this->inNames($namepart, array('Лев', 'Гаїна', 'Афіна', 'Антоніна', 'Ангеліна', 'Альвіна', 'Альбіна', 'Аліна', 'Павло', 'Олесь', 'Микола')))
|
||||
if ($this->inNames($namepart, array('Лев', 'Гаїна', 'Афіна', 'Антоніна', 'Ангеліна', 'Альвіна', 'Альбіна', 'Аліна', 'Павло', 'Олесь', 'Микола', 'Мая')))
|
||||
{
|
||||
$first+=10;
|
||||
}
|
||||
|
@ -500,7 +500,7 @@ class NCLNameCaseCore extends NCL
|
||||
* @param string $fullname строка, для которой необходимо определить формат
|
||||
* @return array формат в котором записано имя массив типа <var>$this->words</var>
|
||||
*/
|
||||
public function splitFullName($fullname)
|
||||
private function splitFullName($fullname)
|
||||
{
|
||||
|
||||
$fullname = trim($fullname);
|
||||
@ -522,6 +522,27 @@ class NCLNameCaseCore extends NCL
|
||||
return $this->words;
|
||||
}
|
||||
|
||||
/**
|
||||
* Разбивает строку <var>$fullname</var> на слова и возвращает формат в котором записано имя
|
||||
* <b>Формат:</b>
|
||||
* - S - Фамилия
|
||||
* - N - Имя
|
||||
* - F - Отчество
|
||||
* @param string $fullname строка, для которой необходимо определить формат
|
||||
* @return string формат в котором записано имя
|
||||
*/
|
||||
public function getFullNameFormat($fullname)
|
||||
{
|
||||
$this->fullReset();
|
||||
$words = $this->splitFullName($fullname);
|
||||
$format = '';
|
||||
foreach ($words as $word)
|
||||
{
|
||||
$format .= $word->getNamePart() . ' ';
|
||||
}
|
||||
return $format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Склоняет слово <var>$word</var> по нужным правилам в зависимости от пола и типа слова
|
||||
* @param NCLNameCaseWord $word слово, которое нужно просклонять
|
||||
@ -765,22 +786,9 @@ class NCLNameCaseCore extends NCL
|
||||
$length = NCLStr::strlen($format);
|
||||
$result = array();
|
||||
$cases = array();
|
||||
for ($i = 0; $i < $length; $i++)
|
||||
{
|
||||
$symbol = NCLStr::substr($format, $i, 1);
|
||||
if ($symbol == 'S')
|
||||
{
|
||||
$cases['S'] = $this->getSecondNameCase();
|
||||
}
|
||||
elseif ($symbol == 'N')
|
||||
{
|
||||
$cases['N'] = $this->getFirstNameCase();
|
||||
}
|
||||
elseif ($symbol == 'F')
|
||||
{
|
||||
$cases['F'] = $this->getFatherNameCase();
|
||||
}
|
||||
}
|
||||
$cases['S'] = $this->getCasesConnected($this->index['S']);
|
||||
$cases['N'] = $this->getCasesConnected($this->index['N']);
|
||||
$cases['F'] = $this->getCasesConnected($this->index['F']);
|
||||
|
||||
for ($curCase = 0; $curCase < $this->CaseCount; $curCase++)
|
||||
{
|
||||
|
@ -32,7 +32,7 @@ interface NCLNameCaseInterface
|
||||
|
||||
public function genderAutoDetect();
|
||||
|
||||
public function splitFullName($fullname);
|
||||
public function getFullNameFormat($fullname);
|
||||
|
||||
public function getFirstNameCase($number=null);
|
||||
|
||||
|
54
Tests/Library/CrazyTestFatherboy.php
Normal file
54
Tests/Library/CrazyTestFatherboy.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
require_once dirname(__FILE__) . '/../../Library/NCL.NameCase.ua.php';
|
||||
|
||||
|
||||
class NCLNameCaseUaTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var NCLNameCaseRu
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new NCLNameCaseUa;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testCrazy0()
|
||||
{
|
||||
$this->assertEquals(explode(',','Олександрович,Олександровича,Олександровичу,Олександровича,Олександровичем,Олександровичу,Олександровичу'), $this->object->q('Олександрович'));
|
||||
}
|
||||
public function testCrazy1()
|
||||
{
|
||||
$this->assertEquals(explode(',','Миколайович,Миколайовича,Миколайовичу,Миколайовича,Миколайовичем,Миколайовичу,Миколайовичу'), $this->object->q('Миколайович'));
|
||||
}
|
||||
public function testCrazy2()
|
||||
{
|
||||
$this->assertEquals(explode(',','Кузьмич,Кузьмича,Кузьмичу,Кузьмича,Кузьмичем,Кузьмичу,Кузьмичу'), $this->object->q('Кузьмич'));
|
||||
}
|
||||
public function testCrazy3()
|
||||
{
|
||||
$this->assertEquals(explode(',','Петрович,Петровича,Петровичу,Петровича,Петровичем,Петровичу,Петровичу'), $this->object->q('Петрович'));
|
||||
}
|
||||
public function testCrazy4()
|
||||
{
|
||||
$this->assertEquals(explode(',','Ілліч,Ілліча,Іллічу,Ілліча,Іллічем,Іллічу,Іллічу'), $this->object->q('Ілліч'));
|
||||
}
|
||||
|
||||
}
|
46
Tests/Library/CrazyTestFathergirl.php
Normal file
46
Tests/Library/CrazyTestFathergirl.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
require_once dirname(__FILE__) . '/../../Library/NCL.NameCase.ua.php';
|
||||
|
||||
|
||||
class NCLNameCaseUaTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var NCLNameCaseRu
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new NCLNameCaseUa;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testCrazy0()
|
||||
{
|
||||
$this->assertEquals(explode(',','Василівна,Василівни,Василівні,Василівну,Василівною,Василівні,Василівно'), $this->object->q('Василівна'));
|
||||
}
|
||||
public function testCrazy1()
|
||||
{
|
||||
$this->assertEquals(explode(',','Антонівна,Антонівни,Антонівні,Антонівну,Антонівною,Антонівні,Антонівно'), $this->object->q('Антонівна'));
|
||||
}
|
||||
public function testCrazy2()
|
||||
{
|
||||
$this->assertEquals(explode(',','Яківна,Яківни,Яківні,Яківну,Яківною,Яківні,Яківно'), $this->object->q('Яківна'));
|
||||
}
|
||||
|
||||
}
|
2070
Tests/Library/CrazyTestNamesboy.php
Normal file
2070
Tests/Library/CrazyTestNamesboy.php
Normal file
File diff suppressed because it is too large
Load Diff
1346
Tests/Library/CrazyTestNamesgirl.php
Normal file
1346
Tests/Library/CrazyTestNamesgirl.php
Normal file
File diff suppressed because it is too large
Load Diff
2998
Tests/Library/CrazyTestSirnamesboy.php
Normal file
2998
Tests/Library/CrazyTestSirnamesboy.php
Normal file
File diff suppressed because it is too large
Load Diff
2930
Tests/Library/CrazyTestSirnamesgirl.php
Normal file
2930
Tests/Library/CrazyTestSirnamesgirl.php
Normal file
File diff suppressed because it is too large
Load Diff
95
Tests/TestGenerator/CrazyNCLNameCaseUAGenerator.php
Normal file
95
Tests/TestGenerator/CrazyNCLNameCaseUAGenerator.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
class TestGeneratorDB
|
||||
{
|
||||
|
||||
public $maintemplate;
|
||||
public $testtemplate;
|
||||
public $resultArr = array();
|
||||
private $gender;
|
||||
private $tests;
|
||||
private $count = 0;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
mysql_connect('localhost', 'root', '');
|
||||
mysql_select_db('names');
|
||||
mysql_set_charset('utf8');
|
||||
//$this->resultArr[]=file('Names/boy_full_result.txt');
|
||||
//$this->resultArr[]=file('Names/girl_full_result.txt');
|
||||
}
|
||||
|
||||
public function generate($fname, $gender)
|
||||
{
|
||||
$this->maintemplate = file_get_contents('Template/NCLNameCaseUaTest.main');
|
||||
$this->testtemplate = file_get_contents('Template/NCLNameCaseCrazyTest.test');
|
||||
//$this->resultArr=file('Names/'.$gender.'_full_result.txt');
|
||||
$this->count = 0;
|
||||
$fnewname = $fname;
|
||||
if ($fnewname == 'Sirnames')
|
||||
{
|
||||
$fnewname = 'second';
|
||||
}
|
||||
if ($gender == 'boy')
|
||||
{
|
||||
$this->gender = 1;
|
||||
$this->dbTable = 'boy' . strtolower($fnewname);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->gender = 2;
|
||||
$this->dbTable = 'girl' . strtolower($fnewname);
|
||||
}
|
||||
$this->resultArr = mysql_query("SELECT * FROM {$this->dbTable}");
|
||||
//foreach ($this->resultArr as $key=>$value)
|
||||
//{
|
||||
//$this->gender=$key+1;
|
||||
$all = array();
|
||||
while ($row = mysql_fetch_assoc($this->resultArr))
|
||||
{
|
||||
//$tmpnames=explode("#",trim(str_replace('ё','е',$name)));
|
||||
|
||||
$firstRes = array();
|
||||
$secondRes = array();
|
||||
$fatherRes = array();
|
||||
$secondRes = $fatherRes = $firstRes = explode('#', $row['nameCase']);
|
||||
if ($row['nameCase'])
|
||||
{
|
||||
$this->generateTest($firstRes);
|
||||
}
|
||||
}
|
||||
//}
|
||||
$res = str_replace('{% tests %}', $this->tests, $this->maintemplate);
|
||||
$res = str_replace('{% name %}', $fname, $res);
|
||||
file_put_contents('../Library/CrazyTest' . $fname . $gender . '.php', $res);
|
||||
}
|
||||
|
||||
private function generateTest($firstRes)
|
||||
{
|
||||
$tpl = $this->testtemplate;
|
||||
$tpl = str_replace('{% id %}', $this->count, $tpl);
|
||||
|
||||
$tpl = str_replace('{% name %}', $firstRes[0], $tpl);
|
||||
$tpl = str_replace('{% OK %}', implode(',', $firstRes), $tpl);
|
||||
|
||||
$this->tests.=$tpl;
|
||||
$this->count++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$p = new TestGeneratorDB;
|
||||
$p->generate('Names', 'boy');
|
||||
$p = new TestGeneratorDB;
|
||||
$p->generate('Names', 'girl');
|
||||
|
||||
$p = new TestGeneratorDB;
|
||||
$p->generate('Father', 'boy');
|
||||
$p = new TestGeneratorDB;
|
||||
$p->generate('Father', 'girl');
|
||||
|
||||
$p = new TestGeneratorDB;
|
||||
$p->generate('Sirnames', 'boy');
|
||||
$p = new TestGeneratorDB;
|
||||
$p->generate('Sirnames', 'girl');
|
||||
?>
|
5
Tests/TestGenerator/Template/NCLNameCaseCrazyTest.test
Normal file
5
Tests/TestGenerator/Template/NCLNameCaseCrazyTest.test
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
public function testCrazy{% id %}()
|
||||
{
|
||||
$this->assertEquals(explode(',','{% OK %}'), $this->object->q('{% name %}'));
|
||||
}
|
@ -4,6 +4,7 @@ header('Content-type: text/html; charset=utf-8');
|
||||
require '../Library/NCL.NameCase.ua.php';
|
||||
$ob = new NCLNameCaseUa;
|
||||
|
||||
print_r($ob->q("Афонін Микола Сергійович"));
|
||||
print_r($ob->q("Іванцов Микола Микита Андрій Петро Михайлович Миколайович Антонівна"));
|
||||
echo $ob->getFullNameFormat("Мая");
|
||||
//echo $ob->getSecondNameRule();
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user