turkic-mwe 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.
Files changed (40) hide show
  1. turkic_mwe-0.1.0/.gitignore +27 -0
  2. turkic_mwe-0.1.0/CHANGELOG.md +37 -0
  3. turkic_mwe-0.1.0/LICENSE +202 -0
  4. turkic_mwe-0.1.0/NOTICE +4 -0
  5. turkic_mwe-0.1.0/PKG-INFO +146 -0
  6. turkic_mwe-0.1.0/README.md +124 -0
  7. turkic_mwe-0.1.0/docs/PLAN.md +245 -0
  8. turkic_mwe-0.1.0/docs/RELEASING.md +36 -0
  9. turkic_mwe-0.1.0/docs/quality.md +128 -0
  10. turkic_mwe-0.1.0/pyproject.toml +75 -0
  11. turkic_mwe-0.1.0/src/turkic_mwe/__init__.py +43 -0
  12. turkic_mwe-0.1.0/src/turkic_mwe/_version.py +1 -0
  13. turkic_mwe-0.1.0/src/turkic_mwe/cli.py +122 -0
  14. turkic_mwe-0.1.0/src/turkic_mwe/engine.py +133 -0
  15. turkic_mwe-0.1.0/src/turkic_mwe/evaluation.py +100 -0
  16. turkic_mwe-0.1.0/src/turkic_mwe/finder.py +220 -0
  17. turkic_mwe-0.1.0/src/turkic_mwe/fold.py +49 -0
  18. turkic_mwe-0.1.0/src/turkic_mwe/hit.py +38 -0
  19. turkic_mwe-0.1.0/src/turkic_mwe/languages/__init__.py +31 -0
  20. turkic_mwe-0.1.0/src/turkic_mwe/languages/az.py +350 -0
  21. turkic_mwe-0.1.0/src/turkic_mwe/languages/base.py +137 -0
  22. turkic_mwe-0.1.0/src/turkic_mwe/languages/tr.py +328 -0
  23. turkic_mwe-0.1.0/src/turkic_mwe/languages/uz.py +284 -0
  24. turkic_mwe-0.1.0/src/turkic_mwe/notation.py +109 -0
  25. turkic_mwe-0.1.0/src/turkic_mwe/py.typed +0 -0
  26. turkic_mwe-0.1.0/src/turkic_mwe/verify.py +130 -0
  27. turkic_mwe-0.1.0/tests/__init__.py +0 -0
  28. turkic_mwe-0.1.0/tests/conftest.py +16 -0
  29. turkic_mwe-0.1.0/tests/fixtures/README.md +4 -0
  30. turkic_mwe-0.1.0/tests/fixtures/tr_lexicon_min.txt +253 -0
  31. turkic_mwe-0.1.0/tests/golden/az.tsv +26 -0
  32. turkic_mwe-0.1.0/tests/golden/tr.tsv +23 -0
  33. turkic_mwe-0.1.0/tests/golden/uz.tsv +22 -0
  34. turkic_mwe-0.1.0/tests/test_az.py +67 -0
  35. turkic_mwe-0.1.0/tests/test_finder.py +164 -0
  36. turkic_mwe-0.1.0/tests/test_fold_notation.py +63 -0
  37. turkic_mwe-0.1.0/tests/test_golden.py +40 -0
  38. turkic_mwe-0.1.0/tests/test_tr.py +149 -0
  39. turkic_mwe-0.1.0/tests/test_uz.py +68 -0
  40. turkic_mwe-0.1.0/tests/test_verify.py +61 -0
@@ -0,0 +1,27 @@
1
+ # Python
2
+ .venv/
3
+ __pycache__/
4
+ *.py[cod]
5
+ *.egg-info/
6
+ build/
7
+ dist/
8
+ .pytest_cache/
9
+ .ruff_cache/
10
+ .mypy_cache/
11
+ .coverage
12
+ htmlcov/
13
+ .hypothesis/
14
+
15
+ # Docs build
16
+ site/
17
+
18
+ # Local data and benchmarks output (never commit corpora)
19
+ data/
20
+ benchmarks/out/
21
+ *.parquet
22
+ *.jsonl.gz
23
+
24
+ # OS / editors
25
+ .DS_Store
26
+ .idea/
27
+ .vscode/
@@ -0,0 +1,37 @@
1
+ # Changelog
2
+
3
+ All notable changes. The format follows [Keep a Changelog](https://keepachangelog.com/) and
4
+ versions follow [Semantic Versioning](https://semver.org/) (0.x: the API may still change).
5
+
6
+ ## [Unreleased]
7
+
8
+ ## [0.1.0] - 2026-12-01
9
+
10
+ First release (alpha). Turkish, Azerbaijani and Uzbek; language packs not yet reviewed by
11
+ native speakers (docs/quality.md).
12
+
13
+ ### Added
14
+ - `voice` option (default `"same"`): causative forms are refused as another idiom; passives
15
+ always match. `--voice` on the CLI.
16
+ - Turkish verb endings found by measuring recall on PARSEME (negative present, *-sin*,
17
+ *-DIk*, negative ability, vowel loss before *-yor*): recall 94.7% -> 96.4% (95.7% with
18
+ the default voice).
19
+ - Uzbek: short verb stems need a real verb ending, longer endings allowed, verb-derived
20
+ nouns refused; quote marks are no longer part of words.
21
+ - Verifier: Uzbek lemmas with ʻ compared correctly; measured for all three languages.
22
+ - Benchmarks: `recall_parseme.py`, `compare_options.py`; 68 golden sentences in all.
23
+ - Apache-2.0 licence (LICENSE, NOTICE) and package metadata.
24
+ - Release workflow: a version tag builds, checks and publishes to PyPI by trusted
25
+ publishing (no stored tokens); TestPyPI can be tried first by hand.
26
+ - `Finder(lang, expressions).find(text)`: inflection-aware matching for Turkish,
27
+ Azerbaijani and Uzbek, with spans into the original text, sentence, gap, score and the
28
+ rule behind each word; `find_iter`, `explain`, `skipped`.
29
+ - Text folding with exact offsets (lowercase, Turkic İ/ı, schwa stand-ins, Cyrillic
30
+ look-alikes, every Uzbek apostrophe form, Cyrillic Uzbek and Azerbaijani input).
31
+ - Dictionary notation: alternatives (`veya`, `yoki`, `yaxud`, bare parentheses, slashes),
32
+ optional words, in-word optional letters, `...` slots, leading placeholders.
33
+ - Evaluation: `sample`, `write_sheet`, `score` with Wilson intervals; CLI `find`,
34
+ `explain`, `eval-sample`, `eval-score`, `languages`.
35
+ - Optional `ApertiumVerifier` (extra `[apertium]`, via TurkicNLP).
36
+ - Golden tests per language, property tests on offsets, parity benchmark against the
37
+ turkic-idioms miners (`benchmarks/parity.py`); measurements in `docs/quality.md`.
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
@@ -0,0 +1,4 @@
1
+ turkic-mwe
2
+ Copyright 2026 Hajorda
3
+
4
+ This product includes code adapted from the turkic-idioms project by the same author.
@@ -0,0 +1,146 @@
1
+ Metadata-Version: 2.5
2
+ Name: turkic-mwe
3
+ Version: 0.1.0
4
+ Summary: Find idioms, proverbs and set phrases in running Turkic text, in any inflected form
5
+ Project-URL: Source, https://github.com/Hajorda/turkic-mwe
6
+ Author: Hajorda
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ License-File: NOTICE
10
+ Keywords: azerbaijani,corpus,idioms,multiword expressions,mwe,nlp,turkic,turkish,uzbek
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Natural Language :: Turkish
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Topic :: Text Processing :: Linguistic
17
+ Classifier: Typing :: Typed
18
+ Requires-Python: >=3.10
19
+ Provides-Extra: apertium
20
+ Requires-Dist: turkicnlp[hfst]; extra == 'apertium'
21
+ Description-Content-Type: text/markdown
22
+
23
+ # turkic-mwe
24
+
25
+ Find idioms, proverbs and set phrases in running Turkic text, in any inflected form.
26
+
27
+ ```python
28
+ from turkic_mwe import Finder
29
+
30
+ finder = Finder("az", ["göz atmaq", "ürəyi yarpaq kimi əsmək"])
31
+ for hit in finder.find("Səhər o, qəzetlərə tələsik göz atdı. Onun ürəyi yarpaq kimi əsirdi."):
32
+ print(hit.matched, hit.spans)
33
+ # göz atdı [(27, 30), (31, 35)]
34
+ # ürəyi yarpaq kimi əsirdi [(42, 47), (48, 54), (55, 59), (60, 66)]
35
+ ```
36
+
37
+ In Turkic languages one idiom appears in dozens of forms (*göz atmaq* → *göz atdı*,
38
+ *gözünü atıb*; *ağız açmak* → *ağzını açtı*). Plain search misses them; prefix search finds
39
+ wrong ones (*gəlmək* in *gəlinlik*). This library knows each language's endings and
40
+ sound changes, so it finds the real forms and only those.
41
+
42
+ **Languages:** Turkish (`tr`), Azerbaijani (`az`), Uzbek (`uz`). Kazakh and Uyghur are planned.
43
+ **Status:** alpha (0.1.0). API may still change. Measured quality: [docs/quality.md](docs/quality.md)
44
+ (Turkish recall on hand-annotated PARSEME idioms: 95.7%; native-speaker precision checks pending).
45
+
46
+ ## Install
47
+
48
+ ```bash
49
+ pip install turkic-mwe # pure Python, no dependencies
50
+ pip install "turkic-mwe[apertium]" # + optional morphology check (Linux, macOS)
51
+ ```
52
+
53
+
54
+ ## What it handles
55
+
56
+ | | Example |
57
+ |---|---|
58
+ | Inflection, person, case | *ağız açmak* ~ *ağzını açıp*; *göz atmaq* ~ *göz atdım* |
59
+ | Sound changes | softening *ayaq* ~ *ayağı*, *kitap* ~ *kitabı*; vowel drop *burun* ~ *burnu* |
60
+ | Words in between | *etekleri zil çalmak* ~ *Etekleri adeta zil çalıyordu* (shown as `Etekleri … zil çalıyordu`) |
61
+ | Look-alikes kept out | *göz* ≠ *gözlük*; *at-* ≠ *ateş*, *atlet*; *gəl-* ≠ *gəlinlik*; *ye-* ≠ *yerə* |
62
+ | Case agreement (tr) | *ortada olmak* needs *ortada*, not *orta* |
63
+ | Voice | causatives are another idiom and are refused by default (*taş atmak* ≠ *taş attırdı*; `voice="any"` allows them); passives match (*dikkat edildi*) |
64
+ | Dictionary notation | `göz (veya gözünü) dikmek`, `ol(ma)maq`, `birinin ... çalmak`, `bad olmoq/ bad yemoq` |
65
+ | Placeholders | *birinin kapısını çalmak* finds *Komşunun kapısını çaldık* |
66
+ | Spelling and script | Turkic İ/ı; ǝ/ä for ə; Cyrillic look-alikes in Latin words; Uzbek ʻ ʼ ’ ‘ ' \` all the same; Cyrillic Uzbek and Azerbaijani input (spans still point into your text) |
67
+ | Sentences | matches never cross a sentence boundary |
68
+
69
+ ## The `Hit`
70
+
71
+ | Field | |
72
+ |---|---|
73
+ | `expression`, `form` | what you passed, and the spelling that matched |
74
+ | `spans` | one `(start, end)` per expression word, into **your** text |
75
+ | `matched`, `sentence`, `sentence_span` | the words found (`…` for skipped words) and their sentence |
76
+ | `gap_words`, `score` | words in between; an ordering score (1.0 = adjacent; not a probability) |
77
+ | `why` | the rule that accepted each word, e.g. `("verb stem 'at' + verb ending", "atdı")` |
78
+ | `verified` | second-stage verdict: `True` / `False` / `None` (not run or no verdict) |
79
+
80
+ `finder.explain("göz atmaq", "gözlədi")` shows why a token is or is not a form of each word;
81
+ `finder.skipped` lists expressions that could not be used, with the reason.
82
+
83
+ ## Turkish needs a word list
84
+
85
+ Turkish dictionary entries are often inflected (*gözüne*, *ağzını*). To match other persons
86
+ (*gözüme*, *ağzımı*) the root is found in a headword list. **No list is bundled** (the best
87
+ one, TDK's, is copyrighted). Pass one (one word per line) or set an environment variable:
88
+
89
+ ```python
90
+ Finder("tr", idioms, lexicon="headwords.txt")
91
+ ```
92
+ ```bash
93
+ export TURKIC_MWE_TR_LEXICON=/path/to/headwords.txt
94
+ ```
95
+
96
+ Without it a suffix heuristic is used, and a warning says so. Measured: recall on PARSEME is
97
+ the same either way (95.6% vs 95.7%); on web text the list finds ~7% more hits.
98
+
99
+ ## Command line
100
+
101
+ ```bash
102
+ turkic-mwe find --lang az --expressions idioms.txt corpus.txt # one text per line
103
+ turkic-mwe find --lang az -e "göz atmaq" --jsonl corpus.txt > hits.jsonl
104
+ turkic-mwe explain --lang az -e "göz atmaq" gözlədi
105
+ turkic-mwe eval-sample --lang az --expressions idioms.txt corpus.txt -n 300 -o check.csv
106
+ turkic-mwe eval-score check.csv # precision with a 95% Wilson interval
107
+ ```
108
+
109
+ ## Optional: morphology check
110
+
111
+ ```python
112
+ from turkic_mwe.verify import ApertiumVerifier
113
+
114
+ verifier = ApertiumVerifier.download(["tr"]) # Apertium analysers via TurkicNLP, once
115
+ finder = Finder("tr", idioms, lexicon="headwords.txt", verifier=verifier)
116
+ ```
117
+
118
+ Rejected hits get `verified=False` and a low score; nothing is removed, so you decide. On
119
+ Turkish and Uzbek about 22 of 30 sampled rejections were right; on Azerbaijani the analyser
120
+ is too small to help (numbers: [docs/quality.md](docs/quality.md)).
121
+ The analysers are GPL-3.0 and are downloaded separately; this library does not include them.
122
+
123
+ ## Measuring quality on your data
124
+
125
+ Precision depends on your text. `eval-sample` draws random hits (at most one per expression)
126
+ into a CSV; mark each `y`/`n`/`?`; `eval-score` gives precision with a 95% confidence
127
+ interval. Every language here was measured this way and against the miners it replaces.
128
+
129
+ ## Development
130
+
131
+ ```bash
132
+ uv sync --group dev
133
+ uv run pytest # tests, incl. golden sentences per language
134
+ uv run ruff check && uv run mypy
135
+ ```
136
+
137
+ Adding a language: [CONTRIBUTING.md](CONTRIBUTING.md). Design and roadmap: [docs/PLAN.md](docs/PLAN.md).
138
+
139
+ ## Licence
140
+
141
+ Apache-2.0 ([LICENSE](LICENSE), [NOTICE](NOTICE)). The optional Apertium analysers are
142
+ GPL-3.0 and are downloaded separately by TurkicNLP; they are not part of this package.
143
+
144
+ Grew out of the matchers in [turkic-idioms](https://github.com/Hajorda/turkic-idioms)
145
+ (SIGTURK 2027 shared task, Idioms and Conventional Expressions), which mined about 480,000
146
+ example sentences with them.
@@ -0,0 +1,124 @@
1
+ # turkic-mwe
2
+
3
+ Find idioms, proverbs and set phrases in running Turkic text, in any inflected form.
4
+
5
+ ```python
6
+ from turkic_mwe import Finder
7
+
8
+ finder = Finder("az", ["göz atmaq", "ürəyi yarpaq kimi əsmək"])
9
+ for hit in finder.find("Səhər o, qəzetlərə tələsik göz atdı. Onun ürəyi yarpaq kimi əsirdi."):
10
+ print(hit.matched, hit.spans)
11
+ # göz atdı [(27, 30), (31, 35)]
12
+ # ürəyi yarpaq kimi əsirdi [(42, 47), (48, 54), (55, 59), (60, 66)]
13
+ ```
14
+
15
+ In Turkic languages one idiom appears in dozens of forms (*göz atmaq* → *göz atdı*,
16
+ *gözünü atıb*; *ağız açmak* → *ağzını açtı*). Plain search misses them; prefix search finds
17
+ wrong ones (*gəlmək* in *gəlinlik*). This library knows each language's endings and
18
+ sound changes, so it finds the real forms and only those.
19
+
20
+ **Languages:** Turkish (`tr`), Azerbaijani (`az`), Uzbek (`uz`). Kazakh and Uyghur are planned.
21
+ **Status:** alpha (0.1.0). API may still change. Measured quality: [docs/quality.md](docs/quality.md)
22
+ (Turkish recall on hand-annotated PARSEME idioms: 95.7%; native-speaker precision checks pending).
23
+
24
+ ## Install
25
+
26
+ ```bash
27
+ pip install turkic-mwe # pure Python, no dependencies
28
+ pip install "turkic-mwe[apertium]" # + optional morphology check (Linux, macOS)
29
+ ```
30
+
31
+
32
+ ## What it handles
33
+
34
+ | | Example |
35
+ |---|---|
36
+ | Inflection, person, case | *ağız açmak* ~ *ağzını açıp*; *göz atmaq* ~ *göz atdım* |
37
+ | Sound changes | softening *ayaq* ~ *ayağı*, *kitap* ~ *kitabı*; vowel drop *burun* ~ *burnu* |
38
+ | Words in between | *etekleri zil çalmak* ~ *Etekleri adeta zil çalıyordu* (shown as `Etekleri … zil çalıyordu`) |
39
+ | Look-alikes kept out | *göz* ≠ *gözlük*; *at-* ≠ *ateş*, *atlet*; *gəl-* ≠ *gəlinlik*; *ye-* ≠ *yerə* |
40
+ | Case agreement (tr) | *ortada olmak* needs *ortada*, not *orta* |
41
+ | Voice | causatives are another idiom and are refused by default (*taş atmak* ≠ *taş attırdı*; `voice="any"` allows them); passives match (*dikkat edildi*) |
42
+ | Dictionary notation | `göz (veya gözünü) dikmek`, `ol(ma)maq`, `birinin ... çalmak`, `bad olmoq/ bad yemoq` |
43
+ | Placeholders | *birinin kapısını çalmak* finds *Komşunun kapısını çaldık* |
44
+ | Spelling and script | Turkic İ/ı; ǝ/ä for ə; Cyrillic look-alikes in Latin words; Uzbek ʻ ʼ ’ ‘ ' \` all the same; Cyrillic Uzbek and Azerbaijani input (spans still point into your text) |
45
+ | Sentences | matches never cross a sentence boundary |
46
+
47
+ ## The `Hit`
48
+
49
+ | Field | |
50
+ |---|---|
51
+ | `expression`, `form` | what you passed, and the spelling that matched |
52
+ | `spans` | one `(start, end)` per expression word, into **your** text |
53
+ | `matched`, `sentence`, `sentence_span` | the words found (`…` for skipped words) and their sentence |
54
+ | `gap_words`, `score` | words in between; an ordering score (1.0 = adjacent; not a probability) |
55
+ | `why` | the rule that accepted each word, e.g. `("verb stem 'at' + verb ending", "atdı")` |
56
+ | `verified` | second-stage verdict: `True` / `False` / `None` (not run or no verdict) |
57
+
58
+ `finder.explain("göz atmaq", "gözlədi")` shows why a token is or is not a form of each word;
59
+ `finder.skipped` lists expressions that could not be used, with the reason.
60
+
61
+ ## Turkish needs a word list
62
+
63
+ Turkish dictionary entries are often inflected (*gözüne*, *ağzını*). To match other persons
64
+ (*gözüme*, *ağzımı*) the root is found in a headword list. **No list is bundled** (the best
65
+ one, TDK's, is copyrighted). Pass one (one word per line) or set an environment variable:
66
+
67
+ ```python
68
+ Finder("tr", idioms, lexicon="headwords.txt")
69
+ ```
70
+ ```bash
71
+ export TURKIC_MWE_TR_LEXICON=/path/to/headwords.txt
72
+ ```
73
+
74
+ Without it a suffix heuristic is used, and a warning says so. Measured: recall on PARSEME is
75
+ the same either way (95.6% vs 95.7%); on web text the list finds ~7% more hits.
76
+
77
+ ## Command line
78
+
79
+ ```bash
80
+ turkic-mwe find --lang az --expressions idioms.txt corpus.txt # one text per line
81
+ turkic-mwe find --lang az -e "göz atmaq" --jsonl corpus.txt > hits.jsonl
82
+ turkic-mwe explain --lang az -e "göz atmaq" gözlədi
83
+ turkic-mwe eval-sample --lang az --expressions idioms.txt corpus.txt -n 300 -o check.csv
84
+ turkic-mwe eval-score check.csv # precision with a 95% Wilson interval
85
+ ```
86
+
87
+ ## Optional: morphology check
88
+
89
+ ```python
90
+ from turkic_mwe.verify import ApertiumVerifier
91
+
92
+ verifier = ApertiumVerifier.download(["tr"]) # Apertium analysers via TurkicNLP, once
93
+ finder = Finder("tr", idioms, lexicon="headwords.txt", verifier=verifier)
94
+ ```
95
+
96
+ Rejected hits get `verified=False` and a low score; nothing is removed, so you decide. On
97
+ Turkish and Uzbek about 22 of 30 sampled rejections were right; on Azerbaijani the analyser
98
+ is too small to help (numbers: [docs/quality.md](docs/quality.md)).
99
+ The analysers are GPL-3.0 and are downloaded separately; this library does not include them.
100
+
101
+ ## Measuring quality on your data
102
+
103
+ Precision depends on your text. `eval-sample` draws random hits (at most one per expression)
104
+ into a CSV; mark each `y`/`n`/`?`; `eval-score` gives precision with a 95% confidence
105
+ interval. Every language here was measured this way and against the miners it replaces.
106
+
107
+ ## Development
108
+
109
+ ```bash
110
+ uv sync --group dev
111
+ uv run pytest # tests, incl. golden sentences per language
112
+ uv run ruff check && uv run mypy
113
+ ```
114
+
115
+ Adding a language: [CONTRIBUTING.md](CONTRIBUTING.md). Design and roadmap: [docs/PLAN.md](docs/PLAN.md).
116
+
117
+ ## Licence
118
+
119
+ Apache-2.0 ([LICENSE](LICENSE), [NOTICE](NOTICE)). The optional Apertium analysers are
120
+ GPL-3.0 and are downloaded separately by TurkicNLP; they are not part of this package.
121
+
122
+ Grew out of the matchers in [turkic-idioms](https://github.com/Hajorda/turkic-idioms)
123
+ (SIGTURK 2027 shared task, Idioms and Conventional Expressions), which mined about 480,000
124
+ example sentences with them.