Skip to content

Commit 195fbd4

Browse files
authoredApr 27, 2021
Split class 音韻地位 to qieyun-encoder-python (#3)
* Split class 音韻地位 to qieyun-encoder-python * Update metadata
1 parent ceeed3f commit 195fbd4

18 files changed

+165
-825
lines changed
 

‎.github/workflows/documentation.yml

+55-51
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,58 @@ jobs:
99
publish:
1010
runs-on: ubuntu-20.04
1111
steps:
12-
- uses: actions/checkout@v2
13-
- name: Setup Python
14-
uses: actions/setup-python@v2
15-
with:
16-
python-version: '3.9'
17-
- name: Upgrade pip
18-
run: python -m pip install --upgrade pip
19-
- name: Install packaging tools
20-
run: pip install setuptools wheel twine
21-
- name: Install pdoc
22-
run: pip install pdoc3
23-
- name: Prepare data
24-
run: python prepare.py
25-
- name: Install package
26-
run: pip install .
27-
- name: Build documentation
28-
run: pdoc --html -o docs -f -c sort_identifiers=False Qieyun
29-
- name: Publish
30-
run: |
31-
# Create a temporary directory
32-
export temp_dir=`mktemp -d -p ~`
33-
34-
(
35-
# Preserve .git
36-
mv .git $temp_dir
37-
cd $temp_dir
38-
39-
# Switch branch
40-
git fetch
41-
git checkout gh-pages
42-
git reset --hard gh-pages
43-
)
44-
45-
(
46-
# Move .git
47-
mv docs/Qieyun/* $temp_dir
48-
49-
# Go to the temporary directory
50-
cd $temp_dir
51-
52-
# Set commit identity
53-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
54-
git config user.name "github-actions[bot]"
55-
56-
# Publish
57-
git add .
58-
if [ -n "$(git status --porcelain)" ]; then
59-
git commit -m "Publish `TZ='Asia/Hong_Kong' date`"
60-
git push -f origin gh-pages
61-
fi
62-
)
12+
- uses: actions/checkout@v2
13+
- name: Setup Python
14+
uses: actions/setup-python@v2
15+
with:
16+
python-version: "3.9"
17+
- name: Upgrade pip
18+
run: python -m pip install --upgrade pip
19+
- name: Install packaging tools
20+
run: pip install setuptools wheel twine
21+
- name: Install pdoc
22+
run: pip install pdoc3
23+
- name: Prepare data
24+
run: python prepare.py
25+
- name: Install package
26+
run: pip install .
27+
- name: Build documentation
28+
run: pdoc --html -o docs -f -c sort_identifiers=False Qieyun
29+
- name: Publish
30+
run: |
31+
# Create a temporary directory
32+
export temp_dir=`mktemp -d -p ~`
33+
34+
(
35+
# Preserve .git
36+
mkdir $temp_dir/temp
37+
mv .git $temp_dir/temp
38+
cd $temp_dir/temp
39+
40+
# Switch branch
41+
git fetch
42+
git checkout gh-pages
43+
git reset --hard gh-pages
44+
)
45+
46+
(
47+
# Move .git
48+
mv $temp_dir/temp/.git $temp_dir
49+
rm -rf $temp_dir/temp
50+
mv docs/Qieyun/* $temp_dir
51+
mv LICENSE $temp_dir
52+
53+
# Go to the temporary directory
54+
cd $temp_dir
55+
56+
# Set commit identity
57+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
58+
git config user.name "github-actions[bot]"
59+
60+
# Publish
61+
git add .
62+
if [ -n "$(git status --porcelain)" ]; then
63+
git commit -m "Publish `TZ='Asia/Hong_Kong' date`"
64+
git push -f origin gh-pages
65+
fi
66+
)

‎.github/workflows/publish.yml

+18-18
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ jobs:
88
deploy:
99
runs-on: macos-latest
1010
steps:
11-
- uses: actions/checkout@v2
12-
- name: Set up Python
13-
uses: actions/setup-python@v2
14-
with:
15-
python-version: '3.x'
16-
- name: Upgrade pip
17-
run: python -m pip install --upgrade pip
18-
- name: Install packaging tools
19-
run: pip install setuptools wheel twine
20-
- name: Prepare data
21-
run: python prepare.py
22-
- name: Build
23-
run: python setup.py sdist bdist_wheel
24-
- name: Publish
25-
env:
26-
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
27-
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
28-
run: twine upload dist/*
11+
- uses: actions/checkout@v2
12+
- name: Set up Python
13+
uses: actions/setup-python@v2
14+
with:
15+
python-version: "3.9"
16+
- name: Upgrade pip
17+
run: python -m pip install --upgrade pip
18+
- name: Install packaging tools
19+
run: pip install setuptools wheel twine
20+
- name: Prepare data
21+
run: python prepare.py
22+
- name: Build
23+
run: python setup.py sdist bdist_wheel
24+
- name: Publish
25+
env:
26+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
27+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
28+
run: twine upload dist/*

‎.github/workflows/test.yml

+19-19
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ name: Python test
33
on:
44
push:
55
paths-ignore:
6-
- '*.md'
6+
- "*.md"
77
pull_request:
88
paths-ignore:
9-
- '*.md'
9+
- "*.md"
1010

1111
jobs:
1212
build:
@@ -15,20 +15,20 @@ jobs:
1515
matrix:
1616
python-version: [3.6, 3.7, 3.8, 3.9]
1717
steps:
18-
- uses: actions/checkout@v2
19-
- name: Set up Python ${{ matrix.python-version }}
20-
uses: actions/setup-python@v2
21-
with:
22-
python-version: ${{ matrix.python-version }}
23-
- name: Upgrade pip
24-
run: python -m pip install --upgrade pip
25-
- name: Install packaging tools
26-
run: pip install setuptools wheel twine
27-
- name: Install PyTest
28-
run: pip install pytest
29-
- name: Prepare data
30-
run: python prepare.py
31-
- name: Install package
32-
run: pip install .
33-
- name: Test
34-
run: pytest test/main.py
18+
- uses: actions/checkout@v2
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v2
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
- name: Upgrade pip
24+
run: python -m pip install --upgrade pip
25+
- name: Install packaging tools
26+
run: pip install setuptools wheel twine
27+
- name: Install PyTest
28+
run: pip install pytest
29+
- name: Prepare data
30+
run: python prepare.py
31+
- name: Install package
32+
run: pip install .
33+
- name: Test
34+
run: pytest test/main.py

‎.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ dist
33
.mypy_cache
44
.pytest_cache
55
__pycache__
6-
.vscode
76
/src/Qieyun/rhyme_book.csv
87
/src/Qieyun/rhyme_table.csv
8+
/build
99
/docs

‎.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "editor.formatOnSave": true }

‎prepare.py

+2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
here = path.abspath(path.dirname(__file__))
55
url = 'https://raw.githubusercontent.com/nk2028/qieyun-data/7d7586a/'
66

7+
78
def retrieve(filename):
89
target = path.join(here, 'src/Qieyun', filename)
910
if not path.exists(target):
1011
urlretrieve(url + filename, target)
1112

13+
1214
retrieve('rhyme_book.csv')
1315
retrieve('rhyme_table.csv')

‎setup.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,20 @@
66
here = path.abspath(path.dirname(__file__))
77

88
if not path.exists(path.join(here, 'src/Qieyun/rhyme_book.csv')) \
9-
or not path.exists(path.join(here, 'src/Qieyun/rhyme_table.csv')):
9+
or not path.exists(path.join(here, 'src/Qieyun/rhyme_table.csv')):
1010
system('python3 prepare.py')
1111

1212
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
1313
long_description = f.read()
1414

15-
with open(path.join(here, 'src/Qieyun/_version.py'), encoding='utf-8') as f:
16-
exec(f.read())
17-
1815
setup(
1916
name='qieyun',
20-
version=__version__,
17+
version='0.13.3',
2118
description='A Python library for the Qieyun phonological system',
2219
long_description=long_description,
2320
long_description_content_type='text/markdown',
2421
url='https://github.com/nk2028/qieyun-python',
25-
author='nk2028',
22+
author='The nk2028 Project',
2623
author_email='support@nk2028.shn.hk',
2724
classifiers=[
2825
'Development Status :: 4 - Beta',
@@ -44,7 +41,7 @@
4441
'Qieyun': ['rhyme_book.csv', 'rhyme_table.csv'],
4542
},
4643
python_requires='>=3.6, <4',
47-
install_requires=['networkx>=2.5,<2.6'],
44+
install_requires=['qieyun-encoder>=0.4,<0.5', 'networkx>=2.5,<2.6'],
4845
entry_points={},
4946
project_urls={
5047
'Bug Reports': 'https://github.com/nk2028/qieyun-python/issues',

‎src/Qieyun/__init__.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
切韻音系 Python 函式庫。
55
'''
66

7-
from ._version import __version__
8-
from .常量 import 常量
9-
from .音韻地位 import 音韻地位
7+
from QieyunEncoder import 常量
8+
from QieyunEncoder import 音韻地位
9+
1010
from .韻書 import 音韻地位2代表字, 音韻地位2字頭_韻書出處們, iter音韻地位
1111
from .韻書和韻圖 import 字頭2音韻地位_出處們
12+
13+
__version__ = '0.13.3'

‎src/Qieyun/_utils.py

+32-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
from .常量 import 常量
2-
from .音韻地位 import 音韻地位
1+
# -*- coding: utf-8 -*-
2+
3+
from QieyunEncoder import 常量
4+
from QieyunEncoder import 音韻地位
35

46
'''
57
注意!!
@@ -8,6 +10,7 @@
810
未來寫好後,此檔案將被移除。
911
'''
1012

13+
1114
def normalize韻():
1215
'''
1316
TODO: 1. 檢查韻典網錯誤
@@ -230,12 +233,13 @@ def normalize韻(韻):
230233
'末': '寒',
231234
'霄': '宵',
232235
'𥬇': '宵',
233-
'敬': '庚', # 映韻
234-
'寢': '侵', # 寑韻
235-
'帖': '添', # 怗韻
236+
'敬': '庚', # 映韻
237+
'寢': '侵', # 寑韻
238+
'帖': '添', # 怗韻
236239
'䰟': '魂',
237240
}[]
238241

242+
239243
'''
240244
TODO:
241245
韻目 = {
@@ -274,14 +278,15 @@ def normalize韻(韻):
274278
'''
275279

276280
l韻圖母號2韻圖母位置 = [
277-
'舌齒音第二位', '舌齒音第一位', # 舌齒音
278-
'喉音第四位', '喉音第三位', '喉音第二位', '喉音第一位', # 喉音
279-
'齒音第五位', '齒音第四位', '齒音第三位', '齒音第二位', '齒音第一位', # 齒音
280-
'牙音第四位', '牙音第三位', '牙音第二位', '牙音第一位', # 牙音
281-
'舌音第四位', '舌音第三位', '舌音第二位', '舌音第一位', # 舌音
282-
'脣音第四位', '脣音第三位', '脣音第二位', '脣音第一位', # 脣音
281+
'舌齒音第二位', '舌齒音第一位', # 舌齒音
282+
'喉音第四位', '喉音第三位', '喉音第二位', '喉音第一位', # 喉音
283+
'齒音第五位', '齒音第四位', '齒音第三位', '齒音第二位', '齒音第一位', # 齒音
284+
'牙音第四位', '牙音第三位', '牙音第二位', '牙音第一位', # 牙音
285+
'舌音第四位', '舌音第三位', '舌音第二位', '舌音第一位', # 舌音
286+
'脣音第四位', '脣音第三位', '脣音第二位', '脣音第一位', # 脣音
283287
]
284288

289+
285290
def 韻圖母號_韻圖等_切韻韻2韻圖母(韻圖母號, 韻圖等, 切韻韻):
286291
return [
287292
# 舌齒音
@@ -315,13 +320,15 @@ def 韻圖母號_韻圖等_切韻韻2韻圖母(韻圖母號, 韻圖等, 切韻
315320
'非' if 韻圖等 == '三' and 切韻韻 in 常量.輕脣韻 else '幫',
316321
][韻圖母號]
317322

323+
318324
def 韻圖等_切韻韻2切韻等(韻圖等, 切韻韻):
319325
if 切韻韻 in 常量.一三等韻:
320326
return '一' if 韻圖等 == '一' else '三'
321327
if 切韻韻 in 常量.二三等韻:
322-
return '二' if 韻圖等 == '二' else '三' # TODO: 麻庚韻莊組
328+
return '二' if 韻圖等 == '二' else '三' # TODO: 麻庚韻莊組
323329
return ''
324330

331+
325332
def 韻圖母_韻圖等2切韻母(韻圖母, 韻圖等):
326333
if 韻圖母 == '喻':
327334
return '云' if 韻圖等 == '三' else '以'
@@ -337,17 +344,23 @@ def 韻圖母_韻圖等2切韻母(韻圖母, 韻圖等):
337344
if 韻圖母 == '禪':
338345
return '船' if 韻圖等 == '三' else '俟'
339346

340-
if 韻圖母 == '非': return '幫'
341-
if 韻圖母 == '敷': return '滂'
342-
if 韻圖母 == '奉': return '並'
343-
if 韻圖母 == '微': return '明'
347+
if 韻圖母 == '非':
348+
return '幫'
349+
if 韻圖母 == '敷':
350+
return '滂'
351+
if 韻圖母 == '奉':
352+
return '並'
353+
if 韻圖母 == '微':
354+
return '明'
344355

345356
return 韻圖母
346357

358+
347359
def 切韻母_切韻韻_韻圖等2重紐(切韻母, 切韻韻, 韻圖等):
348360
return '' if 切韻母 not in 常量.重紐母 or 切韻韻 not in 常量.重紐韻 else \
349-
'B' if 韻圖等 == '三' else \
350-
'A'
361+
'B' if 韻圖等 == '三' else \
362+
'A'
363+
351364

352365
def 韻圖2切韻(轉號, 韻圖開合修正後, 韻圖母位置, 韻圖聲, 韻圖韻, 韻圖等):
353366
切韻韻 = normalize韻(韻圖韻)
@@ -360,7 +373,7 @@ def 韻圖2切韻(轉號, 韻圖開合修正後, 韻圖母位置, 韻圖聲, 韻
360373
重紐 = 切韻母_切韻韻_韻圖等2重紐(切韻母, 切韻韻, 韻圖等)
361374
音韻描述 = 切韻母 + 韻圖開合修正後 + 切韻等 + 重紐 + 切韻韻 + 韻圖聲
362375
try:
363-
當前音韻地位 = 音韻地位.from描述(音韻描述) # will perform check
376+
當前音韻地位 = 音韻地位.from描述(音韻描述) # will perform check
364377
except Exception:
365378
assert False, 音韻描述
366379
return 韻圖母, 當前音韻地位

‎src/Qieyun/_version.py

-1
This file was deleted.

0 commit comments

Comments
 (0)