From a9c7d66933227cc949ad0902651124e0f9606783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=9B=E4=B8=9E=E5=AE=8F?= Date: Tue, 31 Jul 2018 17:14:34 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E7=99=BD=E8=A9=B1=E5=AD=97=E6=96=87?= =?UTF-8?q?=E7=8D=BB=E9=A4=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 1 + tox.ini | 6 ++ ...27\346\226\207\347\215\273\351\244\250.py" | 65 +++++++++++++++++++ ...27\346\226\207\347\215\273\351\244\250.py" | 13 ++++ 4 files changed, 85 insertions(+) create mode 100644 "\345\214\257\345\205\245/management/commands/\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" create mode 100644 "\350\251\246\351\251\227/test\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" diff --git a/.travis.yml b/.travis.yml index 4794d93..fa4bdd4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,7 @@ env: - TOX_ENV=台語文語料庫蒐集及語料庫為本台語書面語音節詞頻統計 - TOX_ENV=台語文數位典藏資料庫 - TOX_ENV=教育部臺灣閩南語字詞頻調查工作 +- TOX_ENV=白話字文獻館 - TOX_ENV=台灣植物名彙 - TOX_ENV=台灣白話基礎語句 addons: diff --git a/tox.ini b/tox.ini index 9c2c1ff..5ef500e 100644 --- a/tox.ini +++ b/tox.ini @@ -86,6 +86,12 @@ deps = commands= coverage run --source=匯入 manage.py test 試驗.test教育部臺灣閩南語字詞頻調查工作 +[testenv:白話字文獻館] +deps = + coverage +commands= + coverage run --source=匯入 manage.py test 試驗.test白話字文獻館 + [testenv:台灣植物名彙] deps = coverage diff --git "a/\345\214\257\345\205\245/management/commands/\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" "b/\345\214\257\345\205\245/management/commands/\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" new file mode 100644 index 0000000..8256d1a --- /dev/null +++ "b/\345\214\257\345\205\245/management/commands/\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" @@ -0,0 +1,65 @@ +import io +import json +from urllib.request import urlopen + + +from 臺灣言語工具.解析整理.拆文分析器 import 拆文分析器 +from 臺灣言語服務.models import 訓練過渡格式 +from 臺灣言語工具.解析整理.解析錯誤 import 解析錯誤 +from 匯入.指令 import 匯入枋模 + + +class Command(匯入枋模): + help = 'pojbh.lib.ntnu.edu.tw' + json網址 = ( + 'https://github.com/Taiwanese-Corpus/Khin-hoan_2010_pojbh/' + 'raw/master/pojbh.json' + ) + + 公家內容 = { + '來源': '白話字文獻館', + '種類': '語句', + '年代': '2010', + } + + def 全部資料(self, *args, **參數): + 匯入數量 = 0 + for 台語物件 in self._全部資料(): + yield 訓練過渡格式( + 文本=台語物件.看分詞(), + **self.公家內容 + ) + + 匯入數量 += 1 + if 匯入數量 % 1000 == 0: + self.stdout.write('匯入 {} 條'.format(匯入數量)) + + def _全部資料(self): + with urlopen(self.json網址) as 檔: + with io.StringIO(檔.read().decode()) as 資料: + for phinn in json.load(資料): + if len(phinn['tailo']) != len(phinn['hanlo']): + for tuann in phinn['tailo']: + yield from self.羅轉物件(tuann) + else: + for han, lo in zip(phinn['hanlo'], phinn['tailo']): + yield from self.轉物件(han, lo) + + def 轉物件(self, 漢羅, 羅): + try: + yield 拆文分析器.建立句物件(漢羅, 羅) + except 解析錯誤 as 錯誤: + if self.錯誤全印: + self.stderr.write(錯誤) + else: + self.stderr.write(str(錯誤)[:40]) + yield from self.羅轉物件(羅) + + def 羅轉物件(self, 羅): + try: + yield 拆文分析器.建立句物件(羅) + except 解析錯誤 as 錯誤: + if self.錯誤全印: + self.stderr.write(錯誤) + else: + self.stderr.write(str(錯誤)[:40]) diff --git "a/\350\251\246\351\251\227/test\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" "b/\350\251\246\351\251\227/test\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" new file mode 100644 index 0000000..e6da6d5 --- /dev/null +++ "b/\350\251\246\351\251\227/test\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" @@ -0,0 +1,13 @@ +from django.test.testcases import TestCase +from 臺灣言語服務.models import 訓練過渡格式 +from django.core.management import call_command + + +class 白話字文獻館試驗(TestCase): + @classmethod + def setUpClass(cls): + call_command('白話字文獻館') + return super().setUpClass() + + def test句數正確(self): + self.assertGreater(訓練過渡格式.資料數量(), 10000) From d81cbceb4ad8baa445172f0b9099e13693d3a771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=9B=E4=B8=9E=E5=AE=8F?= Date: Tue, 31 Jul 2018 17:15:40 +0800 Subject: [PATCH 2/6] =?UTF-8?q?'--=E9=8C=AF=E8=AA=A4=E5=8D=B0=E9=83=A8?= =?UTF-8?q?=E4=BB=BD=E5=B0=B1=E5=A5=BD'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\345\255\227\346\226\207\347\215\273\351\244\250.py" | 9 +++++++++ ...1\345\255\227\346\226\207\347\215\273\351\244\250.py" | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git "a/\345\214\257\345\205\245/management/commands/\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" "b/\345\214\257\345\205\245/management/commands/\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" index 8256d1a..f1adbdf 100644 --- "a/\345\214\257\345\205\245/management/commands/\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" +++ "b/\345\214\257\345\205\245/management/commands/\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" @@ -22,7 +22,16 @@ class Command(匯入枋模): '年代': '2010', } + def add_arguments(self, parser): + parser.add_argument( + '--錯誤印部份就好', + action='store_true', + help='因為CI有限制輸出4M', + ) + def 全部資料(self, *args, **參數): + self.錯誤全印 = not 參數['錯誤印部份就好'] + 匯入數量 = 0 for 台語物件 in self._全部資料(): yield 訓練過渡格式( diff --git "a/\350\251\246\351\251\227/test\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" "b/\350\251\246\351\251\227/test\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" index e6da6d5..0d9093c 100644 --- "a/\350\251\246\351\251\227/test\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" +++ "b/\350\251\246\351\251\227/test\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" @@ -6,7 +6,7 @@ class 白話字文獻館試驗(TestCase): @classmethod def setUpClass(cls): - call_command('白話字文獻館') + call_command('白話字文獻館', '--錯誤印部份就好') return super().setUpClass() def test句數正確(self): From 717e6f1d6a17a225955440314797660f3776bf4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=9B=E4=B8=9E=E5=AE=8F?= Date: Tue, 31 Jul 2018 17:33:33 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E5=85=88=E9=96=AC=E9=81=8E=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\261\345\255\227\346\226\207\347\215\273\351\244\250.py" | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git "a/\345\214\257\345\205\245/management/commands/\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" "b/\345\214\257\345\205\245/management/commands/\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" index f1adbdf..9a7d35b 100644 --- "a/\345\214\257\345\205\245/management/commands/\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" +++ "b/\345\214\257\345\205\245/management/commands/\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" @@ -56,7 +56,11 @@ def _全部資料(self): def 轉物件(self, 漢羅, 羅): try: - yield 拆文分析器.建立句物件(漢羅, 羅) + try: + yield 拆文分析器.建立句物件(漢羅, 羅) + except ValueError: + 'https://github.com/i3thuan5/tai5-uan5_gian5-gi2_kang1-ku7/issues/566' + raise 解析錯誤(ValueError) except 解析錯誤 as 錯誤: if self.錯誤全印: self.stderr.write(錯誤) From 3bd70a1e09d84a8e5424a69ab3e13853a3340aa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=9B=E4=B8=9E=E5=AE=8F?= Date: Tue, 31 Jul 2018 18:22:06 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BF=AE=E5=B0=88=E6=A1=88=E8=A9=A6?= =?UTF-8?q?=E9=A9=97=E3=80=81README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 ++++++++ ...61\345\255\227\346\226\207\347\215\273\351\244\250.py" | 2 +- ...61\345\255\227\346\226\207\347\215\273\351\244\250.py" | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4956331..6276290 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,14 @@ python manage.py 台語文數位典藏資料庫 - 語料:[Github](https://github.com/Taiwanese-Corpus/Ungian_2009_KIPsupin) ``` python manage.py 教育部臺灣閩南語字詞頻調查工作 +``` + +### [白話字文獻館](http://pojbh.lib.ntnu.edu.tw) +- 形式:漢羅、全羅 +- 段數:43493段,其中XXX段對會齊,XXX段無法度對齊就用羅馬字(2018/07/31) +- 語料:[Github](https://github.com/Taiwanese-Corpus/Khin-hoan_2010_pojbh) +``` +python manage.py 白話字文獻館 ``` ### [台灣植物名彙](http://ip194097.ntcu.edu.tw/memory/TGB/thak.asp?id=59&page=4) diff --git "a/\345\214\257\345\205\245/management/commands/\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" "b/\345\214\257\345\205\245/management/commands/\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" index 9a7d35b..e374163 100644 --- "a/\345\214\257\345\205\245/management/commands/\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" +++ "b/\345\214\257\345\205\245/management/commands/\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" @@ -60,7 +60,7 @@ def 轉物件(self, 漢羅, 羅): yield 拆文分析器.建立句物件(漢羅, 羅) except ValueError: 'https://github.com/i3thuan5/tai5-uan5_gian5-gi2_kang1-ku7/issues/566' - raise 解析錯誤(ValueError) + raise 解析錯誤(ValueError) except 解析錯誤 as 錯誤: if self.錯誤全印: self.stderr.write(錯誤) diff --git "a/\350\251\246\351\251\227/test\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" "b/\350\251\246\351\251\227/test\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" index 0d9093c..48a5ac2 100644 --- "a/\350\251\246\351\251\227/test\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" +++ "b/\350\251\246\351\251\227/test\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" @@ -10,4 +10,4 @@ def setUpClass(cls): return super().setUpClass() def test句數正確(self): - self.assertGreater(訓練過渡格式.資料數量(), 10000) + self.assertGreater(訓練過渡格式.資料數量(), 45000) From 91dec9d137ff8357b8215bb8a69f2abdd9310597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=9B=E4=B8=9E=E5=AE=8F?= Date: Tue, 31 Jul 2018 18:38:14 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E5=8A=A0readme=E6=95=B8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6276290..a6a6598 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ python manage.py 教育部臺灣閩南語字詞頻調查工作 ### [白話字文獻館](http://pojbh.lib.ntnu.edu.tw) - 形式:漢羅、全羅 -- 段數:43493段,其中XXX段對會齊,XXX段無法度對齊就用羅馬字(2018/07/31) +- 段數:43493段,其中31195段對會齊,12298段無法度對齊就用羅馬字(2018/07/31) - 語料:[Github](https://github.com/Taiwanese-Corpus/Khin-hoan_2010_pojbh) ``` python manage.py 白話字文獻館 From 06a0bde6aea69ab1e44e7e100e221742326a2ce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=9B=E4=B8=9E=E5=AE=8F?= Date: Wed, 1 Aug 2018 09:56:39 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E6=94=B9=E6=95=B8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/\350\251\246\351\251\227/test\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" "b/\350\251\246\351\251\227/test\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" index 48a5ac2..8bf600d 100644 --- "a/\350\251\246\351\251\227/test\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" +++ "b/\350\251\246\351\251\227/test\347\231\275\350\251\261\345\255\227\346\226\207\347\215\273\351\244\250.py" @@ -10,4 +10,4 @@ def setUpClass(cls): return super().setUpClass() def test句數正確(self): - self.assertGreater(訓練過渡格式.資料數量(), 45000) + self.assertGreater(訓練過渡格式.資料數量(), 43000)