tglstemmer 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
tglstemmer/__init__.py ADDED
@@ -0,0 +1 @@
1
+ """A package for Tagalog word stemming."""
File without changes
@@ -0,0 +1,27 @@
1
+ import os
2
+
3
+ script_dir = os.path.dirname(os.path.realpath(__file__))
4
+
5
+
6
+ def get_affixes(type, folder_path=None):
7
+ """Get list of affixes from file.
8
+
9
+ Args:
10
+ type (str): Type of affixes to get. Value can only be:
11
+ - 'pre': Prefixes
12
+ - 'in': Infixes
13
+ - 'suf': Suffixes
14
+ folder_path (str, optional): Path to the folder containing .txt files of Tagalog affixes.
15
+
16
+ Returns:
17
+ list: A list of affixes of chosen type.
18
+ """
19
+ if folder_path is None:
20
+ folder_path = os.path.join(script_dir, "../resources/affixes/")
21
+ with open(os.path.join(folder_path, f"{type}fixes.txt")) as in_file:
22
+ return sorted([affix.strip() for affix in in_file], key=len)
23
+
24
+
25
+ PREFIXES = get_affixes("pre")
26
+ INFIXES = get_affixes("in")
27
+ SUFFIXES = get_affixes("suf")
@@ -0,0 +1,2 @@
1
+ VOWELS = set("aeiou")
2
+ CONSONANTS = set("bcdfghjklmnpqrstvwxyz")
@@ -0,0 +1,39 @@
1
+ from ..stem import Stem
2
+
3
+
4
+ def replace_letter(token, index, letter):
5
+ """Replaces a letter in a token.
6
+
7
+ Args:
8
+ token (str): Word to be updated.
9
+ index (int): Index of the letter to be replaced.
10
+ letter (str): Letter used to replace.
11
+
12
+ Returns:
13
+ str: The updated word.
14
+ """
15
+ token_as_list = list(token)
16
+
17
+ token_as_list[index] = letter
18
+
19
+ return Stem("".join(token_as_list), **token.__dict__)
20
+
21
+
22
+ def swap_letters(token, index1, index2):
23
+ """Swaps two letters in a token.
24
+
25
+ Args:
26
+ token (str): Word to be updated.
27
+ index1 (int): Index of the first letter to be swapped.
28
+ index2 (int): Index of the second letter to be swapped.
29
+
30
+ Returns:
31
+ str: The updated word.
32
+ """
33
+ token_as_list = list(token)
34
+
35
+ index1_letter = token_as_list[index1]
36
+ token_as_list[index1] = token_as_list[index2]
37
+ token_as_list[index2] = index1_letter
38
+
39
+ return Stem("".join(token_as_list), **token.__dict__)
@@ -0,0 +1,63 @@
1
+ from .alphabet import CONSONANTS, VOWELS
2
+
3
+
4
+ def is_valid(token, valid_words=None):
5
+ """Checks if token is valid against a list of words.
6
+
7
+ Args:
8
+ token (str): Any word to be tested.
9
+ valid_words (list): List of valid words. Defaults to None.
10
+
11
+ Returns:
12
+ str/bool: The token if token is valid, False otherwise.
13
+ """
14
+ if not valid_words:
15
+ return token
16
+
17
+ if token in valid_words:
18
+ return token
19
+
20
+ return False
21
+
22
+
23
+ def is_acceptable(token):
24
+ """Checks if token is acceptable against certain acceptability conditions.
25
+
26
+ Args:
27
+ token (str): Any word to be tested.
28
+
29
+ Returns:
30
+ str/bool: The token if token is acceptable, False otherwise.
31
+ """
32
+ if is_vowel(token[0]):
33
+ if len(token) == 2 or (len(token) >= 3 and any(is_consonant(c) for c in token)):
34
+ return token
35
+ elif is_consonant(token[0]) and (
36
+ len(token) == 3 or (len(token) >= 4 and any(is_vowel(c) for c in token))
37
+ ):
38
+ return token
39
+ return False
40
+
41
+
42
+ def is_vowel(*substring):
43
+ """Checks if a substring is a consonant.
44
+
45
+ Args:
46
+ *substring: Substrings to be tested.
47
+
48
+ Returns:
49
+ bool: True if substring is consonant, False otherwise.
50
+ """
51
+ return all(letter.lower() in VOWELS for letter in "".join(substring))
52
+
53
+
54
+ def is_consonant(*substring):
55
+ """Checks if a substring is a consonant.
56
+
57
+ Args:
58
+ *substring: Substrings to be tested.
59
+
60
+ Returns:
61
+ bool: True if substring is consonant, False otherwise.
62
+ """
63
+ return all(letter.lower() in CONSONANTS for letter in "".join(substring))
@@ -0,0 +1,17 @@
1
+ import os
2
+
3
+ script_dir = os.path.dirname(os.path.realpath(__file__))
4
+
5
+
6
+ def get_words(file_path=None):
7
+ """Get list of words from a Tagalog word list txt file.
8
+
9
+ Args:
10
+ file_path (str, optional): Path to the Tagalog word lsit txt file. Defaults to '<script_dir>/../resources/tgl_wordlist.txt'.
11
+ Returns:
12
+ list: A list of words.
13
+ """
14
+ if file_path is None:
15
+ file_path = os.path.join(script_dir, "../resources/tgl_wordlist.txt")
16
+ with open(file_path) as in_file:
17
+ return [word.strip().lower() for word in in_file]
@@ -0,0 +1,2 @@
1
+ in
2
+ um
@@ -0,0 +1,102 @@
1
+ i
2
+ ka
3
+ ika
4
+ pa
5
+ pang
6
+ pan
7
+ pam
8
+ pina
9
+ ipa
10
+ ipapa
11
+ paka
12
+ pakaka
13
+ pana
14
+ panana
15
+ pama
16
+ pamama
17
+ pinaka
18
+ pinakama
19
+ ma
20
+ mang
21
+ man
22
+ mam
23
+ mina
24
+ mai
25
+ maii
26
+ maka
27
+ makaka
28
+ makakapag
29
+ makapa
30
+ makapag
31
+ na
32
+ nang
33
+ nan
34
+ nam
35
+ nai
36
+ naii
37
+ naka
38
+ nakaka
39
+ nakakapag
40
+ nakapa
41
+ nakapag
42
+ napa
43
+ napapa
44
+ napaka
45
+ napag
46
+ sa
47
+ sang
48
+ san
49
+ sam
50
+ ni
51
+ mag
52
+ magka
53
+ magkaka
54
+ magpa
55
+ magpapa
56
+ nag
57
+ nagka
58
+ nagkaka
59
+ nagpa
60
+ nagpapa
61
+ pag
62
+ pagka
63
+ pagkaka
64
+ pagpa
65
+ pagpapa
66
+ pinag
67
+ ipag
68
+ ipinag
69
+ pinagka
70
+ pinagkaka
71
+ ipinagka
72
+ ipinagkaka
73
+ tag
74
+ tig
75
+ may
76
+ maki
77
+ makipag
78
+ makipagka
79
+ makikipag
80
+ makikipagka
81
+ naki
82
+ nakipag
83
+ nakipagka
84
+ nakikipag
85
+ nakikipagka
86
+ paki
87
+ pakiki
88
+ pakipag
89
+ pakipagka
90
+ pakikipag
91
+ pakikipagka
92
+ pala
93
+ mala
94
+ tiga
95
+ tigapag
96
+ taga
97
+ tagapag
98
+ sing
99
+ sin
100
+ sim
101
+ kasing
102
+ di-
@@ -0,0 +1,19 @@
1
+ an
2
+ in
3
+ han
4
+ hin
5
+ nan
6
+ anan
7
+ nin
8
+ anin
9
+ ang
10
+ ing
11
+ ita
12
+ ito
13
+ dor
14
+ syon
15
+ siyon
16
+ ng
17
+ g
18
+ 't
19
+ 'y