sinkit 1.0.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.
sinkit-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Trishan (gosdrkht)
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,3 @@
1
+ include README.md
2
+ include LICENSE
3
+ recursive-include data *.json
sinkit-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,400 @@
1
+ Metadata-Version: 2.4
2
+ Name: sinkit
3
+ Version: 1.0.0
4
+ Summary: The missing developer toolkit for Sinhala language processing
5
+ Home-page: https://github.com/gosdrkht/sinhala-toolkit
6
+ Author: gosdrkht
7
+ Project-URL: Bug Reports, https://github.com/gosdrkht/sinhala-toolkit/issues
8
+ Project-URL: Source, https://github.com/gosdrkht/sinhala-toolkit
9
+ Keywords: sinhala nlp tokenizer text-processing sri-lanka sinhalese natural-language-processing
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Topic :: Text Processing :: Linguistic
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Requires-Python: >=3.8
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Dynamic: author
24
+ Dynamic: classifier
25
+ Dynamic: description
26
+ Dynamic: description-content-type
27
+ Dynamic: home-page
28
+ Dynamic: keywords
29
+ Dynamic: license-file
30
+ Dynamic: project-url
31
+ Dynamic: requires-python
32
+ Dynamic: summary
33
+
34
+ <div align="center">
35
+
36
+ # 🇱🇰 sinhala-toolkit
37
+ **The missing developer toolkit for Sinhala language processing**
38
+
39
+ සිංහල භාෂා සැකසීම සඳහා නවීන developer toolkit එක
40
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
41
+ [![PHP Version](https://img.shields.io/badge/PHP-8.1%2B-blue.svg)](https://php.net)
42
+ [![Sinhala NLP](https://img.shields.io/badge/NLP-Sinhala-green.svg)]()
43
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
44
+ [![GitHub Stars](https://img.shields.io/github/stars/gosdrkht/sinhala-toolkit?style=social)]()
45
+
46
+ [English](#english) · [සිංහල](#sinhala) · [Quick Start](#quick-start) · [API Reference](#api-reference) · [Contributing](#contributing)
47
+
48
+ </div>
49
+
50
+ ---
51
+
52
+ ## Why this exists
53
+
54
+ There are academic NLP papers on Sinhala. There are scattered university datasets. But if you're a developer who wants to **just use** a Sinhala tokenizer, cleaner, or stopword filter in your PHP project today — you had nothing.
55
+
56
+ Until now.
57
+
58
+ `sinhala-toolkit` is production-ready, zero-dependency Sinhala NLP for PHP developers. Built for the Sri Lankan dev community, by a Sri Lankan developer.
59
+
60
+ ---
61
+
62
+ <a name="english"></a>
63
+
64
+ ## Features
65
+
66
+ | Feature | Status |
67
+ |---|---|
68
+ | 📋 Stopwords list (120+ curated words, categorised) | ✅ Ready |
69
+ | 🧹 Text cleaner (Unicode, ZWJ, whitespace, noise) | ✅ Ready |
70
+ | ✂️ Sentence tokenizer (danda, mixed punctuation) | ✅ Ready |
71
+ | 🔤 Word tokenizer (Sinhala, English, mixed) | ✅ Ready |
72
+ | 🔍 Token type classifier (sinhala/english/number/mixed) | ✅ Ready |
73
+ | 🧬 Grapheme cluster splitter (ZWJ conjuncts) | ✅ Ready |
74
+ | 📊 Word frequency counter | ✅ Ready |
75
+ | 🔡 Script detector (sinhala/english/mixed/unknown) | ✅ Ready |
76
+ | 💬 Singlish transliterator | 🔲 Coming soon |
77
+ | 😊 Sentiment analyser | 🔲 Coming soon |
78
+ | 🚫 Profanity filter | 🔲 Coming soon |
79
+
80
+ ---
81
+
82
+ ## Quick Start
83
+
84
+ ### Installation
85
+
86
+ **Option 1 — Manual (shared hosting friendly)**
87
+
88
+ Download and drop the `src/` folder into your project:
89
+
90
+ ```php
91
+ require_once 'src/TextCleaner.php';
92
+ require_once 'src/Tokenizer.php';
93
+
94
+ use SinhalaToolkit\TextCleaner;
95
+ use SinhalaToolkit\Tokenizer;
96
+ ```
97
+
98
+ **Option 2 — Composer** *(coming soon)*
99
+
100
+ ```bash
101
+ composer require gosdrkht/sinhala-toolkit
102
+ ```
103
+
104
+ ---
105
+
106
+ ## Usage Examples
107
+
108
+ ### Text Cleaner
109
+
110
+ ```php
111
+ use SinhalaToolkit\TextCleaner;
112
+
113
+ $cleaner = new TextCleaner('/path/to/data/stopwords.json');
114
+
115
+ // Full clean pipeline
116
+ $raw = " මම සහ ඔබ හොඳ ගුරුවරයා ළඟ ඉගෙන ගත්තා ";
117
+ $text = $cleaner->clean($raw, [
118
+ 'remove_stopwords' => true,
119
+ ]);
120
+ // Output: "හොඳ ගුරුවරයා ඉගෙන ගත්තා"
121
+
122
+ // Remove English and numbers from mixed text
123
+ $mixed = "මෙය good idea එකක් වේ 2024 දී";
124
+ $clean = $cleaner->clean($mixed, [
125
+ 'remove_english' => true,
126
+ 'remove_numbers' => true,
127
+ ]);
128
+ // Output: "මෙය එකක් වේ"
129
+
130
+ // Detect script
131
+ $cleaner->detectScript("ආයුබෝවන්"); // "sinhala"
132
+ $cleaner->detectScript("Hello World"); // "english"
133
+ $cleaner->detectScript("Hello ආයුබෝවන්"); // "mixed"
134
+
135
+ // Check stopwords
136
+ $cleaner->isStopword("මම"); // true
137
+ $cleaner->isStopword("ගුරු"); // false
138
+ $cleaner->isStopword("සඳහා"); // true
139
+ ```
140
+
141
+ ---
142
+
143
+ ### Tokenizer
144
+
145
+ ```php
146
+ use SinhalaToolkit\Tokenizer;
147
+
148
+ $tokenizer = new Tokenizer();
149
+
150
+ // --- Sentence tokenization ---
151
+
152
+ $text = "ඔහු ගෙදර ගියා। ඇය පාසලට ගියාය। ළමයි ක්‍රීඩා කළා।";
153
+ $sentences = $tokenizer->splitSentences($text);
154
+ // [
155
+ // "ඔහු ගෙදර ගියා",
156
+ // "ඇය පාසලට ගියාය",
157
+ // "ළමයි ක්‍රීඩා කළා"
158
+ // ]
159
+
160
+ // Works with mixed-language text too
161
+ $mixed = "What is your name? ඔබේ නම කුමක්ද?";
162
+ $sentences = $tokenizer->splitSentences($mixed);
163
+ // ["What is your name", "ඔබේ නම කුමක්ද"]
164
+
165
+
166
+ // --- Word tokenization ---
167
+
168
+ $tokens = $tokenizer->tokenize("ශ්‍රී ලංකාව ලස්සන රටකි");
169
+ // ["ශ්‍රී", "ලංකාව", "ලස්සන", "රටකි"]
170
+
171
+
172
+ // --- Tokenize with type metadata ---
173
+
174
+ $typed = $tokenizer->tokenizeWithTypes("ලංකා cricket team 2024 දී ජය ගත්තා");
175
+ // [
176
+ // ["token" => "ලංකා", "type" => "sinhala"],
177
+ // ["token" => "cricket", "type" => "english"],
178
+ // ["token" => "team", "type" => "english"],
179
+ // ["token" => "2024", "type" => "number"],
180
+ // ["token" => "දී", "type" => "sinhala"],
181
+ // ["token" => "ජය", "type" => "sinhala"],
182
+ // ["token" => "ගත්තා", "type" => "sinhala"],
183
+ // ]
184
+
185
+
186
+ // --- Filter by type ---
187
+
188
+ $text = "Ceylon Ledger මගින් ඔබේ business 2024 සිට manage කරන්න";
189
+
190
+ $tokenizer->tokenizeByType($text, 'sinhala');
191
+ // ["මගින්", "ඔබේ", "සිට", "කරන්න"]
192
+
193
+ $tokenizer->tokenizeByType($text, 'english');
194
+ // ["Ceylon", "Ledger", "business", "manage"]
195
+
196
+
197
+ // --- Word frequency ---
198
+
199
+ $text = "ශ්‍රී ලංකාව ලස්සන රටකි ශ්‍රී ලංකාව හොඳ රටකි ශ්‍රී ලංකාව";
200
+ $freq = $tokenizer->frequency($text);
201
+ // ["ශ්‍රී" => 3, "ලංකාව" => 3, "රටකි" => 2, ...]
202
+
203
+
204
+ // --- Grapheme clusters (ZWJ conjuncts) ---
205
+
206
+ // ශ්‍රී contains a ZWJ conjunct consonant — kept intact as one cluster
207
+ $clusters = $tokenizer->graphemes("ශ්‍රී");
208
+ // ["ශ්‍රී"] ← treated as a single grapheme unit
209
+ ```
210
+
211
+ ---
212
+
213
+ ## Real-World Use Cases
214
+
215
+ **Search & filtering** — Strip stopwords before indexing Sinhala content so "ගෙදර ගෙදරට ගෙදරයි" all match "ගෙදර"
216
+
217
+ **Content moderation** — Detect script type to route Sinhala vs English vs mixed comments to the right classifier
218
+
219
+ **SMS / WhatsApp bots** — Clean noisy user input before passing to your logic
220
+
221
+ **AI pipelines** — Pre-process Sinhala text before sending to Claude API or any LLM
222
+
223
+ **News aggregators** — Sentence-split articles, count word frequency, extract keywords
224
+
225
+ ---
226
+
227
+ ## Data Files
228
+
229
+ ### `data/stopwords.json`
230
+
231
+ 120+ curated Sinhala stopwords organised into categories:
232
+
233
+ ```
234
+ pronouns → මම, ඔබ, ඔහු, ඇය, ඔවුන් ...
235
+ conjunctions → හා, සහ, හෝ, නමුත් ...
236
+ prepositions → ඉහත, පහත, සඳහා, ගැන ...
237
+ particles → ද, නේ, යි, ම ...
238
+ aux_verbs → ඇත, නැත, වේ, හැකි ...
239
+ question_words → මොකද, ඇයි, කවදා ...
240
+ adverbs → ඉතා, බොහෝ, දැන් ...
241
+ ```
242
+
243
+ The `flat_list` key gives you a ready-to-use array of all words:
244
+
245
+ ```php
246
+ $data = json_decode(file_get_contents('data/stopwords.json'), true);
247
+ $stopwords = $data['flat_list'];
248
+ ```
249
+
250
+ ---
251
+
252
+ ## API Reference
253
+
254
+ ### `TextCleaner`
255
+
256
+ ```php
257
+ $cleaner = new TextCleaner(?string $stopwordsPath = null);
258
+ ```
259
+
260
+ | Method | Parameters | Returns | Description |
261
+ |---|---|---|---|
262
+ | `clean()` | `string $text, array $options` | `string` | Full pipeline |
263
+ | `normaliseUnicode()` | `string $text` | `string` | NFC normalisation |
264
+ | `removeInvisibleChars()` | `string $text, bool $keepZwj` | `string` | Strip ZWJ/ZWNJ/BOM |
265
+ | `normaliseWhitespace()` | `string $text` | `string` | Collapse spaces |
266
+ | `removePunctuation()` | `string $text` | `string` | Strip punctuation |
267
+ | `removeEnglish()` | `string $text` | `string` | Strip ASCII letters |
268
+ | `removeNumbers()` | `string $text` | `string` | Strip digits |
269
+ | `removeStopwords()` | `string $text` | `string` | Filter stopwords |
270
+ | `detectScript()` | `string $text` | `string` | sinhala/english/mixed/unknown |
271
+ | `isPureSinhala()` | `string $text` | `bool` | Check purity |
272
+ | `isStopword()` | `string $word` | `bool` | Single word check |
273
+ | `getStopwords()` | — | `array` | Full stopword list |
274
+
275
+ **`clean()` options:**
276
+
277
+ ```php
278
+ [
279
+ 'remove_stopwords' => false, // Remove stopwords
280
+ 'remove_punctuation' => false, // Remove punctuation
281
+ 'remove_english' => false, // Remove English characters
282
+ 'remove_numbers' => false, // Remove digits
283
+ 'keep_zwj' => true, // Preserve ZWJ (Sinhala conjuncts)
284
+ ]
285
+ ```
286
+
287
+ ---
288
+
289
+ ### `Tokenizer`
290
+
291
+ ```php
292
+ $tokenizer = new Tokenizer();
293
+ ```
294
+
295
+ | Method | Parameters | Returns | Description |
296
+ |---|---|---|---|
297
+ | `splitSentences()` | `string $text, bool $keepBoundary` | `array` | Split into sentences |
298
+ | `tokenize()` | `string $text, bool $lowercase` | `array` | Word tokens |
299
+ | `tokenizeWithTypes()` | `string $text` | `array` | Tokens with type metadata |
300
+ | `tokenizeByType()` | `string $text, string $type` | `array` | Filter by type |
301
+ | `graphemes()` | `string $text` | `array` | Grapheme clusters |
302
+ | `classifyToken()` | `string $token` | `string` | sinhala/english/number/mixed |
303
+ | `frequency()` | `string $text, array $stopwords` | `array` | Word frequency map |
304
+ | `countTokens()` | `string $text` | `int` | Token count |
305
+ | `countSentences()` | `string $text` | `int` | Sentence count |
306
+
307
+ **Token types:** `sinhala` · `english` · `number` · `mixed` · `punctuation` · `unknown`
308
+
309
+ ---
310
+
311
+ ## Project Structure
312
+
313
+ ```
314
+ sinhala-toolkit/
315
+ ├── src/
316
+ │ ├── TextCleaner.php # Text cleaning & normalisation
317
+ │ └── Tokenizer.php # Sentence & word tokenization
318
+ ├── data/
319
+ │ └── stopwords.json # 120+ curated Sinhala stopwords
320
+ ├── tests/
321
+ │ ├── test_cleaner.php
322
+ │ └── test_tokenizer.php
323
+ ├── CONTRIBUTING.md
324
+ ├── LICENSE
325
+ └── README.md
326
+ ```
327
+
328
+ ---
329
+
330
+ ## Roadmap
331
+
332
+ - [ ] `composer require` support
333
+ - [ ] Singlish transliterator (`ආයුබෝවන්` ↔ `aayubowan`)
334
+ - [ ] Sinhala sentiment analyser
335
+ - [ ] Profanity / bad word filter
336
+ - [ ] Language detector (Sinhala vs Tamil vs English)
337
+ - [ ] Keyword extractor (TF-IDF)
338
+ - [ ] Python package (`pip install sinkit`)
339
+ - [ ] REST API (hosted)
340
+
341
+ ---
342
+
343
+ ## Contributing
344
+
345
+ **This project needs your help!** Especially:
346
+
347
+ - 🔤 More stopwords — open `data/stopwords.json` and add
348
+ - 🐛 Bug reports — especially edge cases with Sinhala Unicode
349
+ - 🧪 More test cases — real-world Sinhala text samples
350
+ - 📖 Sinhala documentation translation
351
+
352
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
353
+
354
+ ---
355
+
356
+ <a name="sinhala"></a>
357
+
358
+ ## සිංහල
359
+
360
+ **sinhala-toolkit** යනු PHP developers ලා සඳහා නිර්මාණය කරන ලද, නිෂ්පාදන-සූදානම් සිංහල NLP toolkit එකකි.
361
+
362
+ ### ස්ථාපනය
363
+
364
+ ```php
365
+ require_once 'src/TextCleaner.php';
366
+ require_once 'src/Tokenizer.php';
367
+ ```
368
+
369
+ ### සරල නිදර්ශනයක්
370
+
371
+ ```php
372
+ $cleaner = new SinhalaToolkit\TextCleaner('data/stopwords.json');
373
+ $tokenizer = new SinhalaToolkit\Tokenizer();
374
+
375
+ // පෙළ පිරිසිදු කිරීම
376
+ $clean = $cleaner->clean("මම සහ ඔබ හොඳ ගුරුවරයා ළඟ ඉගෙන ගත්තා", [
377
+ 'remove_stopwords' => true
378
+ ]);
379
+ // ප්‍රතිඵලය: "හොඳ ගුරුවරයා ඉගෙන ගත්තා"
380
+
381
+ // වාක්‍ය කැපීම
382
+ $sentences = $tokenizer->splitSentences("ඔහු ගෙදර ගියා। ඇය පාසලට ගියාය।");
383
+ // ["ඔහු ගෙදර ගියා", "ඇය පාසලට ගියාය"]
384
+ ```
385
+
386
+ ---
387
+
388
+ ## License
389
+
390
+ MIT © 2025 [Trishan Sri Viduranga](https://github.com/gosdrkht)
391
+
392
+ ---
393
+
394
+ <div align="center">
395
+
396
+ Built for the Sri Lankan developer community
397
+ **ශ්‍රී ලාංකික developer ප්‍රජාව සඳහා නිර්මාණය කරන ලදී**
398
+ ⭐ If this helped you, please star the repo! 🙏
399
+
400
+ </div>