Skip to content

Commit f9888bd

Browse files
authored
Merge pull request #160 from bact/dev
Utility functions: rearrange package locations + add thai_strftime() date and time formatter
2 parents c89bb0d + 0e11673 commit f9888bd

40 files changed

+735
-592
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ where ```extras``` can be
5656
- ```deepcut``` (to support deepcut machine-learnt tokenizer)
5757
- ```icu``` (for ICU support in transliteration and tokenization)
5858
- ```ipa``` (for International Phonetic Alphabet support in transliteration)
59-
- ```ml``` (to support ULMFiT models, like one for sentiment analyser)
59+
- ```ml``` (to support ULMFiT models)
6060
- ```ner``` (for named-entity recognizer)
6161
- ```thai2rom``` (for machine-learnt romanization)
6262
- ```thai2vec``` (for Thai word vector)
@@ -141,7 +141,7 @@ $ pip install pythainlp[extra1,extra2,...]
141141
- ```deepcut``` (สำหรับตัวตัดคำ deepcut)
142142
- ```icu``` (สำหรับการถอดตัวสะกดเป็นสัทอักษรและการตัดคำด้วย ICU)
143143
- ```ipa``` (สำหรับการถอดตัวสะกดเป็นสัทอักษรสากล (IPA))
144-
- ```ml``` (สำหรับการรองรับโมเดล ULMFiT ซึ่งใช้ในฟังก์ชันเช่นการวิเคราะห์อารมณ์)
144+
- ```ml``` (สำหรับการรองรับโมเดล ULMFiT)
145145
- ```ner``` (สำหรับการติดป้ายชื่อเฉพาะ (named-entity))
146146
- ```thai2rom``` (สำหรับการถอดตัวสะกดเป็นอักษรละติน)
147147
- ```thai2vec``` (สำหรับ word vector)

Diff for: docs/api/change.rst

-11
This file was deleted.

Diff for: docs/api/collation.rst

-7
This file was deleted.

Diff for: docs/api/date.rst

-7
This file was deleted.

Diff for: docs/api/ner.rst

-11
This file was deleted.

Diff for: docs/api/number.rst

-12
This file was deleted.

Diff for: docs/api/sentiment.rst

-7
This file was deleted.

Diff for: docs/api/soundex.rst

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ pythainlp.soundex
44
====================================
55
The :class:`pythainlp.soundex` is soundex for thai.
66

7+
Modules
8+
-------
9+
710
.. autofunction:: lk82
811
.. autofunction:: udom83
912
.. autofunction:: metasound

Diff for: docs/api/spell.rst

+3
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ pythainlp.spell
44
=====================================
55
The :class:`pythainlp.spell` finds the closest correctly spelled word to the given text.
66

7+
Modules
8+
-------
9+
710
.. autofunction:: spell

Diff for: docs/api/tag.rst

+5
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@ pythainlp.tag
44
=====================================
55
The :class:`pythainlp.tag` contains functions that are used to tag different parts of a text.
66

7+
Modules
8+
-------
9+
710
.. autofunction:: pos_tag
11+
.. autoclass:: ThaiNameTagger
12+
:members: get_ner

Diff for: docs/api/tokenize.rst

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ pythainlp.tokenize
55
=====================================
66
The :class:`pythainlp.tokenize` contains multiple functions for tokenizing a chunk of Thai text into desirable units.
77

8+
Modules
9+
-------
10+
811
.. autofunction:: word_tokenize
912
.. autofunction:: dict_word_tokenize
1013
.. autofunction:: subword_tokenize

Diff for: docs/api/romanization.rst renamed to docs/api/transliterate.rst

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ pythainlp.transliterate
44
====================================
55
The :class:`pythainlp.transliterate` turns Thai text into a romanized one (put simply, spelled with English).
66

7+
Modules
8+
-------
9+
10+
.. autofunction:: romanize
711
.. autofunction:: transliterate
8-
.. currentmodule:: pythainlp.transliterate.thai2rom
9-
.. autoclass:: thai2rom
12+
.. currentmodule:: pythainlp.transliterate.ThaiTransliterator
13+
.. autoclass:: ThaiTransliterator
1014
:members: romanize

Diff for: docs/api/util.rst

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.. currentmodule:: pythainlp.util
2+
3+
pythainlp.util
4+
=====================================
5+
The :class:`pythainlp.util` contains utility functions, like text conversion and formatting
6+
7+
Modules
8+
-------
9+
10+
.. autofunction:: arabic_digit_to_thai_digit
11+
.. autofunction:: bahttext
12+
.. autofunction:: collate
13+
.. autofunction:: deletetone
14+
.. autofunction:: digit_to_text
15+
.. autofunction:: eng_to_thai
16+
.. autofunction:: find_keyword
17+
.. autofunction:: is_thai
18+
.. autofunction:: is_thaichar
19+
.. autofunction:: is_thaiword
20+
.. autofunction:: normalize
21+
.. autofunction:: now_reign_year
22+
.. autofunction:: num_to_thaiword
23+
.. autofunction:: rank
24+
.. autofunction:: reign_year_to_ad
25+
.. autofunction:: text_to_arabic_digit
26+
.. autofunction:: text_to_thai_digit
27+
.. autofunction:: thai_strftime
28+
.. autofunction:: thai_to_eng
29+
.. autofunction:: thai_digit_to_arabic_digit
30+
.. autofunction:: thaiword_to_num

Diff for: docs/pythainlp-dev-thai.md

+13-28
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,6 @@ summarize(text="อาหาร หมายถึง ของแข็งห
215215

216216
สร้างเวกเตอร์คำ
217217

218-
```python
219-
from pythainlp.word_vector import thai2vec
220-
```
221-
222-
ปัจจุบันรองรับเฉพาะ thai2vec (https://github.com/cstorm125/thai2vec)
223-
224-
พัฒนาโดย Charin Polpanumas
225218

226219
#### thai2vec
227220

@@ -247,6 +240,8 @@ from pythainlp.word_vector import thai2vec
247240
การทำงาน หาคำที่ถูกใช้งานมากกว่าค่าขั้นต่ำที่กำหนดได้ โดยจะลบ stopword ออก
248241

249242
```python
243+
from pythainlp.util import find_keyword
244+
250245
find_keyword(word_list, lentext=3)
251246
```
252247

@@ -347,22 +342,26 @@ thaiword_to_num(["หกหมื่น", "หกพัน", "หกร้อย
347342
เรียงลำดับข้อมูลภาษาไทยใน List
348343

349344
```python
350-
from pythainlp.collation import collate
345+
from pythainlp.util import collate
351346
print(collate(["ไก่", "ไข่", "กา", "ฮา"])) # ['กา', 'ไก่', 'ไข่', 'ฮา']
352347
```
353348

354349
รับ list คืนค่า list
355350

356351
### date
357352

358-
#### now
353+
#### thai_strftime
359354

360-
รับเวลาปัจจุบันเป็นภาษาไทย
355+
จัดรูปแบบข้อความบอกวันที่และเวลาเป็นภาษาไทยและปีพุทธศักราช
361356

362357
```python
363-
from pythainlp.date import now
358+
import datetime
359+
from pythainlp.util import thai_strftime
364360

365-
now() # '30 พฤษภาคม 2560 18:45:24'
361+
fmt = "%Aที่ %-d %B พ.ศ. %Y เวลา %H:%Mน. (%a %d-%b-%y)"
362+
date = datetime.datetime(1976, 10, 6, 1, 40)
363+
print(thai_strftime(date, fmt))
364+
# วันพุธที่ 6 ตุลาคม พ.ศ. 2519 เวลา 01:40น. (พ 06-ต.ค.-19)
366365
```
367366
### rank
368367

@@ -371,7 +370,7 @@ now() # '30 พฤษภาคม 2560 18:45:24'
371370
หาคำที่มีจำนวนการใช้งานมากที่สุด
372371

373372
```python
374-
from pythainlp.rank import rank
373+
from pythainlp.util import rank
375374

376375
rank(list)
377376
```
@@ -408,20 +407,6 @@ print(udom83("รถ")) # ร800000
408407
print(metasound("รัก")) # 'ร100'
409408
```
410409

411-
### sentiment
412-
413-
sentiment analysis ภาษาไทย ใช้ข้อมูลจาก [https://github.com/PyThaiNLP/lexicon-thai/tree/master/ข้อความ/](https://github.com/PyThaiNLP/lexicon-thai/tree/master/ข้อความ/)
414-
415-
```python
416-
from pythainlp.sentiment import sentiment
417-
418-
sentiment(str)
419-
```
420-
421-
รับค่า str
422-
423-
คืนค่าเป็น str ซึ่งมีค่า "pos" หรือ "neg"
424-
425410
### Util
426411

427412
#### normalize
@@ -559,7 +544,7 @@ for province in provinces():
559544
สำหรับใช้ติดป้ายกำกับชื่อจังหวัดในประเทศไทย
560545

561546
```python
562-
from pythainlp.ner.locations import tag_provinces
547+
from pythainlp.tag.locations import tag_provinces
563548

564549
tag_provinces(text_list)
565550
```
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
22

3-
from pythainlp.collation import collate
3+
from pythainlp.util import collate
44

55
print(collate(["ไก่", "ไข่", "ก", "ฮา"])) # ['ก', 'ไก่', 'ไข่', 'ฮา']

Diff for: examples/date.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import datetime
4+
from pythainlp.util import thai_strftime
5+
6+
fmt = "%Aที่ %-d %B พ.ศ. %Y เวลา %H:%Mน. (%a %d-%b-%y)"
7+
date = datetime.datetime(1976, 10, 6, 1, 40)
8+
9+
# วันพุธที่ 6 ตุลาคม พ.ศ. 2519 เวลา 01:40น. (พ 06-ต.ค.-19)
10+
print(thai_strftime(date, fmt))

Diff for: pythainlp/__init__.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@
2424
thai_characters = "".join([thai_letters, thai_punctuations, thai_digits, thai_symbols])
2525

2626

27-
from pythainlp.collation import collate
28-
from pythainlp.date import now
29-
from pythainlp.transliterate import romanize, transliterate
3027
from pythainlp.soundex import soundex
3128
from pythainlp.spell import spell
3229
from pythainlp.tag import pos_tag
3330
from pythainlp.tokenize import sent_tokenize, tcc, word_tokenize
31+
from pythainlp.transliterate import romanize, transliterate
32+
from pythainlp.util import collate, thai_strftime

Diff for: pythainlp/collation/__init__.py

-8
This file was deleted.

Diff for: pythainlp/date/__init__.py

-60
This file was deleted.

Diff for: pythainlp/keywords/__init__.py

-16
This file was deleted.

Diff for: pythainlp/number/__init__.py

-25
This file was deleted.

0 commit comments

Comments
 (0)