|
4 | 4 |
|
5 | 5 | Has three systems to choose from: Udom83 (default), LK82, and MetaSound |
6 | 6 | """ |
| 7 | + |
| 8 | +__all__ = [ |
| 9 | + "soundex", |
| 10 | + "lk82", |
| 11 | + "metasound", |
| 12 | + "udom83", |
| 13 | +] |
| 14 | + |
7 | 15 | from pythainlp.soundex.lk82 import lk82 |
8 | 16 | from pythainlp.soundex.metasound import metasound |
9 | 17 | from pythainlp.soundex.udom83 import udom83 |
10 | 18 |
|
11 | | -# Other Thai soundex systems (not implemented yet): Arun91, KSS97 |
12 | | -# [KSS97] https://linux.thai.net/~thep/soundex/soundex.html |
13 | | - |
14 | 19 | DEFAULT_SOUNDEX_ENGINE = "udom83" |
15 | 20 |
|
16 | | - |
17 | | -def soundex(text: str, engine: str = DEFAULT_SOUNDEX_ENGINE) -> str: |
18 | | - """ |
19 | | - This function converts Thai text into phonetic code. |
20 | | -
|
21 | | - :param string text: word |
22 | | - :param str engine: soundex engine |
23 | | - :return: Soundex code |
24 | | - :rtype: str |
25 | | -
|
26 | | - :Options for engine: |
27 | | - * *udom83* (default) - Thai soundex algorithm proposed |
28 | | - by Vichit Lorchirachoonkul [#udom83]_ |
29 | | - * *lk82* - Thai soundex algorithm proposed by |
30 | | - Wannee Udompanich [#lk82]_ |
31 | | - * *metasound* - Thai soundex algorithm based on a combination |
32 | | - of Metaphone and Soundex proposed by Snae & Brückner [#metasound]_ |
33 | | -
|
34 | | - :Example: |
35 | | - :: |
36 | | -
|
37 | | - from pythainlp.soundex import soundex |
38 | | -
|
39 | | - soundex("ลัก"), soundex("ลัก", engine='lk82'), \\ |
40 | | - soundex("ลัก", engine='metasound') |
41 | | - # output: ('ร100000', 'ร1000', 'ล100') |
42 | | -
|
43 | | - soundex("รัก"), soundex("รัก", engine='lk82'), \\ |
44 | | - soundex("รัก", engine='metasound') |
45 | | - # output: ('ร100000', 'ร1000', 'ร100') |
46 | | -
|
47 | | - soundex("รักษ์"), soundex("รักษ์", engine='lk82'), \\ |
48 | | - soundex("รักษ์", engine='metasound') |
49 | | - # output: ('ร100000', 'ร1000', 'ร100') |
50 | | -
|
51 | | - soundex("บูรณการ"), soundex("บูรณการ", engine='lk82'), \\ |
52 | | - soundex("บูรณการ", engine='metasound') |
53 | | - # output: ('บ931900', 'บE419', 'บ551') |
54 | | -
|
55 | | - soundex("ปัจจุบัน"), soundex("ปัจจุบัน", engine='lk82'), \\ |
56 | | - soundex("ปัจจุบัน", engine='metasound') |
57 | | - # output: ('ป775300', 'ป3E54', 'ป223') |
58 | | - """ |
59 | | - if engine == "lk82": |
60 | | - _soundex = lk82 |
61 | | - elif engine == "metasound": |
62 | | - _soundex = metasound |
63 | | - else: # default, use "udom83" |
64 | | - _soundex = udom83 |
65 | | - |
66 | | - return _soundex(text) |
| 21 | +from pythainlp.soundex.core import soundex |
0 commit comments