Skip to content

Commit eee760e

Browse files
committed
fix rule in normalize
1 parent d96aac7 commit eee760e

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

pythainlp/summarize/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def _rank(self, ranking, n):
2929

3030
def summarize(self, text, n):
3131
sents = sent_tokenize(text)
32-
assert n <= len(sents)
3332
word_sent = [word_tokenize(s) for s in sents]
3433
self._freq = self._compute_frequencies(word_sent)
3534
ranking = defaultdict(int)

pythainlp/util/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ def trigram(token):
4747
] # เก็บพวกสระ วรรณยุกต์ที่ซ้ำกันแล้วมีปัญหา
4848
rule2=[
4949
(u"เเ",u"แ"),
50-
(u"ํ้า",u"้ำ"),
51-
(u"ํา้",u"้ำ"),
52-
(u"้ั",u"ั้")
50+
(u"ํ(t)า",u"\\1ำ"),
51+
(u"ํา(t)",u"\\1ำ"),
52+
(u"([่-๋])([ัิ-ื])",u"\\2\\1")
5353
] # เก็บพวก พิมพ์ลำดับผิดหรือผิดแป้นแต่กลับแสดงผลถูกต้อง ให้ไปเป็นแป้นที่ถูกต้อง เช่น เ + เ ไปเป็น แ
5454
def normalize(text):
5555
"""
@@ -60,6 +60,8 @@ def normalize(text):
6060
>>> print(normalize("เเปลก")=="แปลก") # เ เ ป ล ก กับ แปลก
6161
True
6262
"""
63-
for data in rule2+list(zip(rule1,rule1)):
64-
text=re.sub(data[0]+"+",data[1],text,re.U)
63+
for data in rule2:
64+
text=re.sub(data[0].replace("t","[่้๊๋]"),data[1],text,re.U)
65+
for data in list(zip(rule1,rule1)):
66+
text=re.sub(data[0].replace("t","[่้๊๋]")+"+",data[1],text,re.U)
6567
return text

0 commit comments

Comments
 (0)