Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Thai language support #192

Merged
merged 3 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"Hebrew": ["hebrew_tokenizer"],
"Greek": ["greek-stemmer-pos"],
"Arabic": ["pyarabic"],
"Thai": ["pythainlp"],
},
packages=find_packages(),
package_data={"sumy": [
Expand Down Expand Up @@ -92,6 +93,7 @@
"Natural Language :: Ukrainian",
"Natural Language :: Greek",
"Natural Language :: Arabic",
"Natural Language :: Thai",

"Topic :: Education",
"Topic :: Internet",
Expand Down
115 changes: 115 additions & 0 deletions sumy/data/stopwords/thai.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
กล่าว
กว่า
กัน
กับ
การ
ก็
ก่อน
ขณะ
ขอ
ของ
ขึ้น
คง
ครั้ง
ความ
คือ
จะ
จัด
จาก
จึง
ช่วง
ซึ่ง
ดัง
ด้วย
ด้าน
ตั้ง
ตั้งแต่
ตาม
ต่อ
ต่าง
ต่างๆ
ต้อง
ถึง
ถูก
ถ้า
ทั้ง
ทั้งนี้
ทาง
ทำ
ทำให้
ที่
ที่สุด
ทุก
นอกจาก
นัก
นั้น
นำ
นี้
น่า
บาง
ผล
ผ่าน
พบ
พร้อม
มา
มาก
มี
ยัง
รวม
ระหว่าง
รับ
ราย
ร่วม
ลง
วัน
ว่า
สำหรับ
สุด
ส่ง
ส่วน
หนึ่ง
หรือ
หลัง
หลังจาก
หลาย
หาก
อยาก
อยู่
อย่าง
ออก
อะไร
อาจ
อีก
เขา
เข้า
เคย
เฉพาะ
เช่น
เดียว
เดียวกัน
เนื่องจาก
เปิด
เปิดเผย
เป็น
เป็นการ
เพราะ
เพื่อ
เมื่อ
เรา
เริ่ม
เลย
เห็น
เอง
แต่
แบบ
แรก
และ
แล้ว
แห่ง
โดย
ใน
ให้
ได้
ไป
ไม่
ไว้
22 changes: 22 additions & 0 deletions sumy/nlp/tokenizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,26 @@ def tokenize(text):
return sentence_tokenize(text)


class ThaiWordTokenizer:
@staticmethod
def tokenize(text):
try:
from pythainlp.tokenize import word_tokenize
except ImportError:
raise ValueError("Thai tokenizer requires pythainlp. Please, install it with 'pip install pythainlp'.")
return word_tokenize(text)


class ThaiSentencesTokenizer:
@staticmethod
def tokenize(text):
try:
from pythainlp.tokenize import sent_tokenize
except ImportError:
raise ValueError("Thai tokenizer requires pythainlp. Please, install it with 'pip install pythainlp'.")
return sent_tokenize(text)


class Tokenizer(object):
"""Language dependent tokenizer of text document."""

Expand Down Expand Up @@ -150,6 +170,7 @@ class Tokenizer(object):
'korean': KoreanSentencesTokenizer(),
'greek': GreekSentencesTokenizer(),
'arabic': ArabicSentencesTokenizer(),
'thai': ThaiSentencesTokenizer(),
}

SPECIAL_WORD_TOKENIZERS = {
Expand All @@ -159,6 +180,7 @@ class Tokenizer(object):
'korean': KoreanWordTokenizer(),
'greek': nltk.RegexpTokenizer(r"[ ,;;.!?:-]+", gaps=True),
'arabic': ArabicWordTokenizer(),
'thai': ThaiWordTokenizer(),
}

def __init__(self, language):
Expand Down
Loading