Skip to content

Commit 7029234

Browse files
authored
Merge pull request #1245 from PyThaiNLP/copilot/validate-example-code-docstrings
[WIP] Recheck example code for accuracy in PyThaiNLP
2 parents 26e7d41 + 1268078 commit 7029234

10 files changed

Lines changed: 15 additions & 15 deletions

File tree

docs/notes/command_line.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ You can use some `thainlp` functions directly from the command line.
2626

2727
**Part-of-speech tagging**::
2828

29-
pythainlp tagg pos [-s SEPARATOR] TEXT
29+
thainlp tag pos [-s SEPARATOR] TEXT
3030

3131
*Example*::
3232

examples/khavee.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
print("ชิชะ", kv.check_karu_lahu("ชิชะ"))
3333
# lahu
3434

35-
# การตรวจสอบกลอน 8 ที่ถูกฉันทลักษณ์
35+
# การตรวจสอบกลอน 8 ที่มีข้อผิดพลาดเล็กน้อย
3636
print(
3737
kv.check_klon(
3838
"""ณรงค์วุฒิผู้เปี่ยมวุฒิสมสง่า มากวิชาหาความรู้ไปสู่ผล
@@ -48,7 +48,7 @@
4848
k_type=8,
4949
)
5050
)
51-
# -> The poem is correct according to the principle.
51+
# -> ["Can't find rhyme between paragraphs ('ผล', 'ทน') in paragraph 1"]
5252

5353
# การตรวจสอบกลอน 8 ที่ผิดฉันทลักษณ์
5454
print(
@@ -67,6 +67,7 @@
6767
)
6868
)
6969
# -> [
70+
# "Can't find rhyme between paragraphs ('ผล', 'ทน') in paragraph 1",
7071
# "Can't find rhyme between paragraphs ('สอน', 'ไป') in paragraph 4",
7172
# "Can't find rhyme between paragraphs ('มี่', ['เกม', 'เอ่อ', 'เก่ง', 'กาจ']) in paragraph 5"
7273
# ]

pythainlp/corpus/wordnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def synsets(word: str, pos: Optional[str] = None, lang: str = "tha") -> list[wor
5353
[Synset('function.v.01'), Synset('work.v.02'),
5454
Synset('work.v.01'), Synset('work.v.08')]
5555
>>>
56-
>>> synsets("บ้าน", lang="tha"))
56+
>>> synsets("บ้าน", lang="tha")
5757
[Synset('duplex_house.n.01'), Synset('dwelling.n.01'),
5858
Synset('house.n.01'), Synset('family.n.01'), Synset('home.n.03'),
5959
Synset('base.n.14'), Synset('home.n.01'),

pythainlp/phayathaibert/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def replace_url(self, text: str) -> str:
3939
:rtype: str
4040
:Example:
4141
>>> replace_url("go to https://github.com")
42-
go to <url>
42+
'go to <url>'
4343
"""
4444
return re.sub(_PAT_URL, self._TK_URL, text)
4545

@@ -50,7 +50,7 @@ def rm_brackets(self, text: str) -> str:
5050
:rtype: str
5151
:Example:
5252
>>> rm_brackets("hey() whats[;] up{*&} man(hey)")
53-
hey whats up man(hey)
53+
'hey whats up man(hey)'
5454
"""
5555
# remove empty brackets
5656
new_line = re.sub(r"\(\)", "", text)

pythainlp/tag/_tag_perceptron.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class PerceptronTagger:
108108
[("นก", "N"), ("บิน", "V")],
109109
]
110110
>>> tagger.train(data)
111-
>>> tagger.tag(["นก", "เดิน])
111+
>>> tagger.tag(["นก", "เดิน"])
112112
[('นก', 'N'), ('เดิน', 'V')]
113113
114114
"""

pythainlp/tag/named_entity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def tag(
8484
>>> ner = NER("thainer")
8585
>>> ner.tag("ทดสอบ นายวรรณพงษ์ ภัททิยไพบูลย์")
8686
[('ทดสอบ', 'O'),
87-
[(' ', 'O'),
87+
(' ', 'O'),
8888
('นาย', 'B-PERSON'),
8989
('วรรณ', 'I-PERSON'),
9090
('พงษ์', 'I-PERSON'),

pythainlp/tag/thainer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ def get_ner(
173173
('น.', 'I-TIME')]
174174
>>> ner.get_ner("วันที่ 15 ก.ย. 61 ทดสอบระบบเวลา 14:49 น.",
175175
tag=True)
176-
'วันที่ <DATE>15 ก.ย. 61</DATE> ทดสอบระบบเวลา <TIME>
177-
14:49 น.</TIME>'
176+
'วันที่ <DATE>15 ก.ย. 61</DATE> ทดสอบระบบเวลา <TIME>14:49 น.</TIME>'
178177
"""
179178
tokens = word_tokenize(text, engine=_TOKENIZER_ENGINE)
180179
pos_tags = pos_tag(

pythainlp/ulmfit/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def process_thai(
132132
>>> from pythainlp.ulmfit import process_thai
133133
>>> text = "บ้านนนนน () อยู่นานนานนาน 😂🤣😃😄😅 PyThaiNLP amp; "
134134
>>> process_thai(text)
135-
[บ้าน', 'xxrep', ' ', 'อยู่', 'xxwrep', 'นาน', '😂', '🤣',
135+
['บ้าน', 'xxrep', ' ', 'อยู่', 'xxwrep', 'นาน', '😂', '🤣',
136136
'😃', '😄', '😅', 'pythainlp', '&']
137137
138138
2. Modify pre_rules and post_rules arguments with

pythainlp/ulmfit/preprocess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def replace_url(text: str) -> str:
3232
3333
>>> from pythainlp.ulmfit import replace_url
3434
>>> replace_url("go to github.com")
35-
go to xxurl
35+
'go to xxurl'
3636
"""
3737
URL_PATTERN = r"""(?i)\b((?:https?:(?:/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.](?:com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|Ja|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)/)(?:[^\s()<>{}\[\]]+|\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\))+(?:\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’])|(?:(?<!@)[a-z0-9]+(?:[.\-][a-z0-9]+)*[.](?:com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|Ja|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)\b/?(?!@)))"""
3838
return re.sub(URL_PATTERN, _TK_URL, text)
@@ -50,7 +50,7 @@ def fix_html(text: str) -> str:
5050
5151
>>> from pythainlp.ulmfit import fix_html
5252
>>> fix_html("Anbsp;amp;nbsp;B @.@ ")
53-
A & B.
53+
'A & B.'
5454
"""
5555
re1 = re.compile(r" +")
5656
text = (

pythainlp/word_vector/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def doesnt_match(self, words: list[str]) -> str:
9292
>>> wv = WordVector()
9393
>>> words = ["อาหารเช้า", "อาหารเที่ยง", "อาหารเย็น", "พริกไทย"]
9494
>>> wv.doesnt_match(words)
95-
พริกไทย
95+
'พริกไทย'
9696
9797
Pick the word "เรือ" (name of vehicle) out of the list of words
9898
related to occupation ("ดีไซน์เนอร์", "พนักงานเงินเดือน", "หมอ").
@@ -102,7 +102,7 @@ def doesnt_match(self, words: list[str]) -> str:
102102
>>> wv = WordVector()
103103
>>> words = ["ดีไซน์เนอร์", "พนักงานเงินเดือน", "หมอ", "เรือ"]
104104
>>> wv.doesnt_match(words)
105-
เรือ
105+
'เรือ'
106106
"""
107107
return self.model.doesnt_match(words)
108108

0 commit comments

Comments
 (0)