Skip to content

Commit

Permalink
Merge pull request #63 from Taiwanese-Corpus/白話字文獻館
Browse files Browse the repository at this point in the history
白話字文獻館 fix #49
  • Loading branch information
sih4sing5hong5 committed Aug 1, 2018
2 parents d43f389 + 06a0bde commit f791bc9
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -17,6 +17,7 @@ env:
- TOX_ENV=台語文語料庫蒐集及語料庫為本台語書面語音節詞頻統計
- TOX_ENV=台語文數位典藏資料庫
- TOX_ENV=教育部臺灣閩南語字詞頻調查工作
- TOX_ENV=白話字文獻館
- TOX_ENV=台灣植物名彙
- TOX_ENV=台灣白話基礎語句
addons:
Expand Down
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -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段,其中31195段對會齊,12298段無法度對齊就用羅馬字(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)
Expand Down
6 changes: 6 additions & 0 deletions tox.ini
Expand Up @@ -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
Expand Down
78 changes: 78 additions & 0 deletions 匯入/management/commands/白話字文獻館.py
@@ -0,0 +1,78 @@
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 add_arguments(self, parser):
parser.add_argument(
'--錯誤印部份就好',
action='store_true',
help='因為CI有限制輸出4M',
)

def 全部資料(self, *args, **參數):
self.錯誤全印 = not 參數['錯誤印部份就好']

匯入數量 = 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:
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(錯誤)
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])
13 changes: 13 additions & 0 deletions 試驗/test白話字文獻館.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(訓練過渡格式.資料數量(), 43000)

0 comments on commit f791bc9

Please sign in to comment.