From 4fc464e6e00463652fa1a7236857694f4ef58960 Mon Sep 17 00:00:00 2001 From: IoeCmcomc <53734763+IoeCmcomc@users.noreply.github.com> Date: Sat, 1 Jun 2024 11:08:01 +0700 Subject: [PATCH] doc: add more examples --- README-vi.md | 28 ++++++++++++++++++++++++++++ README.md | 28 ++++++++++++++++++++++++++++ ctnx/syllable.py | 4 ++-- docs/source/usage.rst | 30 ++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 2 deletions(-) diff --git a/README-vi.md b/README-vi.md index 7f612d3..1fcd3d7 100644 --- a/README-vi.md +++ b/README-vi.md @@ -75,4 +75,32 @@ True CccdResult(id='123456', is_male=False, birth_year=1992, birth_country='vn', birth_province='Bắc Giang') ``` +- Để lấy dấu thanh từ một đoạn văn hoặc chữ tiếng Việt: + +```python +>>> from ctnx.misc import separate_tone +>>> separate_tone("Đẩu") +('Đâu', '?') +>>> toneNames = {'': 'thanh', '/': 'sắc', '\\': 'huyền', '?': 'hỏi', '~': 'ngã', '.': 'nặng'} +>>> ' '.join(toneNames[separate_tone(syll)[1]] for syll in "Tôi thầm cảm ơn Đẩu đã giữ mình ở nán lại".split(' ')) +'thanh huyền hỏi thanh hỏi ngã ngã huyền hỏi sắc nặng' +``` + +- Để thao tác với các âm tiết (còn gọi là chữ hoặc tiếng) tiếng Việt: + +```python +>>> from ctnx.syllable import Syllable +>>> text = "ba ngày một trận nhẹ năm ngày một trận nặng" +>>> a = [Syllable.from_string(x) for x in text.split(' ')] +>>> a +[Syllable(b, a, ), Syllable(ng, ay, , \), Syllable(m, ô, t, .), Syllable(tr, â, n, .), Syllable(nh, e, , .), Syllable(n, ă, m), Syllable(ng, ay, , \), Syllable(m, ô, t, .), Syllable(tr, â, n, .), Syllable(n, ă, ng, .)] +>>> for syll in a: +... syll.onset = 'nh' +... +>>> a +[Syllable(nh, a, ), Syllable(nh, ay, , \), Syllable(nh, ô, t, .), Syllable(nh, â, n, .), Syllable(nh, e, , .), Syllable(nh, ă, m), Syllable(nh, ay, , \), Syllable(nh, ô, t, .), Syllable(nh, â, n, .), Syllable(nh, ă, ng, .)] +>>> ' '.join(str(x) for x in a) +'nha nhày nhột nhận nhẹ nhăm nhày nhột nhận nhặng' +``` + Để biết thêm cách sử dụng, hãy xem tài liệu (tiếng Anh) nằm ở [chiecthuyenngoaixa.readthedocs.io](https://chiecthuyenngoaixa.readthedocs.io/en/latest/). diff --git a/README.md b/README.md index 9c0b203..de2c2bb 100755 --- a/README.md +++ b/README.md @@ -83,4 +83,32 @@ True CccdResult(id='123456', is_male=False, birth_year=1992, birth_country='vn', birth_province='Bắc Giang') ``` +- To extract tones from a Vietnamese syllable or text: + +```python +>>> from ctnx.misc import separate_tone +>>> separate_tone("Đẩu") +('Đâu', '?') +>>> toneNames = {'': 'thanh', '/': 'sắc', '\\': 'huyền', '?': 'hỏi', '~': 'ngã', '.': 'nặng'} +>>> ' '.join(toneNames[separate_tone(syll)[1]] for syll in "Tôi thầm cảm ơn Đẩu đã giữ mình ở nán lại".split(' ')) +'thanh huyền hỏi thanh hỏi ngã ngã huyền hỏi sắc nặng' +``` + +- To manipulate Vietnamese syllables: + +```python +>>> from ctnx.syllable import Syllable +>>> text = "ba ngày một trận nhẹ năm ngày một trận nặng" +>>> a = [Syllable.from_string(x) for x in text.split(' ')] +>>> a +[Syllable(b, a, ), Syllable(ng, ay, , \), Syllable(m, ô, t, .), Syllable(tr, â, n, .), Syllable(nh, e, , .), Syllable(n, ă, m), Syllable(ng, ay, , \), Syllable(m, ô, t, .), Syllable(tr, â, n, .), Syllable(n, ă, ng, .)] +>>> for syll in a: +... syll.onset = 'nh' +... +>>> a +[Syllable(nh, a, ), Syllable(nh, ay, , \), Syllable(nh, ô, t, .), Syllable(nh, â, n, .), Syllable(nh, e, , .), Syllable(nh, ă, m), Syllable(nh, ay, , \), Syllable(nh, ô, t, .), Syllable(nh, â, n, .), Syllable(nh, ă, ng, .)] +>>> ' '.join(str(x) for x in a) +'nha nhày nhột nhận nhẹ nhăm nhày nhột nhận nhặng' +``` + For further usages, see the documentation, which is hosted on [chiecthuyenngoaixa.readthedocs.io](https://chiecthuyenngoaixa.readthedocs.io/en/latest/). diff --git a/ctnx/syllable.py b/ctnx/syllable.py index 23b53d6..c430161 100644 --- a/ctnx/syllable.py +++ b/ctnx/syllable.py @@ -286,7 +286,7 @@ def vowel(self) -> str: return self.nucleus @property - def rhyme(self) -> str: - """The rhyme of the syllable, which is the combination of the vowel and the coda.""" + def rime(self) -> str: + """The rime of the syllable, which is the combination of the vowel and the coda.""" return self.vowel + self.coda diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 2ccfda3..8d0e46d 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -76,4 +76,34 @@ Other functions and classes are put into separate sub-modules. For example: >>> validation.parse_cccd("024192123456") CccdResult(id='123456', is_male=False, birth_year=1992, birth_country='vn', birth_province='Bắc Giang') +* To extract tones from a Vietnamese syllable or text: + + .. doctest:: + :pyversion: >= 3.8 + + >>> from ctnx.misc import separate_tone + >>> separate_tone("Đẩu") + ('Đâu', '?') + >>> toneNames = {'': 'thanh', '/': 'sắc', '\\': 'huyền', '?': 'hỏi', '~': 'ngã', '.': 'nặng'} + >>> ' '.join(toneNames[separate_tone(syll)[1]] for syll in "Tôi thầm cảm ơn Đẩu đã giữ mình ở nán lại".split(' ')) + 'thanh huyền hỏi thanh hỏi ngã ngã huyền hỏi sắc nặng' + +* To manipulate Vietnamese syllables: + + .. doctest:: + :pyversion: >= 3.8 + + >>> from ctnx.syllable import Syllable + >>> text = "ba ngày một trận nhẹ năm ngày một trận nặng" + >>> a = [Syllable.from_string(x) for x in text.split(' ')] + >>> a + [Syllable(b, a, ), Syllable(ng, ay, , \), Syllable(m, ô, t, .), Syllable(tr, â, n, .), Syllable(nh, e, , .), Syllable(n, ă, m), Syllable(ng, ay, , \), Syllable(m, ô, t, .), Syllable(tr, â, n, .), Syllable(n, ă, ng, .)] + >>> for syll in a: + ... syll.onset = 'nh' + ... + >>> a + [Syllable(nh, a, ), Syllable(nh, ay, , \), Syllable(nh, ô, t, .), Syllable(nh, â, n, .), Syllable(nh, e, , .), Syllable(nh, ă, m), Syllable(nh, ay, , \), Syllable(nh, ô, t, .), Syllable(nh, â, n, .), Syllable(nh, ă, ng, .)] + >>> ' '.join(str(x) for x in a) + 'nha nhày nhột nhận nhẹ nhăm nhày nhột nhận nhặng' + See :doc:`generated/api` section for full references. \ No newline at end of file