kotoshu-server 1.1.1 → 1.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bfd8418e06fb8a070347045192c1b3a8e189cc981ad833d9246458b16e5171e5
4
- data.tar.gz: 4a96aa19567eab995cf150a81471056c6b76cd1bd3cbbcf41a16d19294515974
3
+ metadata.gz: bdf662b103098322c9ebe3d8920a14c23a7226eb60cd16d766db124700498344
4
+ data.tar.gz: 7fc304aa0b161759fcd9d890ce8dce3094ba2108cbe11723e08e0d8b10ce0138
5
5
  SHA512:
6
- metadata.gz: ee4aef3288c7f61aee8b46d49584c847c6ac22357be3e8bfd67828b979a4f7ee368d3bc15e1f9e75e920d7a05c4818dc156df128b289d20aea03613a19b10a3e
7
- data.tar.gz: f495ec48ae62deca5df1f4c6d6d596a062f8cc1bd1faea2f96fe79e9997798768b70aa1ca187a4af1e1be0d2af5aae5da30ebe257c9e89e40b97186f2d9ae6ef
6
+ metadata.gz: 68b5e0ff986f50d897b2252202dec9d36341e74856f5a1d5920b5157fedee3ccf6b92a94cd01f4a9ca5e7483fcb47b85c7857055c0c351e1fda951714dae8407
7
+ data.tar.gz: 709e9075d9c2fd78c339cc98515e17e6fc4dff8855b23f95943cc03ce85f02c5a2446d573bd4250541d7a4887051008cf6523378cd0cd5ee4a7960ba0fa8aded
data/README.md CHANGED
@@ -74,6 +74,25 @@ the default fluency tier (the full tier is far larger), plus
74
74
  one-time model load on the first model-enabled request. Listing the
75
75
  language in `KOTOSHU_SERVER_MODEL_LANGS` warms it at boot instead.
76
76
 
77
+
78
+ ## Grammar checking (rules, bundled)
79
+
80
+ `POST /v1/check` accepts an optional `"grammar": true` flag. Grammar
81
+ checking is rule-only: the rule tiers bundle with the gem for
82
+ fourteen languages, no setup step and no downloads. The response
83
+ gains `grammar_errors` — each carries the `rule_id`, the character
84
+ `start_offset` and `end_offset`, the `message`, and the
85
+ `suggestions` array.
86
+
87
+ ```bash
88
+ curl -X POST http://127.0.0.1:9292/v1/check \
89
+ -H "Content-Type: application/json" \
90
+ -d '{"text": "Das ist der Standart.", "language": "de", "grammar": true}'
91
+ ```
92
+
93
+ Requires kotoshu >= 1.0.9 (the release that ships the rule tiers);
94
+ on older gems the flag is ignored.
95
+
77
96
  ## Language detection
78
97
 
79
98
  `POST /v1/detect` reports which engine answered in the `engine`
@@ -100,7 +119,7 @@ the installed gem — the 0.1.1 behavior, byte for byte.
100
119
  | `GET` | `/v1/health` | — | `{ status, ready, timestamp }` |
101
120
  | `GET` | `/v1/version` | — | `{ server, kotoshu, ruby }` |
102
121
  | `GET` | `/v1/languages` | — | `{ cached, supported, model }` |
103
- | `POST` | `/v1/check` | `{ text, language?, format?, model? }` | `{ file, word_count, errors: [...] }` |
122
+ | `POST` | `/v1/check` | `{ text, language?, format?, model?, grammar? }` | `{ file, word_count, errors: [...], grammar_errors: [...] }` |
104
123
  | `POST` | `/v1/suggest` | `{ word, language?, max? }` | `{ word, suggestions: [...] }` |
105
124
  | `POST` | `/v1/detect` | `{ text }` | `{ language, confidence, engine }` |
106
125
 
@@ -325,6 +325,13 @@ module Kotoshu
325
325
  halt_with_error(400, "missing 'text'") unless text.is_a?(String)
326
326
 
327
327
  want = want_model ? %i[spelling model] : %i[spelling]
328
+ # Grammar checks are rule-only and bundled with the gem — no
329
+ # setup step. Soft-gated: kotoshu >= the grammar release; on
330
+ # older gems the flag is simply ignored.
331
+ grammar_errors =
332
+ if body["grammar"] && Kotoshu.respond_to?(:grammar_check)
333
+ Kotoshu.grammar_check(text, language: language)
334
+ end
328
335
  result = with_resource(language, want: want) do |checker, bundle|
329
336
  if want_model && bundle.model.nil?
330
337
  # The gem resolves a nil model for languages that cannot
@@ -341,10 +348,23 @@ module Kotoshu
341
348
  end
342
349
 
343
350
  content_type :json
344
- case format_hint
345
- when "errors" then serialize_errors(result).to_json
346
- else serialize_full(result).to_json
351
+ payload =
352
+ case format_hint
353
+ when "errors" then serialize_errors(result)
354
+ else serialize_full(result)
355
+ end
356
+ if grammar_errors
357
+ payload = payload.merge("grammar_errors" => grammar_errors.map do |e|
358
+ {
359
+ "rule_id" => e[:rule_id],
360
+ "start_offset" => e[:start_offset],
361
+ "end_offset" => e[:end_offset],
362
+ "message" => e[:message],
363
+ "suggestions" => e[:suggestions]
364
+ }
365
+ end)
347
366
  end
367
+ payload.to_json
348
368
  end
349
369
 
350
370
  post "/v1/suggest" do
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kotoshu
4
4
  module Server
5
- VERSION = "1.1.1"
5
+ VERSION = "1.2.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kotoshu-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-09-29 00:00:00.000000000 Z
11
+ date: 2026-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kotoshu