From 2221355b58d43f4c5dd13355acdd9c544c8e5e9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=9B=E4=B8=9E=E5=AE=8F?= Date: Tue, 24 Jul 2018 16:13:45 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=8F=B0=E7=81=A3=E6=A4=8D=E7=89=A9?= =?UTF-8?q?=E5=90=8D=E5=BD=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 1 + README.md | 13 +++- tox.ini | 7 +++ ...15\347\211\251\345\220\215\345\275\231.py" | 61 +++++++++++++++++++ ...15\347\211\251\345\220\215\345\275\231.py" | 10 +++ ...72\347\244\216\350\252\236\345\217\245.py" | 2 +- 6 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 "\345\214\257\345\205\245/management/commands/\345\217\260\347\201\243\346\244\215\347\211\251\345\220\215\345\275\231.py" create mode 100644 "\350\251\246\351\251\227/test\345\217\260\347\201\243\346\244\215\347\211\251\345\220\215\345\275\231.py" diff --git a/.travis.yml b/.travis.yml index 3e6c162..ececcc9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ env: - TOX_ENV=詞彙分級 - TOX_ENV=教育部臺灣閩南語字詞頻調查工作 - TOX_ENV=itaigi +- TOX_ENV=台灣植物名彙 - TOX_ENV=台灣白話基礎語句 addons: apt: diff --git a/README.md b/README.md index aa8d96d..f9e4a12 100644 --- a/README.md +++ b/README.md @@ -57,9 +57,18 @@ python manage.py 詞彙分級 python manage.py 教育部臺灣閩南語字詞頻調查工作 ``` +### [台灣植物名彙](http://ip194097.ntcu.edu.tw/memory/TGB/thak.asp?id=59&page=4) +- 形式:羅馬字、華語漢字 +- 句數:354詞(2018/07/24) +- 語料:[Github](https://github.com/Taiwanese-Corpus/Syuniti-Sasaki_1928_List-of-Plants-of-Formosa) +``` +python manage.py 台灣植物名彙 +``` + + ### [台灣白話基礎語句](http://ip194097.ntcu.edu.tw/memory/TGB/thak.asp?id=862) -- 形式:全漢、全羅 -- 句數:61354句(2018/07/05) +- 形式:羅馬字、華語漢字 +- 句數:61354詞翻譯對照(2018/07/24) - 語料:[Github](https://github.com/Taiwanese-Corpus/Ko-Chek-hoan-Tan-Pang-tin_1956_Basic-Vocabulary-for-Colloquial-Taiwanese) ``` python manage.py 台灣白話基礎語句 diff --git a/tox.ini b/tox.ini index 1f0ac77..dac3d2a 100644 --- a/tox.ini +++ b/tox.ini @@ -74,8 +74,15 @@ deps = commands= coverage run --source=匯入 manage.py test 試驗.testItaigi +[testenv:台灣植物名彙] +deps = + coverage +commands= + coverage run --source=匯入 manage.py test 試驗.test台灣植物名彙 + [testenv:台灣白話基礎語句] deps = coverage commands= coverage run --source=匯入 manage.py test 試驗.test台灣白話基礎語句 + \ No newline at end of file diff --git "a/\345\214\257\345\205\245/management/commands/\345\217\260\347\201\243\346\244\215\347\211\251\345\220\215\345\275\231.py" "b/\345\214\257\345\205\245/management/commands/\345\217\260\347\201\243\346\244\215\347\211\251\345\220\215\345\275\231.py" new file mode 100644 index 0000000..4ed3be4 --- /dev/null +++ "b/\345\214\257\345\205\245/management/commands/\345\217\260\347\201\243\346\244\215\347\211\251\345\220\215\345\275\231.py" @@ -0,0 +1,61 @@ +from csv import DictReader +import io +from urllib.request import urlopen + + +from 臺灣言語工具.解析整理.拆文分析器 import 拆文分析器 +from 臺灣言語服務.models import 訓練過渡格式 +from 匯入.指令 import 匯入枋模 +from 臺灣言語工具.解析整理.解析錯誤 import 解析錯誤 + + +class Command(匯入枋模): + help = 'http://ip194097.ntcu.edu.tw/memory/TGB/thak.asp?id=862' + + 公家內容 = { + '來源': '台灣白話基礎語句', + '種類': '字詞', + '年代': '1956', + } + github網址 = ( + 'https://github.com/Taiwanese-Corpus/' + 'Ko-Chek-hoan-Tan-Pang-tin_1956_Basic-Vocabulary-for-Colloquial-Taiwanese/' + 'raw/master/ChhoeTaigi_TaioanPehoeKichhooGiku.csv' + ) + + def 全部資料(self, *args, **參數): + 全部資料 = [] + 匯入數量 = 0 + for 羅馬字, 華語 in self.github資料(): + 全部資料.append( + 訓練過渡格式( + 文本=羅馬字, + 外文=華語, + **self.公家內容 + ) + ) + + 匯入數量 += 1 + if 匯入數量 % 1000 == 0: + self.stdout.write('匯入 {} 筆'.format(匯入數量)) + return 全部資料 + + def github資料(self): + with urlopen(self.github網址) as 檔: + with io.StringIO(檔.read().decode()) as 資料: + for row in DictReader(資料): + 羅馬字1 = row['poj_unicode'].strip() + 羅馬字2 = row['poj_other_unicode'].strip() + 華語 = row['hoagi'].strip() + if 羅馬字2 != '': + 羅馬字 = [羅馬字1, 羅馬字2] + else: + 羅馬字 = [羅馬字1] + for hoa in 華語.split('、'): + for lo in 羅馬字: + try: + 台文 = 拆文分析器.建立句物件(lo).看分詞() + except 解析錯誤 as 錯誤: + print(錯誤) + else: + yield 台文, 拆文分析器.建立句物件(hoa).看分詞() diff --git "a/\350\251\246\351\251\227/test\345\217\260\347\201\243\346\244\215\347\211\251\345\220\215\345\275\231.py" "b/\350\251\246\351\251\227/test\345\217\260\347\201\243\346\244\215\347\211\251\345\220\215\345\275\231.py" new file mode 100644 index 0000000..02181d4 --- /dev/null +++ "b/\350\251\246\351\251\227/test\345\217\260\347\201\243\346\244\215\347\211\251\345\220\215\345\275\231.py" @@ -0,0 +1,10 @@ +from django.core.management import call_command +from django.test.testcases import TestCase +from 臺灣言語服務.models import 訓練過渡格式 + + +class 台灣植物名彙試驗(TestCase): + + def test句數正確(self): + call_command('台灣植物名彙') + self.assertGreater(訓練過渡格式.資料數量(), 600000) diff --git "a/\350\251\246\351\251\227/test\345\217\260\347\201\243\347\231\275\350\251\261\345\237\272\347\244\216\350\252\236\345\217\245.py" "b/\350\251\246\351\251\227/test\345\217\260\347\201\243\347\231\275\350\251\261\345\237\272\347\244\216\350\252\236\345\217\245.py" index efdf73e..647d425 100644 --- "a/\350\251\246\351\251\227/test\345\217\260\347\201\243\347\231\275\350\251\261\345\237\272\347\244\216\350\252\236\345\217\245.py" +++ "b/\350\251\246\351\251\227/test\345\217\260\347\201\243\347\231\275\350\251\261\345\237\272\347\244\216\350\252\236\345\217\245.py" @@ -3,7 +3,7 @@ from 臺灣言語服務.models import 訓練過渡格式 -class 教典詞條試驗(TestCase): +class 台灣白話基礎語句試驗(TestCase): def test句數正確(self): call_command('台灣白話基礎語句') From 970d281ae4064bc148782e88d4b0e09b8d7d60c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=9B=E4=B8=9E=E5=AE=8F?= Date: Tue, 24 Jul 2018 16:54:40 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=AF=A6=E4=BD=9C=E4=BA=86=EF=BD=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...15\347\211\251\345\220\215\345\275\231.py" | 52 +++++++++---------- ...15\347\211\251\345\220\215\345\275\231.py" | 35 ++++++++++++- 2 files changed, 57 insertions(+), 30 deletions(-) diff --git "a/\345\214\257\345\205\245/management/commands/\345\217\260\347\201\243\346\244\215\347\211\251\345\220\215\345\275\231.py" "b/\345\214\257\345\205\245/management/commands/\345\217\260\347\201\243\346\244\215\347\211\251\345\220\215\345\275\231.py" index 4ed3be4..cc0f005 100644 --- "a/\345\214\257\345\205\245/management/commands/\345\217\260\347\201\243\346\244\215\347\211\251\345\220\215\345\275\231.py" +++ "b/\345\214\257\345\205\245/management/commands/\345\217\260\347\201\243\346\244\215\347\211\251\345\220\215\345\275\231.py" @@ -13,49 +13,45 @@ class Command(匯入枋模): help = 'http://ip194097.ntcu.edu.tw/memory/TGB/thak.asp?id=862' 公家內容 = { - '來源': '台灣白話基礎語句', + '來源': '台灣植物名彙', '種類': '字詞', - '年代': '1956', + '年代': '1928', } github網址 = ( 'https://github.com/Taiwanese-Corpus/' - 'Ko-Chek-hoan-Tan-Pang-tin_1956_Basic-Vocabulary-for-Colloquial-Taiwanese/' - 'raw/master/ChhoeTaigi_TaioanPehoeKichhooGiku.csv' + 'Syuniti-Sasaki_1928_List-of-Plants-of-Formosa/' + 'raw/master/ChhoeTaigi_TaioanSitbutMialui.csv' ) def 全部資料(self, *args, **參數): - 全部資料 = [] 匯入數量 = 0 - for 羅馬字, 華語 in self.github資料(): - 全部資料.append( - 訓練過渡格式( - 文本=羅馬字, - 外文=華語, - **self.公家內容 - ) + for 台文 in self.github資料(): + yield 訓練過渡格式( + 文本=台文, + **self.公家內容 ) 匯入數量 += 1 if 匯入數量 % 1000 == 0: self.stdout.write('匯入 {} 筆'.format(匯入數量)) - return 全部資料 def github資料(self): with urlopen(self.github網址) as 檔: with io.StringIO(檔.read().decode()) as 資料: for row in DictReader(資料): - 羅馬字1 = row['poj_unicode'].strip() - 羅馬字2 = row['poj_other_unicode'].strip() - 華語 = row['hoagi'].strip() - if 羅馬字2 != '': - 羅馬字 = [羅馬字1, 羅馬字2] - else: - 羅馬字 = [羅馬字1] - for hoa in 華語.split('、'): - for lo in 羅馬字: - try: - 台文 = 拆文分析器.建立句物件(lo).看分詞() - except 解析錯誤 as 錯誤: - print(錯誤) - else: - yield 台文, 拆文分析器.建立句物件(hoa).看分詞() + 羅馬字 = row['poj_unicode'].strip() + 可能漢字 = row['taigi_hanji'].strip() + for lo, han in self.漢羅組合(羅馬字, 可能漢字): + try: + 物件 = 拆文分析器.建立句物件(han, lo) + except 解析錯誤 as 錯誤: + self.stderr.write(str(錯誤)) + else: + for 字物件 in 物件.篩出字物件(): + if 字物件.型 == 'XXX': + 字物件.型 = 字物件.音 + yield 物件.看分詞() + + def 漢羅組合(self, 羅馬字, 可能漢字): + for 漢字 in 可能漢字.replace('?', ' XXX ').split('、'): + yield 羅馬字, 漢字 diff --git "a/\350\251\246\351\251\227/test\345\217\260\347\201\243\346\244\215\347\211\251\345\220\215\345\275\231.py" "b/\350\251\246\351\251\227/test\345\217\260\347\201\243\346\244\215\347\211\251\345\220\215\345\275\231.py" index 02181d4..94452cb 100644 --- "a/\350\251\246\351\251\227/test\345\217\260\347\201\243\346\244\215\347\211\251\345\220\215\345\275\231.py" +++ "b/\350\251\246\351\251\227/test\345\217\260\347\201\243\346\244\215\347\211\251\345\220\215\345\275\231.py" @@ -1,10 +1,41 @@ from django.core.management import call_command from django.test.testcases import TestCase from 臺灣言語服務.models import 訓練過渡格式 +from 匯入.management.commands.台灣植物名彙 import Command +from 臺灣言語工具.解析整理.拆文分析器 import 拆文分析器 class 台灣植物名彙試驗(TestCase): - def test句數正確(self): + @classmethod + def setUpClass(cls): call_command('台灣植物名彙') - self.assertGreater(訓練過渡格式.資料數量(), 600000) + super().setUpClass() + + def test句數正確(self): + self.assertGreater(訓練過渡格式.資料數量(), 1700) + + def test切出一詞(self): + self.assertEqual( + list(Command().漢羅組合('Kau-tîn', '鈎藤')), + [('Kau-tîn', '鈎藤')], + ) + + def test切出兩詞(self): + self.assertEqual( + list(Command().漢羅組合('Tsuí-kim-kiann', '水金京、水金驚')), + [('Tsuí-kim-kiann', '水金京'), ('Tsuí-kim-kiann', '水金驚')], + ) + + def test問號換做XXX(self): + self.assertEqual( + list(Command().漢羅組合('Tò-tiàu-hong', '倒?風')), + [('Tò-tiàu-hong', '倒 XXX 風')], + ) + + def test問號上尾改漢羅(self): + self.assertTrue( + 訓練過渡格式.objects + .filter(文本=拆文分析器.建立句物件('倒-tiàu-風', 'Tò-tiàu-hong').看分詞()) + .exists() + )