Skip to content

Commit 648b255

Browse files
author
webdev778
authored
Merge pull request #22 from interscript/interscript-221-detect
Support Interscript.detect
2 parents f0ebc2c + 24c7503 commit 648b255

3 files changed

Lines changed: 44 additions & 6 deletions

File tree

Gemfile.lock

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ GEM
33
specs:
44
diff-lcs (1.4.4)
55
graphql (1.11.3)
6-
interscript (2.0.5)
7-
interscript-maps
6+
interscript (2.2.1)
7+
interscript-maps (~> 2.2.0)
8+
text
89
thor
9-
interscript-maps (2.0.5)
10+
interscript-maps (2.2.1)
1011
rake (13.0.1)
1112
rspec (3.9.0)
1213
rspec-core (~> 3.9.0)
@@ -21,19 +22,20 @@ GEM
2122
diff-lcs (>= 1.2.0, < 2.0)
2223
rspec-support (~> 3.9.0)
2324
rspec-support (3.9.3)
25+
text (1.3.1)
2426
thor (1.1.0)
2527

2628
PLATFORMS
2729
ruby
2830

2931
DEPENDENCIES
3032
graphql (~> 1.9)
31-
interscript (= 2.0.5)
33+
interscript (= 2.2.1)
3234
rake
3335
rspec
3436

3537
RUBY VERSION
36-
ruby 3.0.1p64
38+
ruby 3.0.2p107
3739

3840
BUNDLED WITH
3941
2.1.4

lib/interscript-api/graphql/types/query_type.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
require 'pathname' unless ENV["AWS_EXECUTION_ENV"].nil?
88

9+
class DetectionResultType < GraphQL::Schema::Object
10+
field :map_name, String, null: false
11+
field :distance, Float, null: false
12+
end
13+
914
class QueryType < GraphQL::Schema::Object
1015
description "Root Query for this API"
1116

@@ -40,6 +45,27 @@ def transliterate(system_code:, input:)
4045
)
4146
end
4247

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+
4369
def info
4470
JSON.generate({
4571
version: InterscriptApi::VERSION,

spec/interscript-api/lambda_function_spec.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
context "With valid input" do
77

8-
it "should return valid data" do
8+
it "should return valid data when transliterate is called" do
99
event = {
1010
"body" => '{transliterate(systemCode: "odni-rus-Cyrl-Latn-2015", input: "Михаил Тимофеевич Калашников")}'
1111
}
@@ -14,6 +14,16 @@
1414
expect(rs).to eql("Mikhail Timofeyevich Kalashnikov")
1515
end
1616

17+
it "should return valid data when detect is called" do
18+
event = {
19+
"body" => '{detect(input: "привет", output: "privet", mapPattern: "icao-ukr-*"){mapName,distance}}'
20+
}
21+
rs = handler(event: event)
22+
p rs
23+
rs = JSON.parse(rs[:body])["data"]["detect"]
24+
expect(rs).to eq([{"mapName" => "icao-ukr-Cyrl-Latn-9303", "distance" => 1.0}])
25+
end
26+
1727
it "should print system_codes" do
1828
ENV['INTERSCRIPT_STAGING'] = '1'
1929
event = {

0 commit comments

Comments
 (0)