aklstemmer 0.1.0__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Andrian Lloyd Maagma
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,129 @@
1
+ Metadata-Version: 2.4
2
+ Name: aklstemmer
3
+ Version: 0.1.0
4
+ Summary: A library for Aklanon word stemming.
5
+ Author-email: Andrian Lloyd Maagma <maagmaandrian@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Andrian Lloyd Maagma
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: homepage, https://github.com/andrianllmm/aklstemmer
29
+ Project-URL: issues, https://github.com/andrianllmm/aklstemmer/issues
30
+ Keywords: stemmer,aklanon,affix removal
31
+ Classifier: Development Status :: 3 - Alpha
32
+ Classifier: License :: OSI Approved :: MIT License
33
+ Classifier: Programming Language :: Python :: 3.10
34
+ Classifier: Operating System :: OS Independent
35
+ Requires-Python: >=3.10
36
+ Description-Content-Type: text/markdown
37
+ License-File: LICENSE
38
+ Requires-Dist: nltk>=3.8.1
39
+ Requires-Dist: tabulate>=0.9.0
40
+ Dynamic: license-file
41
+
42
+ # AklStemmer
43
+
44
+ **A Python library for Aklanon word stemming**
45
+
46
+ ## About
47
+
48
+ AklStemmer is a library that finds the root form of
49
+ <a href="https://www.ethnologue.com/language/akl" target="_blank">Aklanon</a>
50
+ words. It works on inflected words, even those with mixed Aklanon-English terms
51
+ or those not found in dictionaries. It removes affixes, reduces repeated
52
+ syllables, and applies transformation rules to find possible root forms. These
53
+ are filtered using a list of valid words and conditions. The best root is then
54
+ chosen based on how much was changed during the process.
55
+
56
+ ## Installation
57
+
58
+ ```sh
59
+ pip install aklstemmer
60
+ ```
61
+
62
+ ## Usage
63
+
64
+ AklStemmer acts as a standalone library that can be imported via
65
+ `from aklstemmer import stemmer`.
66
+
67
+ Use `get_stem` to get the root of a word. This takes a word and returns its stem
68
+ as a `Stem` object (basically a string with affixes, reduplication,
69
+ transformations, etc. as additional attributes).
70
+
71
+ ```python
72
+ stem = stemmer.get_stem("nagsueat")
73
+ print(stem)
74
+ # Output: 'sueat'
75
+ ```
76
+
77
+ Since `get_stem` returns a `Stem` object, the properties used in the stemming
78
+ process can be accessed as attributes.
79
+
80
+ ```python
81
+ prefix = stem.pre
82
+ print(prefix)
83
+ # Output: 'nag'
84
+
85
+ suffix = stem.suf
86
+ print(suffix)
87
+ # Output: None
88
+ ```
89
+
90
+ Use `get_stems` to get the root of each word in a text. This takes a text and
91
+ returns the stem of each word as a list of `Stem` objects.
92
+
93
+ ```python
94
+ stems = stemmer.get_stems("nagsueat, binasa, ag gision")
95
+ print(stems)
96
+ # Output: ['sueat', 'basa', 'at', 'gisi']
97
+ ```
98
+
99
+ Use `get_stem_candidates` to get all the stem candidates of a word. This takes a
100
+ word and returns the possible stems as a list of `Stem` objects. This is helpful
101
+ for loose checking considering candidate selection is not perfect.
102
+
103
+ ```python
104
+ candidates = stemmer.get_stem_candidates("bukot")
105
+ print(candidates)
106
+ # Output: ['bukot', 'buko', 'bukon']
107
+ ```
108
+
109
+ ## Accuracy
110
+
111
+ The accuracy hasn't been tested yet.
112
+
113
+ ## Development
114
+
115
+ This project uses [uv](https://docs.astral.sh/uv/) for dependency management.
116
+
117
+ Clone the repo and sync dependencies (including dev and test groups):
118
+
119
+ ```sh
120
+ git clone https://github.com/andrianllmm/tagalog-stemmer.git
121
+ cd tagalog-stemmer
122
+ uv sync --all-groups
123
+ ```
124
+
125
+ Run the tests:
126
+
127
+ ```sh
128
+ uv run pytest
129
+ ```
@@ -0,0 +1,88 @@
1
+ # AklStemmer
2
+
3
+ **A Python library for Aklanon word stemming**
4
+
5
+ ## About
6
+
7
+ AklStemmer is a library that finds the root form of
8
+ <a href="https://www.ethnologue.com/language/akl" target="_blank">Aklanon</a>
9
+ words. It works on inflected words, even those with mixed Aklanon-English terms
10
+ or those not found in dictionaries. It removes affixes, reduces repeated
11
+ syllables, and applies transformation rules to find possible root forms. These
12
+ are filtered using a list of valid words and conditions. The best root is then
13
+ chosen based on how much was changed during the process.
14
+
15
+ ## Installation
16
+
17
+ ```sh
18
+ pip install aklstemmer
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ AklStemmer acts as a standalone library that can be imported via
24
+ `from aklstemmer import stemmer`.
25
+
26
+ Use `get_stem` to get the root of a word. This takes a word and returns its stem
27
+ as a `Stem` object (basically a string with affixes, reduplication,
28
+ transformations, etc. as additional attributes).
29
+
30
+ ```python
31
+ stem = stemmer.get_stem("nagsueat")
32
+ print(stem)
33
+ # Output: 'sueat'
34
+ ```
35
+
36
+ Since `get_stem` returns a `Stem` object, the properties used in the stemming
37
+ process can be accessed as attributes.
38
+
39
+ ```python
40
+ prefix = stem.pre
41
+ print(prefix)
42
+ # Output: 'nag'
43
+
44
+ suffix = stem.suf
45
+ print(suffix)
46
+ # Output: None
47
+ ```
48
+
49
+ Use `get_stems` to get the root of each word in a text. This takes a text and
50
+ returns the stem of each word as a list of `Stem` objects.
51
+
52
+ ```python
53
+ stems = stemmer.get_stems("nagsueat, binasa, ag gision")
54
+ print(stems)
55
+ # Output: ['sueat', 'basa', 'at', 'gisi']
56
+ ```
57
+
58
+ Use `get_stem_candidates` to get all the stem candidates of a word. This takes a
59
+ word and returns the possible stems as a list of `Stem` objects. This is helpful
60
+ for loose checking considering candidate selection is not perfect.
61
+
62
+ ```python
63
+ candidates = stemmer.get_stem_candidates("bukot")
64
+ print(candidates)
65
+ # Output: ['bukot', 'buko', 'bukon']
66
+ ```
67
+
68
+ ## Accuracy
69
+
70
+ The accuracy hasn't been tested yet.
71
+
72
+ ## Development
73
+
74
+ This project uses [uv](https://docs.astral.sh/uv/) for dependency management.
75
+
76
+ Clone the repo and sync dependencies (including dev and test groups):
77
+
78
+ ```sh
79
+ git clone https://github.com/andrianllmm/tagalog-stemmer.git
80
+ cd tagalog-stemmer
81
+ uv sync --all-groups
82
+ ```
83
+
84
+ Run the tests:
85
+
86
+ ```sh
87
+ uv run pytest
88
+ ```
@@ -0,0 +1,52 @@
1
+ [build-system]
2
+ requires = ["setuptools"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "aklstemmer"
7
+ version = "0.1.0"
8
+ description = "A library for Aklanon word stemming."
9
+ readme = "README.md"
10
+ license = {file = "LICENSE"}
11
+ authors = [
12
+ {name = "Andrian Lloyd Maagma", email = "maagmaandrian@gmail.com"}
13
+ ]
14
+ keywords = ["stemmer", "aklanon", "affix removal"]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Operating System :: OS Independent",
20
+ ]
21
+ requires-python = ">=3.10"
22
+
23
+ dependencies = [
24
+ "nltk>=3.8.1",
25
+ "tabulate>=0.9.0",
26
+ ]
27
+
28
+ [dependency-groups]
29
+ dev = [
30
+ "commitizen>=4.16.5",
31
+ "git-cliff>=2.13.1",
32
+ "pre-commit>=4.6.1",
33
+ "pytest>=9.1.1",
34
+ "pytest-cov>=7.1.0",
35
+ "ruff>=0.16.0",
36
+ "twine>=5.1.1",
37
+ "ty>=0.0.64",
38
+ ]
39
+
40
+ [project.urls]
41
+ homepage = "https://github.com/andrianllmm/aklstemmer"
42
+ issues = "https://github.com/andrianllmm/aklstemmer/issues"
43
+
44
+ [tool.setuptools]
45
+ package-data = {"aklstemmer" = ["resources/*.txt", "resources/affixes/*.txt"]}
46
+
47
+ [[tool.uv.index]]
48
+ name = "testpypi"
49
+ url = "https://test.pypi.org/simple/"
50
+ publish-url = "https://test.pypi.org/legacy/"
51
+ explicit = true
52
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -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,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,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,4 @@
1
+ in
2
+ um
3
+ il
4
+ ilin
@@ -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-
@@ -0,0 +1,26 @@
1
+ a
2
+ i
3
+ an
4
+ in
5
+ han
6
+ hin
7
+ nan
8
+ anan
9
+ nin
10
+ anin
11
+ non
12
+ anon
13
+ ang
14
+ ing
15
+ ita
16
+ ito
17
+ iti
18
+ dor
19
+ syon
20
+ siyon
21
+ contractions:
22
+ ng
23
+ g
24
+ 't
25
+ 'y
26
+ t