|
6 | 6 |
|
7 | 7 | require 'pathname' unless ENV["AWS_EXECUTION_ENV"].nil? |
8 | 8 |
|
| 9 | +class DetectionResultType < GraphQL::Schema::Object |
| 10 | + field :map_name, String, null: false |
| 11 | + field :distance, Float, null: false |
| 12 | +end |
| 13 | + |
9 | 14 | class QueryType < GraphQL::Schema::Object |
10 | 15 | description "Root Query for this API" |
11 | 16 |
|
@@ -40,6 +45,27 @@ def transliterate(system_code:, input:) |
40 | 45 | ) |
41 | 46 | end |
42 | 47 |
|
| 48 | + field :detect, [DetectionResultType], null: true do |
| 49 | + description "Detect which transliteration system was used for #input to generate #output" |
| 50 | + argument :input, String, required: true |
| 51 | + argument :output, String, required: true |
| 52 | + |
| 53 | + argument :map_pattern, String, required: false, default_value: '*' |
| 54 | + end |
| 55 | + |
| 56 | + def detect(input:, output:, map_pattern: "*") |
| 57 | + Interscript.detect( |
| 58 | + input, |
| 59 | + output, |
| 60 | + compiler: Interscript::Compiler::Ruby, |
| 61 | + multiple: true, |
| 62 | + cache: @cache ||= {}, |
| 63 | + map_pattern: map_pattern |
| 64 | + ).map do |map_name, distance| |
| 65 | + { map_name: map_name, distance: distance } |
| 66 | + end |
| 67 | + end |
| 68 | + |
43 | 69 | def info |
44 | 70 | JSON.generate({ |
45 | 71 | version: InterscriptApi::VERSION, |
|
0 commit comments