-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from chineseboost/hg/hanzi-numerals-measure
Fix numeral + measure word conversion
- Loading branch information
Showing
5 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<?php return ['/(我|你|您|他|她|它|牠|祂|谁|誰[们們]?)([把将])(.{1,20})落/u'=>'$1$2$3 la4','/得([不得]?)到/u'=>'de2$1dao4','/(.{1,2})\1{1}地/u'=>'$1$1 de5','/([么|麽].)地/u'=>'$1 de5','/([一|两|那|这|這|此].)地/u'=>'$1 di4','/不([\p{Han}]{1,4})地/u'=>'bu4 $1 de5','/(一|二|三|四|五|六|七|八|九|十|百|千|万|亿)+个/u'=>'$1 ge5',]; | ||
<?php return ['/(我|你|您|他|她|它|牠|祂|谁|誰[们們]?)([把将])(.{1,20})落/u'=>'$1$2$3 la4','/得([不得]?)到/u'=>'de2$1dao4','/(.{1,2})\1{1}地/u'=>'$1$1 de5','/([么|麽].)地/u'=>'$1 de5','/([一|两|那|这|這|此].)地/u'=>'$1 di4','/不([\p{Han}]{1,4})地/u'=>'bu4 $1 de5','/((?>一|二|三|四|五|六|七|八|九|十|百|千|万|亿)+)个/u'=>'$1 ge5',]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
tests/Unit/Hanzi/HanziSentence/HanziSentenceNumeralMeasureTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Pinyin\Tests\Unit\Hanzi\HanziSentence; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Pinyin\Hanzi\HanziSentence; | ||
|
||
class HanziSentenceNumeralMeasureTest extends TestCase | ||
{ | ||
/** | ||
* @param string $sentence | ||
* @param string $expectedPinyin | ||
* | ||
* @dataProvider numeralMeasurePinyinProvider | ||
*/ | ||
public function testNumeralMeasurePinyin( | ||
string $sentence, | ||
string $expectedPinyin | ||
): void { | ||
// Given a hanzi sentence containing numerals and a measure word; | ||
$hanziSentence = new HanziSentence($sentence); | ||
|
||
// When we convert it to pinyin; | ||
$pinyin = $hanziSentence->asPinyin(); | ||
|
||
// Then we should get the correct pinyin. | ||
self::assertEquals($expectedPinyin, (string) $pinyin); | ||
} | ||
|
||
/** | ||
* @return array[] | ||
*/ | ||
public static function numeralMeasurePinyinProvider(): array | ||
{ | ||
return [ | ||
[ | ||
'一亿三千两百万八千六百七十二个东西', | ||
'Yi1 yi4 san1 qian1 liang3 bai3 wan4 ba1 qian1 liu4 bai3 qi1 shi2 er4 ge5 dong1xi1', | ||
], | ||
[ | ||
'两百五十一个人', | ||
'Liang3 bai3 wu3 shi2 yi1 ge5 ren2', | ||
], | ||
]; | ||
} | ||
} |