Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
ayaka14732 committed Apr 18, 2024
1 parent 0fa92a7 commit fd2e431
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 96 deletions.
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Qieyun Encoder Python 說明文件
:maxdepth: 1

常量
變換
轉換
音韻地位
工具

Expand Down Expand Up @@ -57,7 +57,7 @@ Qieyun Encoder Python 說明文件

不要與中古後期三十六字母混淆。

中古後期三十六字母:
中古後期三十六字母

.. raw:: html

Expand Down
4 changes: 2 additions & 2 deletions docs/變換.rst → docs/轉換.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
QieyunEncoder.變換
QieyunEncoder.轉換
==================

.. automodule:: QieyunEncoder.變換
.. automodule:: QieyunEncoder.轉換
:imported-members:
:members:
:undoc-members:
Expand Down
11 changes: 2 additions & 9 deletions src/QieyunEncoder/工具/反切.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
# -*- coding: utf-8 -*-

'''
根據反切規律自動完成反切過程。
'''

from typing import List
from .. import 常量
from ..音韻地位 import 音韻地位
from .._母對應的標準等 import 母對應的標準等
from ..音韻地位 import 音韻地位


def _jointer(xs: List[str]):
def _jointer(xs: list[str]):
'''
將多個字串以頓號和「或」字連接。
Expand All @@ -25,7 +19,6 @@ def _jointer(xs: List[str]):
'''
return ''.join(x + '、' for x in xs[:-2]) + '或'.join(xs[-2:])


def 反切(上字音韻地位: 音韻地位, 下字音韻地位: 音韻地位, 顯示步驟=False, 類隔切=False):
'''
根據反切規律自動完成反切過程。
Expand Down
8 changes: 3 additions & 5 deletions src/QieyunEncoder/工具/音韻地位到韻鏡位置.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# -*- coding: utf-8 -*-

'''
將音韻地位轉換爲韻鏡位置。
'''

from ..音韻地位 import 音韻地位
from ..韻鏡位置 import 韻鏡位置


def 音韻地位到韻鏡位置(當前音韻地位: 音韻地位) -> 韻鏡位置:
'''
將音韻地位轉換爲韻鏡位置。
'''
raise NotImplementedError
19 changes: 5 additions & 14 deletions src/QieyunEncoder/工具/音韻屬性到韻鏡位置們.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
# -*- coding: utf-8 -*-

'''
將音韻屬性轉換爲韻鏡位置。
'''

from ..韻鏡位置 import 韻鏡位置
from .. import 常量
from ..變換 import 韻目到韻
from ..變換 import 母到組

from ..轉換 import 韻目到韻, 母到組
from ..韻鏡位置 import 韻鏡位置

def 音韻屬性到韻鏡位置們(: str, 韻目: str, : str):
'''
Test
將音韻屬性轉換爲韻鏡位置。
'''

韻鏡母 = {
'幫': '幫非', '滂': '滂敷', '並': '並奉', '明': '明微',
'精': '精照', '清': '清穿', '從': '從牀', '心': '心審', '邪': '邪禪',
Expand Down Expand Up @@ -59,8 +54,4 @@ def 音韻屬性到韻鏡位置們(母: str, 韻目: str, 聲: str):
else:
韻鏡等們 += '三' # 其餘情況排在三等

return [
韻鏡位置(韻鏡母, 韻鏡開合, 韻鏡等, , )
for 韻鏡開合 in 韻鏡開合們
for 韻鏡等 in 韻鏡等們
]
return [韻鏡位置(韻鏡母, 韻鏡開合, 韻鏡等, , ) for 韻鏡開合 in 韻鏡開合們 for 韻鏡等 in 韻鏡等們]
17 changes: 6 additions & 11 deletions src/QieyunEncoder/工具/韻鏡位置到音韻地位.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
# -*- coding: utf-8 -*-

'''
將韻鏡位置轉換爲音韻地位。
'''

from .. import 常量
from ..音韻地位 import 音韻地位
from ..韻鏡位置 import 韻鏡位置
from .. import 常量


def 韻鏡位置到音韻地位(當前韻鏡位置: 韻鏡位置) -> 音韻地位:
'''
Test
將韻鏡位置轉換爲音韻地位。
Example:
```python
>>> 韻鏡位置到音韻地位(韻鏡位置('幫', None, '三', '凡', '入')) == 音韻地位.from描述('幫三凡入')
True
```
>>> 韻鏡位置到音韻地位(韻鏡位置('幫', None, '三', '凡', '入')) == 音韻地位.from描述('幫三凡入')
True
'''
韻鏡母號 = 當前韻鏡位置.韻鏡母號
韻鏡母 = 當前韻鏡位置.最簡韻鏡母
Expand Down
12 changes: 10 additions & 2 deletions src/QieyunEncoder/常量.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,18 @@
'''str: 二三等韻'''


所有音 = '脣舌齒牙喉'
'''str: 所有音'''

所有組 = '幫端知精莊章見影'
'''str: 所有組'''

所有攝 = '通江止遇蟹臻山效果假宕梗曾流深咸'
'''str: 所有攝'''


輕脣韻 = '東鍾微虞廢文元陽尤凡'
'''str: 輕脣韻'''


次入韻 = '祭泰夬廢'
'''str: 次入韻'''

Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-

from .韻目到韻 import 韻目到韻
from .正則化韻 import 正則化韻
from .母到清濁 import 母到清濁
from .母到組 import 母到組
from .母到音 import 母到音
from .韻到攝 import 韻到攝
from .母與等到類 import 母與等到類
from .韻到攝 import 韻到攝
from .韻目到韻 import 韻目到韻
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# -*- coding: utf-8 -*-

'''
將切韻系韻書的韻目轉換爲韻。
'''

_非標準韻表 = [
'東董蕫送屋',
'冬湩宋沃𣵽',
Expand Down Expand Up @@ -68,7 +64,6 @@

_標準韻映射表 = {非標準韻: 非標準韻們[0] for 非標準韻們 in _非標準韻表 for 非標準韻 in 非標準韻們}


def 正則化韻(: str):
'''
將切韻系韻書的韻目轉換爲韻。
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
# -*- coding: utf-8 -*-

'''
將母轉換爲清濁。
'''

_清濁到母表 = (
('全清', '幫端知精心莊生章書見影曉'),
('次清', '滂透徹清初昌溪'),
('全濁', '並定澄從邪崇俟常船羣匣'),
('次濁', '明泥孃來日疑云以'),
)

_d母到清濁 = {: 清濁 for 清濁, 母們 in _清濁到母表 for in 母們}
_母到清濁映射表 = {: 清濁 for 清濁, 母們 in _清濁到母表 for in 母們}

def 母到清濁(: str) -> str:
'''
Expand All @@ -24,4 +20,4 @@ def 母到清濁(母: str) -> str:
>>> 母到清濁('以')
'次濁'
'''
return _d母到清濁[]
return _母到清濁映射表[]
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# -*- coding: utf-8 -*-

'''
將母轉換爲組。
'''

_組到母表 = (
('幫', '幫滂並明'),
('端', '端透定泥'),
Expand All @@ -16,7 +12,7 @@
(None, '來日以'),
)

_d母到組 = {: for , 母們 in _組到母表 for in 母們}
_母到組映射表 = {: for , 母們 in _組到母表 for in 母們}

def 母到組(: str) -> str | None:
'''
Expand All @@ -31,4 +27,4 @@ def 母到組(母: str) -> str | None:
>>> 母到組('以')
None
'''
return _d母到組[]
return _母到組映射表[]
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# -*- coding: utf-8 -*-

'''
將母轉換爲音。
'''

_音到母表 = (
('脣', '幫滂並明'),
('舌', '端透定泥知徹澄孃來'),
Expand All @@ -12,7 +8,7 @@
('喉', '影曉匣云以'),
)

_d母到音 = {: for , 母們 in _音到母表 for in 母們}
_母到音映射表 = {: for , 母們 in _音到母表 for in 母們}

def 母到音(: str) -> str:
'''
Expand All @@ -25,4 +21,4 @@ def 母到音(母: str) -> str:
>>> 母到音('羣')
'牙'
'''
return _d母到音[]
return _母到音映射表[]
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# -*- coding: utf-8 -*-

'''
由母與等確定五十一聲類。
注意五十一聲類中俟母獨立,故實為五十二個。
'''

_五十一聲類映射表 = (
('方', '幫', '三'),
('博', '幫', None),
Expand Down Expand Up @@ -62,6 +56,23 @@
)

def 母與等到類(: str, : str) -> str:
'''
由母與等確定五十一聲類。
注意五十一聲類中俟母獨立,故實為五十二個。
:param 母: 聲母
:type 母: str
:param 等: 等
:type 等: str
Example:
>>> 母與等到類('見', '二')
'古'
>>> 母與等到類('並', '三')
'符'
'''
for 聲類, 母條件, 等條件 in _五十一聲類映射表:
if == 母條件 and (等條件 is None or in 等條件):
return 聲類
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# -*- coding: utf-8 -*-

'''
將韻轉換爲攝。
'''

_攝到韻表 = (
('通', '東冬鍾'),
('江', '江'),
Expand All @@ -23,7 +19,7 @@
('咸', '覃談鹽添咸銜嚴凡'),
)

_d韻到攝 = {: for , 韻們 in _攝到韻表 for in 韻們}
_韻到攝映射表 = {: for , 韻們 in _攝到韻表 for in 韻們}

def 韻到攝(: str) -> str:
'''
Expand All @@ -36,4 +32,4 @@ def 韻到攝(韻: str) -> str:
>>> 韻到攝('侵')
'深'
'''
return _d韻到攝[]
return _韻到攝映射表[]
File renamed without changes.
5 changes: 2 additions & 3 deletions src/QieyunEncoder/音韻地位.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re

from . import 常量
from .變換 import 母到清濁, 母到音, 母到組, 韻到攝, 母與等到類
from .轉換 import 母到清濁, 母到音, 母到組, 韻到攝, 母與等到類

編碼表 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
韻順序表 = '東_冬鍾江支脂之微魚虞模齊祭泰佳皆夬灰咍廢真臻文殷元魂痕寒刪山仙先蕭宵肴豪歌_麻_陽唐庚_耕清青蒸登尤侯幽侵覃談鹽添咸銜嚴凡'
Expand Down Expand Up @@ -510,8 +510,7 @@ def __eq__(self, that) -> bool:

def __lt__(self, that) -> bool:
if not isinstance(that, 音韻地位):
raise TypeError(
"'<' not supported between instances of '音韻地位' and " + type(that).__name__)
raise TypeError("'<' not supported between instances of '音韻地位' and " + type(that).__name__)

def 母到編碼():
return 常量.所有母.index()
Expand Down
Loading

0 comments on commit fd2e431

Please sign in to comment.