kotoshu 1.0.2-x86_64-linux

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 (458) hide show
  1. checksums.yaml +7 -0
  2. data/.kotoshu-baseline.json +1 -0
  3. data/.pre-commit-hooks.yaml +18 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +351 -0
  6. data/.yardopts +8 -0
  7. data/CHANGELOG.md +813 -0
  8. data/CLAUDE.md +176 -0
  9. data/CODE_OF_CONDUCT.md +132 -0
  10. data/Cargo.lock +359 -0
  11. data/Cargo.toml +15 -0
  12. data/LICENSE +31 -0
  13. data/README.adoc +1292 -0
  14. data/Rakefile +150 -0
  15. data/SECURITY.md +93 -0
  16. data/TODO.impl/00-cut-0.1.md +121 -0
  17. data/TODO.impl/00-cut-0.2.md +175 -0
  18. data/TODO.impl/00-vision.md +281 -0
  19. data/TODO.impl/01-hunspell-correctness.md +111 -0
  20. data/TODO.impl/02-cli-unification.md +74 -0
  21. data/TODO.impl/03-dynamic-download.md +107 -0
  22. data/TODO.impl/04-language-modules.md +89 -0
  23. data/TODO.impl/05-semantic-path.md +83 -0
  24. data/TODO.impl/06-cjk-support.md +105 -0
  25. data/TODO.impl/07-rtl-support.md +71 -0
  26. data/TODO.impl/08-grammar-engine.md +106 -0
  27. data/TODO.impl/09-integrity-security.md +90 -0
  28. data/TODO.impl/10-testing-ci.md +98 -0
  29. data/TODO.impl/100-full-feature-batch3.md +28 -0
  30. data/TODO.impl/101-int4-tier-experiment.md +32 -0
  31. data/TODO.impl/102-lid-chain.md +28 -0
  32. data/TODO.impl/103-oov-bucket-tables.md +27 -0
  33. data/TODO.impl/104-vscode-marketplace-readiness.md +32 -0
  34. data/TODO.impl/105-personal-dictionary-in-check.md +34 -0
  35. data/TODO.impl/106-native-lid-detection.md +36 -0
  36. data/TODO.impl/107-basic-support-every-staged-language.md +42 -0
  37. data/TODO.impl/108-ko-ne-full-feature.md +37 -0
  38. data/TODO.impl/109-ten-audit.md +26 -0
  39. data/TODO.impl/11-release-v1.md +95 -0
  40. data/TODO.impl/110-sr-latn-and-polish.md +33 -0
  41. data/TODO.impl/111-embedding-bakeoff.md +33 -0
  42. data/TODO.impl/112-deployability-and-gating.md +26 -0
  43. data/TODO.impl/113-language-packs.md +26 -0
  44. data/TODO.impl/114-typo-biencoder-thread.md +33 -0
  45. data/TODO.impl/115-hybrid-retrieval-pricing.md +22 -0
  46. data/TODO.impl/116-baseline-suggestion-skip.md +81 -0
  47. data/TODO.impl/117-deterministic-frequency-tiers.md +110 -0
  48. data/TODO.impl/118-server-gem-floor.md +33 -0
  49. data/TODO.impl/119-embedded-kelly-tiers.md +56 -0
  50. data/TODO.impl/120-setup-metadata-refresh.md +35 -0
  51. data/TODO.impl/121-jekyll-baseline-skip.md +33 -0
  52. data/TODO.impl/122-pack-compression-kpk2.md +66 -0
  53. data/TODO.impl/123-typo-corpus-synthesis.md +55 -0
  54. data/TODO.impl/124-owner-residue.md +19 -0
  55. data/TODO.impl/125-consumer-floor-guards.md +43 -0
  56. data/TODO.impl/126-tier-error-budgets.md +33 -0
  57. data/TODO.impl/127-suggestion-feedback-loop.md +34 -0
  58. data/TODO.impl/128-hybrid-pricing-verdict.md +47 -0
  59. data/TODO.impl/129-pt-fr-corpora.md +23 -0
  60. data/TODO.impl/130-news-truth-0912.md +23 -0
  61. data/TODO.impl/131-hybrid-productization.md +42 -0
  62. data/TODO.impl/132-techniques-page-and-prose.md +27 -0
  63. data/TODO.impl/133-rust-first-distribution.md +68 -0
  64. data/TODO.impl/20-encapsulation-cleanup.md +47 -0
  65. data/TODO.impl/21-autoload-migration.md +64 -0
  66. data/TODO.impl/22-url-pin-single-source-of-truth.md +120 -0
  67. data/TODO.impl/23-fix-url-defaults.md +57 -0
  68. data/TODO.impl/24-cli-auto-setup-prompt.md +76 -0
  69. data/TODO.impl/25-soft-onnxruntime-require.md +75 -0
  70. data/TODO.impl/26-onnx-vocab-json-generation.md +96 -0
  71. data/TODO.impl/27-end-to-end-smoke-spec.md +113 -0
  72. data/TODO.impl/28-readme-quickstart-verification.md +68 -0
  73. data/TODO.impl/29-status-command.md +84 -0
  74. data/TODO.impl/30-language-auto-detection.md +74 -0
  75. data/TODO.impl/31-download-progress.md +58 -0
  76. data/TODO.impl/32-sarif-output-verification.md +72 -0
  77. data/TODO.impl/33-audit-log-rotation.md +54 -0
  78. data/TODO.impl/34-cache-eviction.md +59 -0
  79. data/TODO.impl/35-shell-completion.md +61 -0
  80. data/TODO.impl/36-cleanup-regressions-0.3.1.md +134 -0
  81. data/TODO.impl/37-hunspell-correctness-tier2.md +203 -0
  82. data/TODO.impl/38-onnx-semantic-gating.md +218 -0
  83. data/TODO.impl/39-tier3-and-beyond.md +232 -0
  84. data/TODO.impl/40-spec-drift-cleanup.md +134 -0
  85. data/TODO.impl/50-structure-aware-document-api.md +194 -0
  86. data/TODO.impl/51-grammar-engine-expansion.md +75 -0
  87. data/TODO.impl/52-multi-language-documents.md +95 -0
  88. data/TODO.impl/53-document-plugin-architecture.md +94 -0
  89. data/TODO.impl/54-cjk-support.md +117 -0
  90. data/TODO.impl/55-rtl-support.md +109 -0
  91. data/TODO.impl/56-t4-t5-t6-quality-architecture-ecosystem.md +126 -0
  92. data/TODO.impl/57-t5.1-step3-pure-function-strategies.md +138 -0
  93. data/TODO.impl/58-t5.2-configuration-as-data.md +113 -0
  94. data/TODO.impl/59-yard-api-documentation.md +75 -0
  95. data/TODO.impl/60-lsp-server.md +174 -0
  96. data/TODO.impl/61-editor-ecosystem.md +167 -0
  97. data/TODO.impl/62-framework-integrations.md +159 -0
  98. data/TODO.impl/63-web-playground-wasm.md +186 -0
  99. data/TODO.impl/64-http-api-and-sdks.md +191 -0
  100. data/TODO.impl/65-universal-kotoshu.md +251 -0
  101. data/TODO.impl/66-kotoshu-core.md +169 -0
  102. data/TODO.impl/67-kotoshu-rs-and-access-libraries.md +137 -0
  103. data/TODO.impl/68-sota-adoption.md +152 -0
  104. data/TODO.impl/69-sota-typo-eval.md +74 -0
  105. data/TODO.impl/70-sota-confidence-cascade.md +59 -0
  106. data/TODO.impl/71-sota-nested-model.md +63 -0
  107. data/TODO.impl/72-model2vec-evaluation.md +49 -0
  108. data/TODO.impl/73-rl-reranker.md +42 -0
  109. data/TODO.impl/74-distilled-reranker.md +36 -0
  110. data/TODO.impl/75-llm-evaluator.md +35 -0
  111. data/TODO.impl/76-optional-llm-backend.md +37 -0
  112. data/TODO.impl/77-model-coverage-expansion.md +96 -0
  113. data/TODO.impl/78-in-browser-playground.md +69 -0
  114. data/TODO.impl/79-news-and-releases.md +60 -0
  115. data/TODO.impl/80-ecosystem-docs.md +56 -0
  116. data/TODO.impl/81-editor-reach.md +68 -0
  117. data/TODO.impl/82-doc-formats-and-ignores.md +81 -0
  118. data/TODO.impl/83-models-batch-2.md +56 -0
  119. data/TODO.impl/84-language-modules-wave2.md +75 -0
  120. data/TODO.impl/85-wasm-model-api.md +48 -0
  121. data/TODO.impl/86-site-truth-wave2.md +45 -0
  122. data/TODO.impl/87-lsp-personal-dictionary.md +36 -0
  123. data/TODO.impl/88-cli-directory-mode.md +54 -0
  124. data/TODO.impl/89-framework-integrations-exec.md +59 -0
  125. data/TODO.impl/90-gem-correctness-residues.md +44 -0
  126. data/TODO.impl/91-unicode-and-sv-aff.md +47 -0
  127. data/TODO.impl/92-tier-mirror-cors.md +88 -0
  128. data/TODO.impl/93-python-wheels.md +32 -0
  129. data/TODO.impl/94-site-integrations-docs.md +35 -0
  130. data/TODO.impl/95-editor-action-polish.md +27 -0
  131. data/TODO.impl/96-server-semantic-models.md +50 -0
  132. data/TODO.impl/97-yard-execution.md +73 -0
  133. data/TODO.impl/98-campaign-cleanup.md +78 -0
  134. data/TODO.impl/99-site-truth-performance-docs.md +31 -0
  135. data/conformance/vectors.jsonl +2630 -0
  136. data/data/en/grammar/rules.yaml +851 -0
  137. data/docs/STABILITY-1.0-AUDIT.md +251 -0
  138. data/docs/STABILITY-1.0.md +137 -0
  139. data/docs/cache-architecture.md +502 -0
  140. data/docs/verification-evidence/correct3/pr_body.md +37 -0
  141. data/docs/verification-evidence/correct3/rspec_final.log +5588 -0
  142. data/docs/verification-evidence/correct3/rspec_full.log +4504 -0
  143. data/docs/verification-evidence/correct3/sv.aff +856 -0
  144. data/docs/verification-evidence/correct3/sv.dic +153717 -0
  145. data/examples/01_basic_word_checking.rb +38 -0
  146. data/examples/02_text_document_checking.rb +77 -0
  147. data/examples/03_dictionary_backends.rb +137 -0
  148. data/examples/04_trie_data_structure.rb +146 -0
  149. data/examples/05_suggestion_algorithms.rb +239 -0
  150. data/examples/06_configuration_advanced.rb +287 -0
  151. data/examples/07_multi_language_dictionaries.rb +278 -0
  152. data/exe/kotoshu +6 -0
  153. data/lib/kotoshu/algorithms/capitalization.rb +276 -0
  154. data/lib/kotoshu/algorithms/edit_distance.rb +128 -0
  155. data/lib/kotoshu/algorithms/lookup/affix_form.rb +132 -0
  156. data/lib/kotoshu/algorithms/lookup/compound_checks.rb +209 -0
  157. data/lib/kotoshu/algorithms/lookup/compound_form.rb +50 -0
  158. data/lib/kotoshu/algorithms/lookup.rb +841 -0
  159. data/lib/kotoshu/algorithms/ngram_suggest.rb +367 -0
  160. data/lib/kotoshu/algorithms/permutations.rb +283 -0
  161. data/lib/kotoshu/algorithms/phonet_suggest.rb +162 -0
  162. data/lib/kotoshu/algorithms/soundex.rb +92 -0
  163. data/lib/kotoshu/algorithms/suggest.rb +794 -0
  164. data/lib/kotoshu/algorithms.rb +23 -0
  165. data/lib/kotoshu/analyzers/semantic_analyzer.rb +405 -0
  166. data/lib/kotoshu/analyzers.rb +8 -0
  167. data/lib/kotoshu/baseline/application.rb +18 -0
  168. data/lib/kotoshu/baseline/entry.rb +33 -0
  169. data/lib/kotoshu/baseline/store.rb +175 -0
  170. data/lib/kotoshu/baseline.rb +20 -0
  171. data/lib/kotoshu/cache/base_cache.rb +778 -0
  172. data/lib/kotoshu/cache/cache.rb +91 -0
  173. data/lib/kotoshu/cache/eviction_policy.rb +66 -0
  174. data/lib/kotoshu/cache/frequency_cache.rb +283 -0
  175. data/lib/kotoshu/cache/language_cache.rb +511 -0
  176. data/lib/kotoshu/cache/lookup_cache.rb +166 -0
  177. data/lib/kotoshu/cache/model_cache.rb +1147 -0
  178. data/lib/kotoshu/cache/model_registry.rb +109 -0
  179. data/lib/kotoshu/cache/staged_languages.rb +45 -0
  180. data/lib/kotoshu/cache/suggestion_cache.rb +113 -0
  181. data/lib/kotoshu/cache.rb +49 -0
  182. data/lib/kotoshu/cli/auto_setup.rb +71 -0
  183. data/lib/kotoshu/cli/baseline_command.rb +119 -0
  184. data/lib/kotoshu/cli/batch_reporter.rb +321 -0
  185. data/lib/kotoshu/cli/cache_command.rb +282 -0
  186. data/lib/kotoshu/cli/completions_command.rb +210 -0
  187. data/lib/kotoshu/cli/dict_command.rb +64 -0
  188. data/lib/kotoshu/cli/directory_check.rb +146 -0
  189. data/lib/kotoshu/cli/directory_walker.rb +132 -0
  190. data/lib/kotoshu/cli/display_formatter.rb +429 -0
  191. data/lib/kotoshu/cli/errors.rb +36 -0
  192. data/lib/kotoshu/cli/ignore_matcher.rb +205 -0
  193. data/lib/kotoshu/cli/interactive_reviewer.rb +314 -0
  194. data/lib/kotoshu/cli/language_resolver.rb +91 -0
  195. data/lib/kotoshu/cli/navigation_manager.rb +273 -0
  196. data/lib/kotoshu/cli/personal_command.rb +113 -0
  197. data/lib/kotoshu/cli/progress_reporter.rb +114 -0
  198. data/lib/kotoshu/cli/status_report.rb +130 -0
  199. data/lib/kotoshu/cli.rb +880 -0
  200. data/lib/kotoshu/components/passthrough_spell_checker.rb +70 -0
  201. data/lib/kotoshu/components/pos_tagger.rb +98 -0
  202. data/lib/kotoshu/components/spell_checker.rb +73 -0
  203. data/lib/kotoshu/components/synthesizer.rb +60 -0
  204. data/lib/kotoshu/components/tokenizer.rb +58 -0
  205. data/lib/kotoshu/components/whitespace_tokenizer.rb +94 -0
  206. data/lib/kotoshu/components.rb +13 -0
  207. data/lib/kotoshu/configuration/builder.rb +207 -0
  208. data/lib/kotoshu/configuration/resolver.rb +124 -0
  209. data/lib/kotoshu/configuration.rb +829 -0
  210. data/lib/kotoshu/conformance_exporter.rb +256 -0
  211. data/lib/kotoshu/conformance_runner.rb +176 -0
  212. data/lib/kotoshu/core/exceptions.rb +186 -0
  213. data/lib/kotoshu/core/indexed_dictionary.rb +293 -0
  214. data/lib/kotoshu/core/models/affix_rule.rb +262 -0
  215. data/lib/kotoshu/core/models/result/document_result.rb +132 -0
  216. data/lib/kotoshu/core/models/result/word_result.rb +131 -0
  217. data/lib/kotoshu/core/models/word.rb +131 -0
  218. data/lib/kotoshu/core/trie/builder.rb +119 -0
  219. data/lib/kotoshu/core/trie/node.rb +94 -0
  220. data/lib/kotoshu/core/trie/trie.rb +249 -0
  221. data/lib/kotoshu/core.rb +28 -0
  222. data/lib/kotoshu/data/common_words/de.yml +1800 -0
  223. data/lib/kotoshu/data/common_words/en.yml +1215 -0
  224. data/lib/kotoshu/data/common_words/es.yml +750 -0
  225. data/lib/kotoshu/data/common_words/fr.yml +1015 -0
  226. data/lib/kotoshu/data/common_words/pt.yml +870 -0
  227. data/lib/kotoshu/data/common_words/ru.yml +484 -0
  228. data/lib/kotoshu/data/common_words_loader.rb +141 -0
  229. data/lib/kotoshu/data/frozen_kelly/en.json +1154 -0
  230. data/lib/kotoshu/data/frozen_kelly.rb +38 -0
  231. data/lib/kotoshu/data.rb +8 -0
  232. data/lib/kotoshu/data_structures/bloom_filter.rb +188 -0
  233. data/lib/kotoshu/data_structures.rb +8 -0
  234. data/lib/kotoshu/debug_logger.rb +146 -0
  235. data/lib/kotoshu/debug_mode.rb +136 -0
  236. data/lib/kotoshu/defaults.rb +84 -0
  237. data/lib/kotoshu/dictionaries/catalog.rb +814 -0
  238. data/lib/kotoshu/dictionaries.rb +8 -0
  239. data/lib/kotoshu/dictionary/base.rb +324 -0
  240. data/lib/kotoshu/dictionary/cspell.rb +243 -0
  241. data/lib/kotoshu/dictionary/custom.rb +225 -0
  242. data/lib/kotoshu/dictionary/hunspell.rb +520 -0
  243. data/lib/kotoshu/dictionary/plain_text.rb +302 -0
  244. data/lib/kotoshu/dictionary/repository.rb +246 -0
  245. data/lib/kotoshu/dictionary/unified.rb +236 -0
  246. data/lib/kotoshu/dictionary/unix_words.rb +218 -0
  247. data/lib/kotoshu/dictionary.rb +15 -0
  248. data/lib/kotoshu/documents/document.rb +120 -0
  249. data/lib/kotoshu/documents/plain_text_document.rb +73 -0
  250. data/lib/kotoshu/documents/source_position.rb +45 -0
  251. data/lib/kotoshu/documents/source_range.rb +76 -0
  252. data/lib/kotoshu/documents/suppressions/scanner.rb +149 -0
  253. data/lib/kotoshu/documents/suppressions/suppression.rb +75 -0
  254. data/lib/kotoshu/documents/suppressions.rb +44 -0
  255. data/lib/kotoshu/documents/text_node.rb +49 -0
  256. data/lib/kotoshu/documents.rb +178 -0
  257. data/lib/kotoshu/embeddings/embedding_pipeline.rb +238 -0
  258. data/lib/kotoshu/embeddings/lru_cache.rb +244 -0
  259. data/lib/kotoshu/embeddings/onnx_runtime_model.rb +411 -0
  260. data/lib/kotoshu/embeddings/protocol.rb +96 -0
  261. data/lib/kotoshu/embeddings/protocols.rb +23 -0
  262. data/lib/kotoshu/embeddings/registry.rb +184 -0
  263. data/lib/kotoshu/embeddings/search.rb +204 -0
  264. data/lib/kotoshu/embeddings/similarity_engine.rb +278 -0
  265. data/lib/kotoshu/embeddings/similarity_search.rb +328 -0
  266. data/lib/kotoshu/embeddings/vocabulary.rb +306 -0
  267. data/lib/kotoshu/embeddings.rb +87 -0
  268. data/lib/kotoshu/fluent_checker.rb +94 -0
  269. data/lib/kotoshu/grammar/pattern_matchers/base_matcher.rb +48 -0
  270. data/lib/kotoshu/grammar/pattern_matchers/double_negative_matcher.rb +179 -0
  271. data/lib/kotoshu/grammar/pattern_matchers/phrase_matcher.rb +86 -0
  272. data/lib/kotoshu/grammar/pattern_matchers/possessive_context_matcher.rb +75 -0
  273. data/lib/kotoshu/grammar/pattern_matchers/possessive_contraction_matcher.rb +87 -0
  274. data/lib/kotoshu/grammar/pattern_matchers/sentence_start_matcher.rb +84 -0
  275. data/lib/kotoshu/grammar/pattern_matchers/vowel_sound_matcher.rb +81 -0
  276. data/lib/kotoshu/grammar/pattern_matchers/word_list_matcher.rb +66 -0
  277. data/lib/kotoshu/grammar/rule.rb +99 -0
  278. data/lib/kotoshu/grammar/rule_engine.rb +96 -0
  279. data/lib/kotoshu/grammar/rule_loader.rb +30 -0
  280. data/lib/kotoshu/grammar.rb +24 -0
  281. data/lib/kotoshu/integrity/audit_log.rb +167 -0
  282. data/lib/kotoshu/integrity/manifest.rb +116 -0
  283. data/lib/kotoshu/integrity/net_http.rb +51 -0
  284. data/lib/kotoshu/integrity/rotation_policy.rb +88 -0
  285. data/lib/kotoshu/integrity.rb +26 -0
  286. data/lib/kotoshu/jekyll.rb +101 -0
  287. data/lib/kotoshu/keyboard/layout.rb +116 -0
  288. data/lib/kotoshu/keyboard/layouts/arabic.rb +59 -0
  289. data/lib/kotoshu/keyboard/layouts/azerty.rb +55 -0
  290. data/lib/kotoshu/keyboard/layouts/bulgarian.rb +57 -0
  291. data/lib/kotoshu/keyboard/layouts/devanagari_inscript.rb +52 -0
  292. data/lib/kotoshu/keyboard/layouts/dubeolsik.rb +56 -0
  293. data/lib/kotoshu/keyboard/layouts/dvorak.rb +54 -0
  294. data/lib/kotoshu/keyboard/layouts/greek.rb +52 -0
  295. data/lib/kotoshu/keyboard/layouts/hebrew.rb +57 -0
  296. data/lib/kotoshu/keyboard/layouts/hrsl.rb +94 -0
  297. data/lib/kotoshu/keyboard/layouts/jcuken.rb +57 -0
  298. data/lib/kotoshu/keyboard/layouts/latin.rb +266 -0
  299. data/lib/kotoshu/keyboard/layouts/persian.rb +58 -0
  300. data/lib/kotoshu/keyboard/layouts/qwerty.rb +52 -0
  301. data/lib/kotoshu/keyboard/layouts/qwertz.rb +55 -0
  302. data/lib/kotoshu/keyboard/layouts/serbian.rb +59 -0
  303. data/lib/kotoshu/keyboard/layouts/turkish_q.rb +52 -0
  304. data/lib/kotoshu/keyboard/layouts/ukrainian.rb +51 -0
  305. data/lib/kotoshu/keyboard/registry.rb +201 -0
  306. data/lib/kotoshu/keyboard.rb +96 -0
  307. data/lib/kotoshu/kotoshu_native.so +0 -0
  308. data/lib/kotoshu/language/detector.rb +242 -0
  309. data/lib/kotoshu/language/identifier.rb +376 -0
  310. data/lib/kotoshu/language/languages/base.rb +271 -0
  311. data/lib/kotoshu/language/lid_detector.rb +188 -0
  312. data/lib/kotoshu/language/normalizer/arabic.rb +113 -0
  313. data/lib/kotoshu/language/normalizer/base.rb +133 -0
  314. data/lib/kotoshu/language/normalizer/greek.rb +63 -0
  315. data/lib/kotoshu/language/normalizer/hebrew.rb +72 -0
  316. data/lib/kotoshu/language/normalizer/persian.rb +36 -0
  317. data/lib/kotoshu/language/normalizer/turkish.rb +38 -0
  318. data/lib/kotoshu/language/registry.rb +209 -0
  319. data/lib/kotoshu/language/resources/ar/common_words.txt +6753 -0
  320. data/lib/kotoshu/language/resources/ar/confusion_sets.txt +11 -0
  321. data/lib/kotoshu/language/resources/de/common_words.txt +10003 -0
  322. data/lib/kotoshu/language/resources/de/confusion_sets.txt +246 -0
  323. data/lib/kotoshu/language/resources/en/common_words.txt +9979 -0
  324. data/lib/kotoshu/language/resources/en/confusion_sets.txt +871 -0
  325. data/lib/kotoshu/language/resources/es/common_words.txt +9992 -0
  326. data/lib/kotoshu/language/resources/es/confusion_sets.txt +17 -0
  327. data/lib/kotoshu/language/resources/fr/common_words.txt +9993 -0
  328. data/lib/kotoshu/language/resources/fr/confusion_sets.txt +76 -0
  329. data/lib/kotoshu/language/resources/pt/common_words.txt +9977 -0
  330. data/lib/kotoshu/language/resources/pt/confusion_sets.txt +18 -0
  331. data/lib/kotoshu/language/resources/ru/common_words.txt +9951 -0
  332. data/lib/kotoshu/language/resources/ru/confusion_sets.txt +5 -0
  333. data/lib/kotoshu/language/script.rb +128 -0
  334. data/lib/kotoshu/language/segmenter.rb +122 -0
  335. data/lib/kotoshu/language/suika.rb +38 -0
  336. data/lib/kotoshu/language/tokenizer/base.rb +187 -0
  337. data/lib/kotoshu/language/tokenizer/cyrillic_tokenizer.rb +76 -0
  338. data/lib/kotoshu/language/tokenizer/devanagari_tokenizer.rb +70 -0
  339. data/lib/kotoshu/language/tokenizer/french_tokenizer.rb +172 -0
  340. data/lib/kotoshu/language/tokenizer/german_tokenizer.rb +41 -0
  341. data/lib/kotoshu/language/tokenizer/greek_tokenizer.rb +72 -0
  342. data/lib/kotoshu/language/tokenizer/hangul_tokenizer.rb +70 -0
  343. data/lib/kotoshu/language/tokenizer/japanese_tokenizer.rb +55 -0
  344. data/lib/kotoshu/language/tokenizer/latin_tokenizer.rb +153 -0
  345. data/lib/kotoshu/language/tokenizer/portuguese_tokenizer.rb +160 -0
  346. data/lib/kotoshu/language/tokenizer/russian_tokenizer.rb +93 -0
  347. data/lib/kotoshu/language/tokenizer/script_tokenizer.rb +62 -0
  348. data/lib/kotoshu/language/tokenizer/spanish_tokenizer.rb +122 -0
  349. data/lib/kotoshu/language.rb +127 -0
  350. data/lib/kotoshu/languages/ar/language.rb +98 -0
  351. data/lib/kotoshu/languages/bg/language.rb +37 -0
  352. data/lib/kotoshu/languages/ca/language.rb +22 -0
  353. data/lib/kotoshu/languages/cs/language.rb +22 -0
  354. data/lib/kotoshu/languages/da/language.rb +22 -0
  355. data/lib/kotoshu/languages/de/language.rb +554 -0
  356. data/lib/kotoshu/languages/el/language.rb +50 -0
  357. data/lib/kotoshu/languages/en/language.rb +470 -0
  358. data/lib/kotoshu/languages/es/language.rb +476 -0
  359. data/lib/kotoshu/languages/et/language.rb +24 -0
  360. data/lib/kotoshu/languages/fa/language.rb +91 -0
  361. data/lib/kotoshu/languages/fr/language.rb +505 -0
  362. data/lib/kotoshu/languages/he/language.rb +98 -0
  363. data/lib/kotoshu/languages/hr/language.rb +24 -0
  364. data/lib/kotoshu/languages/hu/language.rb +22 -0
  365. data/lib/kotoshu/languages/id/language.rb +25 -0
  366. data/lib/kotoshu/languages/it/language.rb +22 -0
  367. data/lib/kotoshu/languages/ja/language.rb +476 -0
  368. data/lib/kotoshu/languages/ko/language.rb +56 -0
  369. data/lib/kotoshu/languages/latin_base.rb +53 -0
  370. data/lib/kotoshu/languages/lt/language.rb +24 -0
  371. data/lib/kotoshu/languages/lv/language.rb +24 -0
  372. data/lib/kotoshu/languages/nb/language.rb +25 -0
  373. data/lib/kotoshu/languages/ne/language.rb +60 -0
  374. data/lib/kotoshu/languages/nl/language.rb +22 -0
  375. data/lib/kotoshu/languages/nn/language.rb +26 -0
  376. data/lib/kotoshu/languages/pl/language.rb +22 -0
  377. data/lib/kotoshu/languages/pt/language.rb +439 -0
  378. data/lib/kotoshu/languages/ro/language.rb +22 -0
  379. data/lib/kotoshu/languages/ru/language.rb +420 -0
  380. data/lib/kotoshu/languages/sk/language.rb +25 -0
  381. data/lib/kotoshu/languages/sl/language.rb +25 -0
  382. data/lib/kotoshu/languages/sr/language.rb +39 -0
  383. data/lib/kotoshu/languages/sr-Latn/language.rb +35 -0
  384. data/lib/kotoshu/languages/sv/language.rb +22 -0
  385. data/lib/kotoshu/languages/tr/language.rb +36 -0
  386. data/lib/kotoshu/languages/uk/language.rb +38 -0
  387. data/lib/kotoshu/languages/vi/language.rb +22 -0
  388. data/lib/kotoshu/languages.rb +64 -0
  389. data/lib/kotoshu/metrics_collector.rb +238 -0
  390. data/lib/kotoshu/metrics_module.rb +121 -0
  391. data/lib/kotoshu/models/context.rb +119 -0
  392. data/lib/kotoshu/models/embedding_model.rb +181 -0
  393. data/lib/kotoshu/models/fasttext_model.rb +212 -0
  394. data/lib/kotoshu/models/nearest_neighbor.rb +96 -0
  395. data/lib/kotoshu/models/onnx_model.rb +330 -0
  396. data/lib/kotoshu/models/semantic_error.rb +204 -0
  397. data/lib/kotoshu/models/suggestion.rb +106 -0
  398. data/lib/kotoshu/models/word_embedding.rb +97 -0
  399. data/lib/kotoshu/models.rb +27 -0
  400. data/lib/kotoshu/multi_language_checker.rb +127 -0
  401. data/lib/kotoshu/native.rb +83 -0
  402. data/lib/kotoshu/native_backend.rb +131 -0
  403. data/lib/kotoshu/paths.rb +79 -0
  404. data/lib/kotoshu/personal_dictionary.rb +105 -0
  405. data/lib/kotoshu/plugins/plugin.rb +61 -0
  406. data/lib/kotoshu/plugins/registry.rb +118 -0
  407. data/lib/kotoshu/plugins.rb +9 -0
  408. data/lib/kotoshu/project_config.rb +76 -0
  409. data/lib/kotoshu/readers/aff_data.rb +530 -0
  410. data/lib/kotoshu/readers/aff_reader.rb +393 -0
  411. data/lib/kotoshu/readers/condition_checker.rb +125 -0
  412. data/lib/kotoshu/readers/dic_reader.rb +208 -0
  413. data/lib/kotoshu/readers/file_reader.rb +377 -0
  414. data/lib/kotoshu/readers/lookup_builder.rb +584 -0
  415. data/lib/kotoshu/readers/readers.rb +17 -0
  416. data/lib/kotoshu/readers.rb +25 -0
  417. data/lib/kotoshu/resource_bundle.rb +55 -0
  418. data/lib/kotoshu/resource_manager.rb +600 -0
  419. data/lib/kotoshu/results/result.rb +165 -0
  420. data/lib/kotoshu/results.rb +8 -0
  421. data/lib/kotoshu/rspec.rb +163 -0
  422. data/lib/kotoshu/scripts/fasttext_to_onnx.py +275 -0
  423. data/lib/kotoshu/source_registry.rb +104 -0
  424. data/lib/kotoshu/spellchecker/parallel_checker.rb +90 -0
  425. data/lib/kotoshu/spellchecker.rb +406 -0
  426. data/lib/kotoshu/string_metrics.rb +153 -0
  427. data/lib/kotoshu/suggestions/context.rb +43 -0
  428. data/lib/kotoshu/suggestions/frequency_provider.rb +80 -0
  429. data/lib/kotoshu/suggestions/generator.rb +169 -0
  430. data/lib/kotoshu/suggestions/pipeline.rb +135 -0
  431. data/lib/kotoshu/suggestions/semantic_cascade.rb +73 -0
  432. data/lib/kotoshu/suggestions/strategies/base_strategy.rb +315 -0
  433. data/lib/kotoshu/suggestions/strategies/composite_strategy.rb +197 -0
  434. data/lib/kotoshu/suggestions/strategies/edit_distance_strategy.rb +631 -0
  435. data/lib/kotoshu/suggestions/strategies/keyboard_proximity_strategy.rb +207 -0
  436. data/lib/kotoshu/suggestions/strategies/ngram_strategy.rb +165 -0
  437. data/lib/kotoshu/suggestions/strategies/phonetic_strategy.rb +284 -0
  438. data/lib/kotoshu/suggestions/strategies/semantic_strategy.rb +317 -0
  439. data/lib/kotoshu/suggestions/strategies/symspell_strategy.rb +270 -0
  440. data/lib/kotoshu/suggestions/strategies/word_index.rb +78 -0
  441. data/lib/kotoshu/suggestions/suggestion.rb +154 -0
  442. data/lib/kotoshu/suggestions/suggestion_set.rb +270 -0
  443. data/lib/kotoshu/suggestions/sweep_index.rb +137 -0
  444. data/lib/kotoshu/suggestions.rb +29 -0
  445. data/lib/kotoshu/tasks/check_task.rb +104 -0
  446. data/lib/kotoshu/tasks.rb +11 -0
  447. data/lib/kotoshu/validators/spelling_validator.rb +101 -0
  448. data/lib/kotoshu/validators.rb +9 -0
  449. data/lib/kotoshu/version.rb +5 -0
  450. data/lib/kotoshu.rb +538 -0
  451. data/rakelib/compile.rake +10 -0
  452. data/script/validate_all_dictionaries.rb +444 -0
  453. data/scripts/build_native_gem.rb +45 -0
  454. data/scripts/extract_eval_grids.rb +37 -0
  455. data/scripts/generate_frozen_tiers.rb +44 -0
  456. data/sig/kotoshu.rbs +435 -0
  457. data/test_oop.rb +79 -0
  458. metadata +546 -0
@@ -0,0 +1,266 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kotoshu
4
+ module Keyboard
5
+ module Layouts
6
+ # Parameterized Latin-script layout family.
7
+ #
8
+ # The wave-1 Latin languages type on one of two physical base
9
+ # grids — QWERTY (it nl pl ro ca vi da nb sv) or QWERTZ (cs hu) —
10
+ # optionally with per-language physical extras: the Nordic layouts
11
+ # have real å/æ/ø and å/ä/ö keys where US QWERTY carries
12
+ # [ ] ; '. Their remaining diacritics are dead-key or AltGr
13
+ # sequences, not physical keys, so they do not appear in the key
14
+ # grid. This mirrors the models repo eval model
15
+ # (kotoshu/models-fasttext-onnx eval/noise.py: LANG_LAYOUT maps
16
+ # the Latin newcomers onto the qwerty/qwertz grids and handles
17
+ # diacritics as _LANG_ALTERNATES slips), keeping gem suggestion
18
+ # adjacency and eval adjacency in sync. Batch 3 (plan 100) adds
19
+ # id sk et lt lv on the same qwerty base grid.
20
+ #
21
+ # One family, per-language declarations — no near-duplicate
22
+ # layout files. The five pre-existing layouts (qwerty qwertz
23
+ # azerty jcuken dvorak) are untouched.
24
+ #
25
+ # @example Declaring a member of the family
26
+ # class Italian < Latin
27
+ # layout_name 'Italian-QWERTY'
28
+ # languages %w[it it-IT]
29
+ # base_grid :qwerty
30
+ # end
31
+ class Latin < Layout
32
+ # Sentinel distinguishing "reader call" from "writer call".
33
+ NOT_SET = Object.new.freeze
34
+
35
+ class << self
36
+ # Get or set the layout display name.
37
+ #
38
+ # @param value [String, NOT_SET] name when declaring
39
+ # @return [String, nil] the declared name
40
+ def layout_name(value = NOT_SET)
41
+ return @layout_name if value.equal?(NOT_SET)
42
+
43
+ @layout_name = value
44
+ end
45
+
46
+ # Get or set the supported language codes.
47
+ #
48
+ # @param value [Array<String>, NOT_SET] codes when declaring
49
+ # @return [Array<String>, nil] the declared codes
50
+ def languages(value = NOT_SET)
51
+ return @languages if value.equal?(NOT_SET)
52
+
53
+ @languages = Array(value).freeze
54
+ end
55
+
56
+ # Get or set the base physical grid.
57
+ #
58
+ # @param value [Symbol, NOT_SET] :qwerty or :qwertz
59
+ # @return [Symbol, nil] the declared base grid
60
+ def base_grid(value = NOT_SET)
61
+ return @base_grid if value.equal?(NOT_SET)
62
+
63
+ @base_grid = value
64
+ end
65
+
66
+ # Get or set keys removed from the base grid.
67
+ #
68
+ # Used by the Nordic members, whose å/æ/ø keys replace the
69
+ # US bracket and semicolon keys.
70
+ #
71
+ # @param value [Array<String>, NOT_SET] keys to remove
72
+ # @return [Array<String>, nil] the removed keys
73
+ def removed_keys(value = NOT_SET)
74
+ return @removed_keys if value.equal?(NOT_SET)
75
+
76
+ @removed_keys = Array(value).freeze
77
+ end
78
+
79
+ # Get or set extra physical keys merged over the base grid.
80
+ #
81
+ # @param value [Hash{String => Array<Integer>}, NOT_SET]
82
+ # key => [row, col] pairs
83
+ # @return [Hash{String => Array<Integer>}, nil] the extras
84
+ def extra_positions(value = NOT_SET)
85
+ return @extra_positions if value.equal?(NOT_SET)
86
+
87
+ @extra_positions = value.freeze
88
+ end
89
+ end
90
+
91
+ # Build the layout from the class declarations: the base grid,
92
+ # minus removed keys, plus extra physical keys.
93
+ def initialize
94
+ super(
95
+ name: self.class.layout_name,
96
+ language_codes: self.class.languages,
97
+ key_positions: build_positions
98
+ )
99
+ end
100
+
101
+ private
102
+
103
+ # Compose the final key-position grid.
104
+ #
105
+ # @return [Hash{String => Array<Integer>}] the composed grid
106
+ def build_positions
107
+ positions = base_grid_positions
108
+ removed = self.class.removed_keys
109
+ positions = positions.except(*removed) if removed
110
+ extras = self.class.extra_positions
111
+ extras ? positions.merge(extras) : positions
112
+ end
113
+
114
+ # Resolve the base grid constant.
115
+ #
116
+ # @return [Hash{String => Array<Integer>}] the base key positions
117
+ # @raise [ArgumentError] when no known base grid was declared
118
+ def base_grid_positions
119
+ case self.class.base_grid
120
+ when :qwerty then Layouts::QWERTY::KEY_POSITIONS
121
+ when :qwertz then Layouts::QWERTZ::KEY_POSITIONS
122
+ else
123
+ raise ArgumentError,
124
+ "#{self.class} must declare base_grid :qwerty or :qwertz"
125
+ end
126
+ end
127
+
128
+ # Italian: US QWERTY physical layout; accents are dead keys.
129
+ class Italian < Latin
130
+ layout_name 'Italian-QWERTY'
131
+ languages %w[it it-IT]
132
+ base_grid :qwerty
133
+ end
134
+
135
+ # Dutch: US QWERTY physical layout; accents are dead keys.
136
+ class Dutch < Latin
137
+ layout_name 'Dutch-QWERTY'
138
+ languages %w[nl nl-NL]
139
+ base_grid :qwerty
140
+ end
141
+
142
+ # Polish: programmers' (US-equivalent) QWERTY layout, the
143
+ # layout Polish fastText corpora are typed on; ą ć ę ł ń ó ś
144
+ # ź ż are AltGr sequences.
145
+ class Polish < Latin
146
+ layout_name 'Polish-QWERTY'
147
+ languages %w[pl pl-PL]
148
+ base_grid :qwerty
149
+ end
150
+
151
+ # Czech: QWERTZ physical layout (z/y swapped, ü ö ä keys);
152
+ # háčky and čárky are dead keys.
153
+ class Czech < Latin
154
+ layout_name 'Czech-QWERTZ'
155
+ languages %w[cs cs-CZ]
156
+ base_grid :qwertz
157
+ end
158
+
159
+ # Hungarian: QWERTZ physical layout; ő ű are dead keys.
160
+ class Hungarian < Latin
161
+ layout_name 'Hungarian-QWERTZ'
162
+ languages %w[hu hu-HU]
163
+ base_grid :qwertz
164
+ end
165
+
166
+ # Romanian: US QWERTY physical layout; ă â î ș ț are AltGr
167
+ # sequences.
168
+ class Romanian < Latin
169
+ layout_name 'Romanian-QWERTY'
170
+ languages %w[ro ro-RO]
171
+ base_grid :qwerty
172
+ end
173
+
174
+ # Catalan: Spanish (US-equivalent) QWERTY physical layout; the
175
+ # gem keys Catalan to the qwerty grid like the eval model does.
176
+ class Catalan < Latin
177
+ layout_name 'Catalan-QWERTY'
178
+ languages %w[ca ca-ES]
179
+ base_grid :qwerty
180
+ end
181
+
182
+ # Vietnamese: US QWERTY physical layout; all tone and vowel
183
+ # marks are typed with dead keys over the ASCII letters.
184
+ class Vietnamese < Latin
185
+ layout_name 'Vietnamese-QWERTY'
186
+ languages %w[vi vi-VN]
187
+ base_grid :qwerty
188
+ end
189
+
190
+ # Danish: Nordic QWERTY with real å æ ø keys replacing the
191
+ # US bracket/semicolon keys.
192
+ class Danish < Latin
193
+ layout_name 'Danish-QWERTY'
194
+ languages %w[da da-DK]
195
+ base_grid :qwerty
196
+ removed_keys %w([ ] ; ')
197
+ extra_positions({ 'å' => [1, 10], 'æ' => [2, 9], 'ø' => [2, 10] })
198
+ end
199
+
200
+ # Norwegian Bokmal: same Nordic physical grid as Danish (å æ ø).
201
+ class Norwegian < Latin
202
+ layout_name 'Norwegian-QWERTY'
203
+ languages %w[nb nb-NO]
204
+ base_grid :qwerty
205
+ removed_keys %w([ ] ; ')
206
+ extra_positions({ 'å' => [1, 10], 'æ' => [2, 9], 'ø' => [2, 10] })
207
+ end
208
+
209
+ # Swedish: Nordic QWERTY with real å ä ö keys (ä ö where
210
+ # Danish/Norwegian carry æ ø).
211
+ class Swedish < Latin
212
+ layout_name 'Swedish-QWERTY'
213
+ languages %w[sv sv-SE]
214
+ base_grid :qwerty
215
+ removed_keys %w([ ] ; ')
216
+ extra_positions({ 'å' => [1, 10], 'ä' => [2, 9], 'ö' => [2, 10] })
217
+ end
218
+
219
+ # Indonesian: US QWERTY physical layout — the Indonesian
220
+ # national standard types on the unmodified US grid, and the
221
+ # eval harness maps id the same way (plan 83 batch 2).
222
+ class Indonesian < Latin
223
+ layout_name 'Indonesian-QWERTY'
224
+ languages %w[id id-ID]
225
+ base_grid :qwerty
226
+ end
227
+
228
+ # Slovak: US QWERTY physical layout; the eval harness maps sk
229
+ # to the qwerty grid (plan 83 batch 2) with the háčik
230
+ # diacritics as dead-key slips, exactly the Polish
231
+ # programmers' pattern. The Slovak QWERTZ national variant
232
+ # exists, but Slovak QWERTY is the widely-typed form.
233
+ class Slovak < Latin
234
+ layout_name 'Slovak-QWERTY'
235
+ languages %w[sk sk-SK]
236
+ base_grid :qwerty
237
+ end
238
+
239
+ # Estonian: US QWERTY physical layout; ä ö õ ü š ž are dead-key
240
+ # or AltGr sequences on the eval model grid (plan 83 batch 2).
241
+ class Estonian < Latin
242
+ layout_name 'Estonian-QWERTY'
243
+ languages %w[et et-EE]
244
+ base_grid :qwerty
245
+ end
246
+
247
+ # Lithuanian: US QWERTY physical layout; ą č ę ė į š ų ū ž are
248
+ # dead-key or AltGr sequences (plan 83 batch 2 eval mapping).
249
+ class Lithuanian < Latin
250
+ layout_name 'Lithuanian-QWERTY'
251
+ languages %w[lt lt-LT]
252
+ base_grid :qwerty
253
+ end
254
+
255
+ # Latvian: US QWERTY physical layout; ā č ē ģ ī ķ ļ ņ š ū ž
256
+ # are dead-key or AltGr sequences (plan 83 batch 2 eval
257
+ # mapping).
258
+ class Latvian < Latin
259
+ layout_name 'Latvian-QWERTY'
260
+ languages %w[lv lv-LV]
261
+ base_grid :qwerty
262
+ end
263
+ end
264
+ end
265
+ end
266
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kotoshu
4
+ module Keyboard
5
+ module Layouts
6
+ # Persian standard keyboard layout (ISIRI 9147).
7
+ #
8
+ # Shares the Arabic letter skeleton but carries the four Persian
9
+ # letters as real keys: پ چ ژ گ replace their Arabic equivalents
10
+ # at standard positions, and ک ی are the Persian keheh/yeh
11
+ # keycaps. The ZWNJ and diacritics are dead keys and stay out of
12
+ # the grid; the Arabic→Persian letter slips (ك→ک ي→ی) are
13
+ # handled at the normalizer level.
14
+ #
15
+ # The key grid is mirrored from the models repo eval harness
16
+ # (kotoshu/models-fasttext-onnx eval/noise.py _FA_STD, plan 83
17
+ # batch 2 of the model coverage expansion, verified there
18
+ # against ISIRI 9147 renderings) so typo-adjacency used for
19
+ # suggestion ranking matches the adjacency used to evaluate the
20
+ # models. spec/kotoshu/keyboard/layouts/eval_grid_drift_spec.rb
21
+ # enforces the sync.
22
+ #
23
+ # Languages: fa, fa-IR
24
+ class PersianStandard < Layout
25
+ # Key positions for the Persian standard layout.
26
+ # Each key maps to [row, column] coordinates.
27
+ KEY_POSITIONS = {
28
+ # Number row
29
+ '`' => [0, 0], '1' => [0, 1], '2' => [0, 2], '3' => [0, 3],
30
+ '4' => [0, 4], '5' => [0, 5], '6' => [0, 6], '7' => [0, 7],
31
+ '8' => [0, 8], '9' => [0, 9], '0' => [0, 10], '-' => [0, 11],
32
+ '=' => [0, 12],
33
+ # Top row (ض ص ث ق ف غ ع ه خ ح ج چ)
34
+ 'ض' => [1, 0], 'ص' => [1, 1], 'ث' => [1, 2], 'ق' => [1, 3],
35
+ 'ف' => [1, 4], 'غ' => [1, 5], 'ع' => [1, 6], 'ه' => [1, 7],
36
+ 'خ' => [1, 8], 'ح' => [1, 9], 'ج' => [1, 10], 'چ' => [1, 11],
37
+ # Home row (ش س ی ب ل ا ت ن م ک گ)
38
+ 'ش' => [2, 0], 'س' => [2, 1], 'ی' => [2, 2], 'ب' => [2, 3],
39
+ 'ل' => [2, 4], 'ا' => [2, 5], 'ت' => [2, 6], 'ن' => [2, 7],
40
+ 'م' => [2, 8], 'ک' => [2, 9], 'گ' => [2, 10],
41
+ # Bottom row (ظ ط ز ر ذ د پ و ۀ .)
42
+ 'ظ' => [3, 0], 'ط' => [3, 1], 'ز' => [3, 2], 'ر' => [3, 3],
43
+ 'ذ' => [3, 4], 'د' => [3, 5], 'پ' => [3, 6], 'و' => [3, 7],
44
+ 'ۀ' => [3, 8], '.' => [3, 9]
45
+ }.freeze
46
+
47
+ # Initialize the Persian standard layout.
48
+ def initialize
49
+ super(
50
+ name: 'Persian-Standard',
51
+ language_codes: %w[fa fa-IR],
52
+ key_positions: KEY_POSITIONS
53
+ )
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kotoshu
4
+ module Keyboard
5
+ module Layouts
6
+ # QWERTY keyboard layout
7
+ #
8
+ # Standard QWERTY layout used for:
9
+ # - English (en, en-US, en-GB, etc.)
10
+ # - Spanish (es)
11
+ # - Portuguese (pt, pt-BR, pt-PT)
12
+ # - United States (us)
13
+ #
14
+ # Key positions use [row, col] coordinates where:
15
+ # - row 0: number row (`1`2`3...)
16
+ # - row 1: top row (qwerty...)
17
+ # - row 2: home row (asdfg...)
18
+ # - row 3: bottom row (zxcvb...)
19
+ class QWERTY < Layout
20
+ # Key positions for QWERTY layout
21
+ # Each key maps to [row, column] coordinates
22
+ KEY_POSITIONS = {
23
+ # Number row
24
+ '`' => [0, 0], '1' => [0, 1], '2' => [0, 2], '3' => [0, 3], '4' => [0, 4],
25
+ '5' => [0, 5], '6' => [0, 6], '7' => [0, 7], '8' => [0, 8], '9' => [0, 9],
26
+ '0' => [0, 10], '-' => [0, 11], '=' => [0, 12],
27
+ # Top row (QWERTY)
28
+ 'q' => [1, 0], 'w' => [1, 1], 'e' => [1, 2], 'r' => [1, 3], 't' => [1, 4],
29
+ 'y' => [1, 5], 'u' => [1, 6], 'i' => [1, 7], 'o' => [1, 8], 'p' => [1, 9],
30
+ '[' => [1, 10], ']' => [1, 11], '\\' => [1, 12],
31
+ # Home row (ASDFG)
32
+ 'a' => [2, 0], 's' => [2, 1], 'd' => [2, 2], 'f' => [2, 3], 'g' => [2, 4],
33
+ 'h' => [2, 5], 'j' => [2, 6], 'k' => [2, 7], 'l' => [2, 8], ';' => [2, 9],
34
+ '\'' => [2, 10],
35
+ # Bottom row (ZXCVB)
36
+ 'z' => [3, 0], 'x' => [3, 1], 'c' => [3, 2], 'v' => [3, 3], 'b' => [3, 4],
37
+ 'n' => [3, 5], 'm' => [3, 6], ',' => [3, 7], '.' => [3, 8], '/' => [3, 9]
38
+ }.freeze
39
+
40
+ # Initialize QWERTY layout
41
+ def initialize
42
+ super(
43
+ name: 'QWERTY',
44
+ language_codes: %w[en es pt us en-US en-GB en-AU en-CA en-NZ en-ZA
45
+ es-ES es-MX pt-BR pt-PT],
46
+ key_positions: KEY_POSITIONS
47
+ )
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kotoshu
4
+ module Keyboard
5
+ module Layouts
6
+ # QWERTZ keyboard layout
7
+ #
8
+ # Standard QWERTZ layout used for:
9
+ # - German (de, de-DE, de-AT, de-CH)
10
+ # - Austria (at)
11
+ # - Switzerland (ch)
12
+ #
13
+ # Key differences from QWERTY:
14
+ # - z and y are swapped (z/y → y/z)
15
+ # - Has umlaut keys: ä, ö, ü
16
+ # - Has ß key (Eszett)
17
+ #
18
+ # Key positions use [row, col] coordinates where:
19
+ # - row 0: number row (^°1"2...)
20
+ # - row 1: top row (qwertz...)
21
+ # - row 2: home row (asdfg...)
22
+ # - row 3: bottom row (yxcvb...) - note: y is here, not in top row
23
+ class QWERTZ < Layout
24
+ # Key positions for QWERTZ layout
25
+ # Each key maps to [row, column] coordinates
26
+ KEY_POSITIONS = {
27
+ # Number row
28
+ '^' => [0, 0], '1' => [0, 1], '2' => [0, 2], '3' => [0, 3], '4' => [0, 4],
29
+ '5' => [0, 5], '6' => [0, 6], '7' => [0, 7], '8' => [0, 8], '9' => [0, 9],
30
+ '0' => [0, 10], 'ß' => [0, 11], '´' => [0, 12],
31
+ # Top row (QWERTZ - note z and y are swapped)
32
+ 'q' => [1, 0], 'w' => [1, 1], 'e' => [1, 2], 'r' => [1, 3], 't' => [1, 4],
33
+ 'z' => [1, 5], 'u' => [1, 6], 'i' => [1, 7], 'o' => [1, 8], 'p' => [1, 9],
34
+ 'ü' => [1, 10], '+' => [1, 11],
35
+ # Home row (ASDFG)
36
+ 'a' => [2, 0], 's' => [2, 1], 'd' => [2, 2], 'f' => [2, 3], 'g' => [2, 4],
37
+ 'h' => [2, 5], 'j' => [2, 6], 'k' => [2, 7], 'l' => [2, 8], 'ö' => [2, 9],
38
+ 'ä' => [2, 10],
39
+ # Bottom row (YXCVB - note y is here)
40
+ 'y' => [3, 0], 'x' => [3, 1], 'c' => [3, 2], 'v' => [3, 3], 'b' => [3, 4],
41
+ 'n' => [3, 5], 'm' => [3, 6], ',' => [3, 7], '.' => [3, 8], '-' => [3, 9]
42
+ }.freeze
43
+
44
+ # Initialize QWERTZ layout
45
+ def initialize
46
+ super(
47
+ name: 'QWERTZ',
48
+ language_codes: %w[de at ch de-DE de-AT de-CH],
49
+ key_positions: KEY_POSITIONS
50
+ )
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kotoshu
4
+ module Keyboard
5
+ module Layouts
6
+ # Serbian Cyrillic keyboard layout (ЉЊЕРТЗУИОПШ /
7
+ # АСДФГХЈКЛЧЋ / ЏЦВБНМ, KBDSR driver table).
8
+ #
9
+ # The Serbian-specific letters љ њ ђ ћ џ ј are real keys: љ њ
10
+ # take the q/w faces, ђ sits where QWERTY carries the right
11
+ # bracket, and џ ц в б н м fill the bottom row. Serbian Latin
12
+ # (sr-Latn) types on the South-Slavic QWERTZ grid and is
13
+ # claimed by its own layout (Layouts::SerbianLatin, plan 110),
14
+ # not this one.
15
+ #
16
+ # The key grid is mirrored from the models repo eval harness
17
+ # (kotoshu/models-fasttext-onnx eval/noise.py _SR_CYR, plan 83
18
+ # batch 2 of the model coverage expansion) so typo-adjacency
19
+ # used for suggestion ranking matches the adjacency used to
20
+ # evaluate the models.
21
+ # spec/kotoshu/keyboard/layouts/eval_grid_drift_spec.rb enforces
22
+ # the sync.
23
+ #
24
+ # Languages: sr, sr-RS
25
+ class SerbianCyrillic < Layout
26
+ # Key positions for the Serbian Cyrillic layout.
27
+ # Each key maps to [row, column] coordinates.
28
+ KEY_POSITIONS = {
29
+ # Number row
30
+ '`' => [0, 0], '1' => [0, 1], '2' => [0, 2], '3' => [0, 3],
31
+ '4' => [0, 4], '5' => [0, 5], '6' => [0, 6], '7' => [0, 7],
32
+ '8' => [0, 8], '9' => [0, 9], '0' => [0, 10],
33
+ "'" => [0, 11], '+' => [0, 12],
34
+ # Top row (љ њ е р т з у и о п ш ђ)
35
+ 'љ' => [1, 0], 'њ' => [1, 1], 'е' => [1, 2], 'р' => [1, 3],
36
+ 'т' => [1, 4], 'з' => [1, 5], 'у' => [1, 6], 'и' => [1, 7],
37
+ 'о' => [1, 8], 'п' => [1, 9], 'ш' => [1, 10], 'ђ' => [1, 11],
38
+ # Home row (а с д ф г х ј к л ч ћ ж)
39
+ 'а' => [2, 0], 'с' => [2, 1], 'д' => [2, 2], 'ф' => [2, 3],
40
+ 'г' => [2, 4], 'х' => [2, 5], 'ј' => [2, 6], 'к' => [2, 7],
41
+ 'л' => [2, 8], 'ч' => [2, 9], 'ћ' => [2, 10], 'ж' => [2, 11],
42
+ # Bottom row (џ ц в б н м , . -)
43
+ 'џ' => [3, 0], 'ц' => [3, 1], 'в' => [3, 2], 'б' => [3, 3],
44
+ 'н' => [3, 4], 'м' => [3, 5], ',' => [3, 6], '.' => [3, 7],
45
+ '-' => [3, 8]
46
+ }.freeze
47
+
48
+ # Initialize the Serbian Cyrillic layout.
49
+ def initialize
50
+ super(
51
+ name: 'Serbian-Cyrillic',
52
+ language_codes: %w[sr sr-RS],
53
+ key_positions: KEY_POSITIONS
54
+ )
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kotoshu
4
+ module Keyboard
5
+ module Layouts
6
+ # Turkish-Q keyboard layout (standard Turkish physical layout).
7
+ #
8
+ # The Turkish-specific letters ı ğ ü ş i ö ç are real keys:
9
+ # ı sits where i is on QWERTY, i replaces the semicolon key, and
10
+ # ğ ü ş ö ç replace the bracket/apostrophe/slash family.
11
+ #
12
+ # The key grid is mirrored from the models repo eval harness
13
+ # (kotoshu/models-fasttext-onnx eval/noise.py _TR_Q, wave 1 of the
14
+ # model coverage expansion) so typo-adjacency used for suggestion
15
+ # ranking matches the adjacency used to evaluate the models.
16
+ # spec/kotoshu/keyboard/layouts/eval_grid_drift_spec.rb enforces
17
+ # the sync.
18
+ #
19
+ # Languages: tr, tr-TR
20
+ class TurkishQ < Layout
21
+ # Key positions for the Turkish-Q layout.
22
+ # Each key maps to [row, column] coordinates.
23
+ KEY_POSITIONS = {
24
+ # Number row
25
+ '"' => [0, 0], '1' => [0, 1], '2' => [0, 2], '3' => [0, 3], '4' => [0, 4],
26
+ '5' => [0, 5], '6' => [0, 6], '7' => [0, 7], '8' => [0, 8], '9' => [0, 9],
27
+ '0' => [0, 10], '*' => [0, 11], '-' => [0, 12],
28
+ # Top row (QWERTY + ı ğ ü)
29
+ 'q' => [1, 0], 'w' => [1, 1], 'e' => [1, 2], 'r' => [1, 3], 't' => [1, 4],
30
+ 'y' => [1, 5], 'u' => [1, 6], 'ı' => [1, 7], 'o' => [1, 8], 'p' => [1, 9],
31
+ 'ğ' => [1, 10], 'ü' => [1, 11],
32
+ # Home row (ASDFG + ş i)
33
+ 'a' => [2, 0], 's' => [2, 1], 'd' => [2, 2], 'f' => [2, 3], 'g' => [2, 4],
34
+ 'h' => [2, 5], 'j' => [2, 6], 'k' => [2, 7], 'l' => [2, 8], 'ş' => [2, 9],
35
+ 'i' => [2, 10],
36
+ # Bottom row (ZXCVB + ö ç)
37
+ 'z' => [3, 0], 'x' => [3, 1], 'c' => [3, 2], 'v' => [3, 3], 'b' => [3, 4],
38
+ 'n' => [3, 5], 'm' => [3, 6], 'ö' => [3, 7], 'ç' => [3, 8], '.' => [3, 9]
39
+ }.freeze
40
+
41
+ # Initialize the Turkish-Q layout.
42
+ def initialize
43
+ super(
44
+ name: 'Turkish-Q',
45
+ language_codes: %w[tr tr-TR],
46
+ key_positions: KEY_POSITIONS
47
+ )
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kotoshu
4
+ module Keyboard
5
+ module Layouts
6
+ # Ukrainian JCUKEN keyboard layout (standard Ukrainian layout).
7
+ #
8
+ # Extends the Russian JCUKEN grid with the Ukrainian-only keys:
9
+ # і replaces ы, ї replaces ъ, є replaces э, and ґ sits right of х.
10
+ # The Russian-only ы ъ э ё keys do not exist on the Ukrainian grid.
11
+ #
12
+ # The key grid is mirrored from the models repo eval harness
13
+ # (kotoshu/models-fasttext-onnx eval/noise.py _UK_JCUKEN, wave 1
14
+ # of the model coverage expansion). The drift spec
15
+ # spec/kotoshu/keyboard/layouts/eval_grid_drift_spec.rb enforces
16
+ # the sync.
17
+ #
18
+ # Languages: uk, uk-UA
19
+ class Ukrainian < Layout
20
+ # Key positions for the Ukrainian JCUKEN layout.
21
+ # Each key maps to [row, column] coordinates.
22
+ KEY_POSITIONS = {
23
+ # Number row
24
+ "'" => [0, 0], '1' => [0, 1], '2' => [0, 2], '3' => [0, 3], '4' => [0, 4],
25
+ '5' => [0, 5], '6' => [0, 6], '7' => [0, 7], '8' => [0, 8], '9' => [0, 9],
26
+ '0' => [0, 10], '-' => [0, 11], '=' => [0, 12],
27
+ # Top row (ЙЦУКЕН + ї ґ)
28
+ 'й' => [1, 0], 'ц' => [1, 1], 'у' => [1, 2], 'к' => [1, 3], 'е' => [1, 4],
29
+ 'н' => [1, 5], 'г' => [1, 6], 'ш' => [1, 7], 'щ' => [1, 8], 'з' => [1, 9],
30
+ 'х' => [1, 10], 'ї' => [1, 11], 'ґ' => [1, 12],
31
+ # Home row (ФІВАПР + є)
32
+ 'ф' => [2, 0], 'і' => [2, 1], 'в' => [2, 2], 'а' => [2, 3], 'п' => [2, 4],
33
+ 'р' => [2, 5], 'о' => [2, 6], 'л' => [2, 7], 'д' => [2, 8], 'ж' => [2, 9],
34
+ 'є' => [2, 10],
35
+ # Bottom row (ЯЧСМИТ + ь б ю)
36
+ 'я' => [3, 0], 'ч' => [3, 1], 'с' => [3, 2], 'м' => [3, 3], 'и' => [3, 4],
37
+ 'т' => [3, 5], 'ь' => [3, 6], 'б' => [3, 7], 'ю' => [3, 8], '.' => [3, 9]
38
+ }.freeze
39
+
40
+ # Initialize the Ukrainian JCUKEN layout.
41
+ def initialize
42
+ super(
43
+ name: 'Ukrainian-JCUKEN',
44
+ language_codes: %w[uk uk-UA],
45
+ key_positions: KEY_POSITIONS
46
+ )
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end