aklstemmer 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.
- aklstemmer/__init__.py +1 -0
- aklstemmer/helpers/__init__.py +0 -0
- aklstemmer/helpers/affixes.py +27 -0
- aklstemmer/helpers/alphabet.py +2 -0
- aklstemmer/helpers/manipulation.py +39 -0
- aklstemmer/helpers/validation.py +64 -0
- aklstemmer/helpers/words.py +17 -0
- aklstemmer/resources/affixes/infixes.txt +4 -0
- aklstemmer/resources/affixes/prefixes.txt +139 -0
- aklstemmer/resources/affixes/suffixes.txt +26 -0
- aklstemmer/resources/akl_wordlist.txt +4471 -0
- aklstemmer/stem.py +117 -0
- aklstemmer/stemmer.py +670 -0
- aklstemmer-0.1.0.dist-info/METADATA +129 -0
- aklstemmer-0.1.0.dist-info/RECORD +18 -0
- aklstemmer-0.1.0.dist-info/WHEEL +5 -0
- aklstemmer-0.1.0.dist-info/licenses/LICENSE +21 -0
- aklstemmer-0.1.0.dist-info/top_level.txt +1 -0
aklstemmer/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""A package for Aklanon 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 Aklanon 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,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,64 @@
|
|
|
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]) and (
|
|
33
|
+
len(token) == 2 or (len(token) >= 3 and any(is_consonant(c) for c in token))
|
|
34
|
+
):
|
|
35
|
+
return token
|
|
36
|
+
if is_consonant(token[0]) and (
|
|
37
|
+
len(token) == 3 or (len(token) >= 4 and any(is_vowel(c) for c in token))
|
|
38
|
+
):
|
|
39
|
+
return token
|
|
40
|
+
return False
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def is_vowel(*substring):
|
|
44
|
+
"""Checks if a substring is a consonant.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
*substring: Substrings to be tested.
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
bool: True if substring is consonant, False otherwise.
|
|
51
|
+
"""
|
|
52
|
+
return all(letter.lower() in VOWELS for letter in "".join(substring))
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def is_consonant(*substring):
|
|
56
|
+
"""Checks if a substring is a consonant.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
*substring: Substrings to be tested.
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
bool: True if substring is consonant, False otherwise.
|
|
63
|
+
"""
|
|
64
|
+
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 Aklanon word list txt file.
|
|
8
|
+
|
|
9
|
+
Args:
|
|
10
|
+
file_path (str, optional): Path to the Aklanon word lsit txt file. Defaults to '<script_dir>/../resources/akl_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/akl_wordlist.txt")
|
|
16
|
+
with open(file_path) as in_file:
|
|
17
|
+
return [word.strip().lower() for word in in_file]
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
i
|
|
2
|
+
ig
|
|
3
|
+
iga
|
|
4
|
+
ieog
|
|
5
|
+
inog
|
|
6
|
+
isigka
|
|
7
|
+
ka
|
|
8
|
+
ika
|
|
9
|
+
pa
|
|
10
|
+
pang
|
|
11
|
+
pan
|
|
12
|
+
pam
|
|
13
|
+
pina
|
|
14
|
+
ipa
|
|
15
|
+
ipapa
|
|
16
|
+
paka
|
|
17
|
+
pakaka
|
|
18
|
+
pana
|
|
19
|
+
panana
|
|
20
|
+
pama
|
|
21
|
+
pamama
|
|
22
|
+
pinaka
|
|
23
|
+
pinakama
|
|
24
|
+
ma
|
|
25
|
+
mang
|
|
26
|
+
man
|
|
27
|
+
mam
|
|
28
|
+
mina
|
|
29
|
+
mai
|
|
30
|
+
maii
|
|
31
|
+
maka
|
|
32
|
+
makaka
|
|
33
|
+
makakapag
|
|
34
|
+
makapa
|
|
35
|
+
makapag
|
|
36
|
+
mapa
|
|
37
|
+
mapapa
|
|
38
|
+
mapag
|
|
39
|
+
manog
|
|
40
|
+
maeog
|
|
41
|
+
mansig
|
|
42
|
+
masig
|
|
43
|
+
matsig
|
|
44
|
+
na
|
|
45
|
+
nang
|
|
46
|
+
nan
|
|
47
|
+
nam
|
|
48
|
+
nai
|
|
49
|
+
naii
|
|
50
|
+
naka
|
|
51
|
+
nakaka
|
|
52
|
+
nakakapag
|
|
53
|
+
nakapa
|
|
54
|
+
nakapag
|
|
55
|
+
napa
|
|
56
|
+
napapa
|
|
57
|
+
napaka
|
|
58
|
+
napag
|
|
59
|
+
ga
|
|
60
|
+
gina
|
|
61
|
+
gi
|
|
62
|
+
ging
|
|
63
|
+
gin
|
|
64
|
+
sa
|
|
65
|
+
sang
|
|
66
|
+
san
|
|
67
|
+
sam
|
|
68
|
+
ha
|
|
69
|
+
maha
|
|
70
|
+
mahag
|
|
71
|
+
naha
|
|
72
|
+
nahag
|
|
73
|
+
hi
|
|
74
|
+
mahi
|
|
75
|
+
nahi
|
|
76
|
+
hili
|
|
77
|
+
hing
|
|
78
|
+
ni
|
|
79
|
+
mag
|
|
80
|
+
magka
|
|
81
|
+
magkaka
|
|
82
|
+
magpa
|
|
83
|
+
magpapa
|
|
84
|
+
nag
|
|
85
|
+
nagka
|
|
86
|
+
nagkaka
|
|
87
|
+
nagpa
|
|
88
|
+
nagpapa
|
|
89
|
+
pag
|
|
90
|
+
pagka
|
|
91
|
+
pagkaka
|
|
92
|
+
pagpa
|
|
93
|
+
pagpapa
|
|
94
|
+
pinag
|
|
95
|
+
ipag
|
|
96
|
+
ipinag
|
|
97
|
+
pinagka
|
|
98
|
+
pinagkaka
|
|
99
|
+
ipinagka
|
|
100
|
+
ipinagkaka
|
|
101
|
+
tag
|
|
102
|
+
natag
|
|
103
|
+
tig
|
|
104
|
+
natig
|
|
105
|
+
may
|
|
106
|
+
maki
|
|
107
|
+
makig
|
|
108
|
+
makiki
|
|
109
|
+
makipag
|
|
110
|
+
makipagka
|
|
111
|
+
makikipag
|
|
112
|
+
makikipagka
|
|
113
|
+
naki
|
|
114
|
+
nakig
|
|
115
|
+
nakiki
|
|
116
|
+
nakipag
|
|
117
|
+
nakipagka
|
|
118
|
+
nakikipag
|
|
119
|
+
nakikipagka
|
|
120
|
+
paki
|
|
121
|
+
pakig
|
|
122
|
+
pakiki
|
|
123
|
+
pakipag
|
|
124
|
+
pakipagka
|
|
125
|
+
pakikipag
|
|
126
|
+
pakikipagka
|
|
127
|
+
pala
|
|
128
|
+
paea
|
|
129
|
+
mala
|
|
130
|
+
maea
|
|
131
|
+
tiga
|
|
132
|
+
tigapag
|
|
133
|
+
taga
|
|
134
|
+
tagapag
|
|
135
|
+
sing
|
|
136
|
+
sin
|
|
137
|
+
sim
|
|
138
|
+
kasing
|
|
139
|
+
di-
|