rosette_api 1.12.1 → 1.14.3

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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +13 -0
  3. data/README.md +38 -0
  4. data/examples/README.md +36 -0
  5. data/examples/address_similarity.rb +35 -0
  6. data/examples/categories.rb +24 -0
  7. data/examples/entities.rb +31 -0
  8. data/examples/info.rb +20 -0
  9. data/examples/language.rb +23 -0
  10. data/examples/language_multilingual.rb +33 -0
  11. data/examples/morphology_complete.rb +23 -0
  12. data/examples/morphology_compound_components.rb +24 -0
  13. data/examples/morphology_han_readings.rb +22 -0
  14. data/examples/morphology_lemmas.rb +24 -0
  15. data/examples/morphology_parts_of_speech.rb +24 -0
  16. data/examples/name_deduplication.rb +27 -0
  17. data/examples/name_similarity.rb +28 -0
  18. data/examples/name_translation.rb +26 -0
  19. data/examples/ping.rb +20 -0
  20. data/examples/relationships.rb +31 -0
  21. data/examples/semantic_vectors.rb +22 -0
  22. data/examples/sentences.rb +28 -0
  23. data/examples/sentiment.rb +32 -0
  24. data/examples/similar_terms.rb +23 -0
  25. data/examples/syntax_dependencies.rb +25 -0
  26. data/examples/tokens.rb +22 -0
  27. data/examples/topics.rb +29 -0
  28. data/examples/transliteration.rb +25 -0
  29. data/lib/address_parameter.rb +117 -0
  30. data/lib/address_similarity_parameters.rb +49 -0
  31. data/lib/bad_request_error.rb +2 -0
  32. data/lib/bad_request_format_error.rb +2 -0
  33. data/lib/document_parameters.rb +20 -11
  34. data/lib/name_deduplication_parameters.rb +15 -7
  35. data/lib/name_parameter.rb +6 -3
  36. data/lib/name_similarity_parameters.rb +14 -6
  37. data/lib/name_translation_parameters.rb +12 -6
  38. data/lib/request_builder.rb +43 -18
  39. data/lib/rosette_api.rb +156 -71
  40. data/lib/rosette_api_error.rb +3 -1
  41. metadata +43 -13
  42. data/.rubocop.yml +0 -312
  43. data/tests/tests_spec.rb +0 -611
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This class encapsulates all Rosette API server errors encountered during
2
4
  # requests.
3
5
  class RosetteAPIError < StandardError
@@ -10,4 +12,4 @@ class RosetteAPIError < StandardError
10
12
  @status_code = status_code
11
13
  @message = message
12
14
  end
13
- end
15
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rosette_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.1
4
+ version: 1.14.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Basis Technology Corp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-08 00:00:00.000000000 Z
11
+ date: 2019-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubysl-securerandom
@@ -24,14 +24,46 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
- description: A Ruby client binding for the Rosette API, a multilingual text analytics
28
- RESTful API.
27
+ description: The Rosette Text Analytics Platform uses natural language processing,
28
+ statistical modeling, and machine learning to analyze unstructured and semi-structured
29
+ text across 364 language-encoding-script combinations, revealing valuable information
30
+ and actionable data. Rosette provides endpoints for extracting entities and relationships,
31
+ translating and comparing the similarity of names, categorizing and adding linguistic
32
+ tags to text and more.
29
33
  email: support@rosette.com
30
34
  executables: []
31
35
  extensions: []
32
36
  extra_rdoc_files: []
33
37
  files:
34
- - ".rubocop.yml"
38
+ - LICENSE
39
+ - README.md
40
+ - examples/README.md
41
+ - examples/address_similarity.rb
42
+ - examples/categories.rb
43
+ - examples/entities.rb
44
+ - examples/info.rb
45
+ - examples/language.rb
46
+ - examples/language_multilingual.rb
47
+ - examples/morphology_complete.rb
48
+ - examples/morphology_compound_components.rb
49
+ - examples/morphology_han_readings.rb
50
+ - examples/morphology_lemmas.rb
51
+ - examples/morphology_parts_of_speech.rb
52
+ - examples/name_deduplication.rb
53
+ - examples/name_similarity.rb
54
+ - examples/name_translation.rb
55
+ - examples/ping.rb
56
+ - examples/relationships.rb
57
+ - examples/semantic_vectors.rb
58
+ - examples/sentences.rb
59
+ - examples/sentiment.rb
60
+ - examples/similar_terms.rb
61
+ - examples/syntax_dependencies.rb
62
+ - examples/tokens.rb
63
+ - examples/topics.rb
64
+ - examples/transliteration.rb
65
+ - lib/address_parameter.rb
66
+ - lib/address_similarity_parameters.rb
35
67
  - lib/bad_request_error.rb
36
68
  - lib/bad_request_format_error.rb
37
69
  - lib/document_parameters.rb
@@ -42,10 +74,9 @@ files:
42
74
  - lib/request_builder.rb
43
75
  - lib/rosette_api.rb
44
76
  - lib/rosette_api_error.rb
45
- - tests/tests_spec.rb
46
77
  homepage: https://developer.rosette.com/
47
78
  licenses:
48
- - MIT
79
+ - Apache-2.0
49
80
  metadata: {}
50
81
  post_install_message:
51
82
  rdoc_options: []
@@ -55,16 +86,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
55
86
  requirements:
56
87
  - - ">="
57
88
  - !ruby/object:Gem::Version
58
- version: 2.0.0
89
+ version: 2.3.0
59
90
  required_rubygems_version: !ruby/object:Gem::Requirement
60
91
  requirements:
61
92
  - - ">="
62
93
  - !ruby/object:Gem::Version
63
94
  version: '0'
64
95
  requirements: []
65
- rubygems_version: 3.0.1
96
+ rubygems_version: 3.0.3
66
97
  signing_key:
67
- specification_version: 2
68
- summary: Rosette API gem that supports multilingual text-analytics.
69
- test_files:
70
- - tests/tests_spec.rb
98
+ specification_version: 4
99
+ summary: A Ruby interface for Rosette Text Analytics Platform.
100
+ test_files: []
@@ -1,312 +0,0 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2016-12-07 10:52:04 -0500 using RuboCop version 0.46.0.
4
- # The point is for the user to remove these configuration records
5
- # one by one as the offenses are removed from the code base.
6
- # Note that changes in the inspected code, or installation of new
7
- # versions of RuboCop, may require this file to be generated again.
8
-
9
- # Offense count: 1
10
- # Configuration parameters: Include.
11
- # Include: **/Gemfile, **/gems.rb
12
- Bundler/OrderedGems:
13
- Exclude:
14
- - 'Gemfile'
15
-
16
- # Offense count: 2
17
- Lint/Void:
18
- Exclude:
19
- - 'examples/sentences.rb'
20
- - 'examples/sentiment.rb'
21
-
22
- # Offense count: 3
23
- Metrics/AbcSize:
24
- Max: 41
25
-
26
- # Offense count: 4
27
- # Configuration parameters: CountComments.
28
- Metrics/BlockLength:
29
- Max: 425
30
-
31
- # Offense count: 2
32
- # Configuration parameters: CountComments.
33
- Metrics/ClassLength:
34
- Max: 140
35
-
36
- # Offense count: 142
37
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
38
- # URISchemes: http, https
39
- Metrics/LineLength:
40
- Max: 408
41
-
42
- # Offense count: 6
43
- # Configuration parameters: CountComments.
44
- Metrics/MethodLength:
45
- Max: 42
46
-
47
- # Offense count: 1
48
- # Configuration parameters: CountKeywordArgs.
49
- Metrics/ParameterLists:
50
- Max: 6
51
-
52
- # Offense count: 94
53
- # Cop supports --auto-correct.
54
- # Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
55
- # SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
56
- Style/AlignHash:
57
- Exclude:
58
- - 'tests/tests_spec.rb'
59
-
60
- # Offense count: 1
61
- # Cop supports --auto-correct.
62
- # Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
63
- # SupportedStyles: line_count_based, semantic, braces_for_chaining
64
- # ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
65
- # FunctionalMethods: let, let!, subject, watch
66
- # IgnoredMethods: lambda, proc, it
67
- Style/BlockDelimiters:
68
- Exclude:
69
- - 'tests/tests_spec.rb'
70
-
71
- # Offense count: 1
72
- # Cop supports --auto-correct.
73
- Style/BlockEndNewline:
74
- Exclude:
75
- - 'tests/tests_spec.rb'
76
-
77
- # Offense count: 18
78
- # Cop supports --auto-correct.
79
- # Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly.
80
- # SupportedStyles: assign_to_condition, assign_inside_condition
81
- Style/ConditionalAssignment:
82
- Enabled: false
83
-
84
- # Offense count: 40
85
- # Cop supports --auto-correct.
86
- # Configuration parameters: EnforcedStyle, SupportedStyles.
87
- # SupportedStyles: leading, trailing
88
- Style/DotPosition:
89
- Exclude:
90
- - 'tests/tests_spec.rb'
91
-
92
- # Offense count: 1
93
- # Cop supports --auto-correct.
94
- # Configuration parameters: AllowAdjacentOneLineDefs.
95
- Style/EmptyLineBetweenDefs:
96
- Exclude:
97
- - 'lib/rosette_api.rb'
98
-
99
- # Offense count: 4
100
- # Cop supports --auto-correct.
101
- Style/EmptyLines:
102
- Exclude:
103
- - 'examples/sentiment.rb'
104
- - 'lib/request_builder.rb'
105
- - 'rosette_api.gemspec'
106
-
107
- # Offense count: 2
108
- # Cop supports --auto-correct.
109
- # Configuration parameters: EnforcedStyle, SupportedStyles.
110
- # SupportedStyles: empty_lines, no_empty_lines
111
- Style/EmptyLinesAroundBlockBody:
112
- Exclude:
113
- - 'tests/tests_spec.rb'
114
-
115
- # Offense count: 1
116
- # Cop supports --auto-correct.
117
- Style/EmptyLinesAroundMethodBody:
118
- Exclude:
119
- - 'lib/request_builder.rb'
120
-
121
- # Offense count: 3
122
- # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
123
- Style/FileName:
124
- Exclude:
125
- - 'examples/morphology_compound-components.rb'
126
- - 'examples/morphology_han-readings.rb'
127
- - 'examples/morphology_parts-of-speech.rb'
128
-
129
- # Offense count: 2
130
- # Configuration parameters: SupportedStyles.
131
- # SupportedStyles: for, each
132
- Style/For:
133
- EnforcedStyle: for
134
-
135
- # Offense count: 30
136
- # Cop supports --auto-correct.
137
- # Configuration parameters: EnforcedStyle, SupportedStyles.
138
- # SupportedStyles: when_needed, always
139
- Style/FrozenStringLiteralComment:
140
- Enabled: false
141
-
142
- # Offense count: 4
143
- # Configuration parameters: MinBodyLength.
144
- Style/GuardClause:
145
- Exclude:
146
- - 'lib/name_similarity_parameters.rb'
147
- - 'lib/name_translation_parameters.rb'
148
- - 'lib/request_builder.rb'
149
-
150
- # Offense count: 90
151
- # Cop supports --auto-correct.
152
- # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
153
- # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
154
- Style/HashSyntax:
155
- Exclude:
156
- - 'tests/tests_spec.rb'
157
-
158
- # Offense count: 3
159
- # Cop supports --auto-correct.
160
- # Configuration parameters: EnforcedStyle, SupportedStyles.
161
- # SupportedStyles: normal, rails
162
- Style/IndentationConsistency:
163
- Exclude:
164
- - 'examples/sentences.rb'
165
- - 'examples/sentiment.rb'
166
- - 'lib/rosette_api.rb'
167
-
168
- # Offense count: 5
169
- # Cop supports --auto-correct.
170
- # Configuration parameters: Width.
171
- Style/IndentationWidth:
172
- Exclude:
173
- - 'examples/morphology_han-readings.rb'
174
- - 'lib/request_builder.rb'
175
- - 'tests/tests_spec.rb'
176
-
177
- # Offense count: 1
178
- # Cop supports --auto-correct.
179
- Style/MultilineBlockLayout:
180
- Exclude:
181
- - 'tests/tests_spec.rb'
182
-
183
- # Offense count: 41
184
- # Cop supports --auto-correct.
185
- # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
186
- # SupportedStyles: aligned, indented, indented_relative_to_receiver
187
- Style/MultilineMethodCallIndentation:
188
- Exclude:
189
- - 'tests/tests_spec.rb'
190
-
191
- # Offense count: 15
192
- # Cop supports --auto-correct.
193
- Style/MutableConstant:
194
- Exclude:
195
- - 'lib/rosette_api.rb'
196
-
197
- # Offense count: 1
198
- # Cop supports --auto-correct.
199
- Style/NegatedIf:
200
- Exclude:
201
- - 'lib/name_translation_parameters.rb'
202
-
203
- # Offense count: 1
204
- # Cop supports --auto-correct.
205
- # Configuration parameters: IncludeSemanticChanges.
206
- Style/NonNilCheck:
207
- Exclude:
208
- - 'lib/request_builder.rb'
209
-
210
- # Offense count: 2
211
- Style/OptionalArguments:
212
- Exclude:
213
- - 'lib/request_builder.rb'
214
-
215
- # Offense count: 4
216
- # Cop supports --auto-correct.
217
- # Configuration parameters: PreferredDelimiters.
218
- Style/PercentLiteralDelimiters:
219
- Exclude:
220
- - 'rosette_api.gemspec'
221
-
222
- # Offense count: 8
223
- # Cop supports --auto-correct.
224
- # Configuration parameters: SupportedStyles.
225
- # SupportedStyles: compact, exploded
226
- Style/RaiseArgs:
227
- EnforcedStyle: compact
228
-
229
- # Offense count: 7
230
- # Cop supports --auto-correct.
231
- Style/RedundantSelf:
232
- Exclude:
233
- - 'lib/document_parameters.rb'
234
- - 'lib/name_parameter.rb'
235
- - 'lib/name_similarity_parameters.rb'
236
- - 'lib/name_translation_parameters.rb'
237
-
238
- # Offense count: 1
239
- # Cop supports --auto-correct.
240
- Style/SpaceAfterColon:
241
- Exclude:
242
- - 'examples/name_similarity.rb'
243
-
244
- # Offense count: 2
245
- # Cop supports --auto-correct.
246
- # Configuration parameters: AllowForAlignment.
247
- Style/SpaceAroundOperators:
248
- Exclude:
249
- - 'examples/language.rb'
250
- - 'rosette_api.gemspec'
251
-
252
- # Offense count: 56
253
- # Cop supports --auto-correct.
254
- # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles.
255
- # SupportedStyles: space, no_space, compact
256
- Style/SpaceInsideHashLiteralBraces:
257
- Exclude:
258
- - 'examples/language.rb'
259
- - 'tests/tests_spec.rb'
260
-
261
- # Offense count: 44
262
- # Cop supports --auto-correct.
263
- # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
264
- # SupportedStyles: single_quotes, double_quotes
265
- Style/StringLiterals:
266
- Exclude:
267
- - 'Gemfile'
268
- - 'examples/categories.rb'
269
- - 'examples/entities.rb'
270
- - 'examples/language.rb'
271
- - 'examples/morphology_complete.rb'
272
- - 'examples/morphology_compound-components.rb'
273
- - 'examples/morphology_han-readings.rb'
274
- - 'examples/name_similarity.rb'
275
- - 'examples/name_translation.rb'
276
- - 'examples/sentiment.rb'
277
- - 'examples/syntax_dependencies.rb'
278
- - 'examples/tokens.rb'
279
- - 'tests/tests_spec.rb'
280
-
281
- # Offense count: 14
282
- # Cop supports --auto-correct.
283
- # Configuration parameters: EnforcedStyle, SupportedStyles.
284
- # SupportedStyles: final_newline, final_blank_line
285
- Style/TrailingBlankLines:
286
- Exclude:
287
- - 'examples/info.rb'
288
- - 'examples/language.rb'
289
- - 'examples/morphology_compound-components.rb'
290
- - 'examples/morphology_han-readings.rb'
291
- - 'examples/morphology_lemmas.rb'
292
- - 'examples/morphology_parts-of-speech.rb'
293
- - 'examples/name_similarity.rb'
294
- - 'examples/name_translation.rb'
295
- - 'examples/ping.rb'
296
- - 'examples/sentences.rb'
297
- - 'examples/sentiment.rb'
298
- - 'examples/tokens.rb'
299
- - 'lib/rosette_api.rb'
300
- - 'lib/rosette_api_error.rb'
301
-
302
- # Offense count: 1
303
- # Cop supports --auto-correct.
304
- Style/TrailingWhitespace:
305
- Exclude:
306
- - 'lib/request_builder.rb'
307
-
308
- # Offense count: 4
309
- # Cop supports --auto-correct.
310
- Style/UnneededPercentQ:
311
- Exclude:
312
- - 'rosette_api.gemspec'
@@ -1,611 +0,0 @@
1
- # encoding: UTF-8
2
- require 'rosette_api'
3
- require 'rspec'
4
- require 'webmock/rspec'
5
- require 'json'
6
- WebMock.disable_net_connect!(allow_localhost: true)
7
-
8
- describe RosetteAPI do
9
- RSpec.configure do |config|
10
- config.before(:example) { @content = 'Sample Content' }
11
- config.before(:example) { @json = {content: 'Sample Content'}.to_json }
12
- config.before(:example) { @user_agent = 'Ruby/' + RosetteAPI::BINDING_VERSION + '/' + RUBY_VERSION }
13
- end
14
-
15
- describe '.user_agent' do
16
- it 'check User-Agent string' do
17
- result = RosetteAPI.new('0123456789').user_agent
18
- expect(result).to eq @user_agent
19
- end
20
- end
21
-
22
- describe '.get_language' do
23
- before do
24
- stub_request(:post, 'https://api.rosette.com/rest/v1/language')
25
- .with(body: @json,
26
- headers: { 'Accept' => 'application/json',
27
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
28
- 'Content-Type' => 'application/json',
29
- 'User-Agent' => @user_agent,
30
- 'X-Rosetteapi-Key' => '0123456789',
31
- 'X-Rosetteapi-Binding' => 'ruby',
32
- 'X-Rosetteapi-Binding-Version' => '1.12.1' })
33
- .to_return(status: 200, body: '{"test": "language"}', headers: {})
34
- end
35
- it 'test language' do
36
- params = DocumentParameters.new
37
- params.content = @content
38
- response = RosetteAPI.new('0123456789').get_language(params)
39
- expect(response).instance_of? Hash
40
- end
41
-
42
- it 'badRequestFormat: the format of the request is invalid: multiple content sources' do
43
- params = DocumentParameters.new
44
- params.content = 'Por favor Senorita, says the man.?'
45
- params.content_uri = 'Por favor Senorita, says the man.?'
46
- expect { RosetteAPI.new('0123456789').get_language(params) }.to raise_error(BadRequestFormatError)
47
- end
48
-
49
- it 'badRequestFormat: the format of the request is invalid: no content provided;' do
50
- params = DocumentParameters.new
51
- expect { RosetteAPI.new('0123456789').get_language(params) }.to raise_error(BadRequestFormatError)
52
- end
53
-
54
- end
55
-
56
- describe '.get_morphology_complete' do
57
- before do
58
- stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/complete')
59
- .with(body: @json,
60
- headers: { 'Accept' => 'application/json',
61
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
62
- 'Content-Type' => 'application/json',
63
- 'User-Agent' => @user_agent,
64
- 'X-Rosetteapi-Key' => '0123456789',
65
- 'X-Rosetteapi-Binding' => 'ruby',
66
- 'X-Rosetteapi-Binding-Version' => '1.12.1' })
67
- .to_return(status: 200, body: '{"test": "morphology/complete"}', headers: {})
68
- end
69
- it 'test morphology complete' do
70
- params = DocumentParameters.new
71
- params.content = @content
72
- response = RosetteAPI.new('0123456789').get_morphology_complete(params)
73
- expect(response).instance_of? Hash
74
- end
75
- end
76
-
77
- describe '.get_compound_components' do
78
- before do
79
- stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/compound-components')
80
- .with(body: @json,
81
- headers: { 'Accept' => 'application/json',
82
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
83
- 'Content-Type' => 'application/json',
84
- 'User-Agent' => @user_agent,
85
- 'X-Rosetteapi-Key' => '0123456789',
86
- 'X-Rosetteapi-Binding' => 'ruby',
87
- 'X-Rosetteapi-Binding-Version' => '1.12.1' })
88
- .to_return(status: 200, body: '{"test": "morphology/compound-components"}', headers: {})
89
- end
90
- it 'test morphology compound components' do
91
- params = DocumentParameters.new
92
- params.content = @content
93
- response = RosetteAPI.new('0123456789').get_compound_components(params)
94
- expect(response).instance_of? Hash
95
- end
96
- end
97
-
98
- describe '.get_han_readings' do
99
- before do
100
- stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/han-readings')
101
- .with(body: @json,
102
- headers: { 'Accept' => 'application/json',
103
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
104
- 'Content-Type' => 'application/json',
105
- 'User-Agent' => @user_agent,
106
- 'X-Rosetteapi-Key' => '0123456789',
107
- 'X-Rosetteapi-Binding' => 'ruby',
108
- 'X-Rosetteapi-Binding-Version' => '1.12.1' })
109
- .to_return(status: 200, body: '{"test": "morphology/han-readings"}', headers: {})
110
- end
111
- it 'test morphology han readings' do
112
- params = DocumentParameters.new
113
- params.content = @content
114
- response = RosetteAPI.new('0123456789').get_han_readings(params)
115
- expect(response).instance_of? Hash
116
- end
117
- end
118
-
119
- describe '.get_parts_of_speech' do
120
- before do
121
- stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/parts-of-speech')
122
- .with(body: @json,
123
- headers: { 'Accept' => 'application/json',
124
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
125
- 'Content-Type' => 'application/json',
126
- 'User-Agent' => @user_agent,
127
- 'X-Rosetteapi-Key' => '0123456789',
128
- 'X-Rosetteapi-Binding' => 'ruby',
129
- 'X-Rosetteapi-Binding-Version' => '1.12.1' })
130
- .to_return(status: 200, body: '{"test": "morphology/parts-of-speech"}', headers: {})
131
- end
132
- it 'test morphology parts of speech' do
133
- params = DocumentParameters.new
134
- params.content = @content
135
- response = RosetteAPI.new('0123456789').get_parts_of_speech(params)
136
- expect(response).instance_of? Hash
137
- end
138
- end
139
-
140
- describe '.get_lemmas' do
141
- before do
142
- stub_request(:post, 'https://api.rosette.com/rest/v1/morphology/lemmas')
143
- .with(body: @json,
144
- headers: { 'Accept' => 'application/json',
145
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
146
- 'Content-Type' => 'application/json',
147
- 'User-Agent' => @user_agent,
148
- 'X-Rosetteapi-Key' => '0123456789',
149
- 'X-Rosetteapi-Binding' => 'ruby',
150
- 'X-Rosetteapi-Binding-Version' => '1.12.1' })
151
- .to_return(status: 200, body: '{"test": "morphology/lemmas"}', headers: {})
152
- end
153
- it 'test morphology lemmas' do
154
- params = DocumentParameters.new
155
- params.content = @content
156
- response = RosetteAPI.new('0123456789').get_lemmas(params)
157
- expect(response).instance_of? Hash
158
- end
159
- end
160
-
161
- describe '.get_entities' do
162
- before do
163
- stub_request(:post, 'https://api.rosette.com/rest/v1/entities')
164
- .with(body: @json,
165
- headers: { 'Accept' => 'application/json',
166
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
167
- 'Content-Type' => 'application/json',
168
- 'User-Agent' => @user_agent,
169
- 'X-Rosetteapi-Key' => '0123456789',
170
- 'X-Rosetteapi-Binding' => 'ruby',
171
- 'X-Rosetteapi-Binding-Version' => '1.12.1' })
172
- .to_return(status: 200, body: '{"test": "entities"}', headers: {})
173
- end
174
- it 'test entities' do
175
- params = DocumentParameters.new
176
- params.content = @content
177
- response = RosetteAPI.new('0123456789').get_entities(params)
178
- expect(response).instance_of? Hash
179
- end
180
- end
181
-
182
- describe '.get_entities_no_qids' do
183
- before do
184
- no_qids_json = { content: 'Sample Content', options: { linkEntities: false } }.to_json
185
- stub_request(:post, 'https://api.rosette.com/rest/v1/entities')
186
- .with(body: no_qids_json,
187
- headers: { 'Accept' => 'application/json',
188
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
189
- 'Content-Type' => 'application/json',
190
- 'User-Agent' => @user_agent,
191
- 'X-Rosetteapi-Key' => '0123456789',
192
- 'X-Rosetteapi-Binding' => 'ruby',
193
- 'X-Rosetteapi-Binding-Version' => '1.12.1' })
194
- .to_return(status: 200, body: '{"test": "entities"}', headers: {})
195
- end
196
- it 'test entities without qids' do
197
- params = DocumentParameters.new
198
- params.content = @content
199
- params.rosette_options = { linkEntities: false}
200
- response = RosetteAPI.new('0123456789').get_entities(params)
201
- expect(response).instance_of? Hash
202
- end
203
-
204
- it 'test rosette_options is not a Hash' do
205
- params = DocumentParameters.new
206
- params.content = 'Last month director Paul Feig announced the movie will have an all-star female cast including' \
207
- ' Kristen Wiig, Melissa McCarthy, Leslie Jones and Kate McKinnon.'
208
- params.rosette_options = 1
209
- expect { RosetteAPI.new('0123456789').get_entities(params) }.to raise_error(BadRequestError)
210
- end
211
- end
212
-
213
- describe '.get_categories' do
214
- before do
215
- categories_json = { contentUri: 'http://google.com' }.to_json
216
- stub_request(:post, 'https://api.rosette.com/rest/v1/categories')
217
- .with(body: categories_json,
218
- headers: { 'Accept' => 'application/json',
219
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
220
- 'Content-Type' => 'application/json',
221
- 'User-Agent' => @user_agent,
222
- 'X-Rosetteapi-Key' => '0123456789',
223
- 'X-Rosetteapi-Binding' => 'ruby',
224
- 'X-Rosetteapi-Binding-Version' => '1.12.1' })
225
- .to_return(status: 200, body: '{"test": "categories"}', headers: {})
226
- end
227
- it 'test categories' do
228
- params = DocumentParameters.new
229
- params.content_uri = 'http://google.com'
230
- response = RosetteAPI.new('0123456789').get_categories(params)
231
- expect(response).instance_of? Hash
232
- end
233
- end
234
-
235
- describe '.get_relationships' do
236
- before do
237
- stub_request(:post, 'https://api.rosette.com/rest/v1/relationships')
238
- .with(body: @json,
239
- headers: { 'Accept' => 'application/json',
240
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
241
- 'Content-Type' => 'application/json',
242
- 'User-Agent' => @user_agent,
243
- 'X-Rosetteapi-Key' => '0123456789',
244
- 'X-Rosetteapi-Binding' => 'ruby',
245
- 'X-Rosetteapi-Binding-Version' => '1.12.1' })
246
- .to_return(status: 200, body: '{"test": "relationships"}', headers: {})
247
- end
248
- it 'test relationships' do
249
- params = DocumentParameters.new
250
- params.content = @content
251
- response = RosetteAPI.new('0123456789').get_relationships(params)
252
- expect(response).instance_of? Hash
253
- end
254
- end
255
-
256
- describe '.name_translation' do
257
- before do
258
- name_translation_json = { name: 'معمر محمد أبو منيار القذاف', targetLanguage: 'eng', targetScript: 'Latn' }.to_json
259
- stub_request(:post, 'https://api.rosette.com/rest/v1/name-translation')
260
- .with(body: name_translation_json,
261
- headers: { 'Accept' => 'application/json',
262
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
263
- 'Content-Type' => 'application/json',
264
- 'User-Agent' => @user_agent,
265
- 'X-Rosetteapi-Key' => '0123456789',
266
- 'X-Rosetteapi-Binding' => 'ruby',
267
- 'X-Rosetteapi-Binding-Version' => '1.12.1' })
268
- .to_return(status: 200, body: '{"test": "name-translation"}', headers: {})
269
- end
270
- it 'test name translation' do
271
- params = NameTranslationParameters.new('معمر محمد أبو منيار القذاف'.encode('UTF-8'), 'eng')
272
- params.target_script = 'Latn'
273
- response = RosetteAPI.new('0123456789').get_name_translation(params)
274
- expect(response).instance_of? Hash
275
- end
276
-
277
- it 'badRequest: Expects NameTranslationParameters type as an argument' do
278
- params = NameSimilarityParameters.new('Michael Jackson', '迈克尔·杰克逊')
279
- expect { RosetteAPI.new('0123456789').get_name_translation(params) }.to raise_error(BadRequestError)
280
- end
281
- end
282
-
283
- describe '.name_similarity' do
284
- before do
285
- name_similarity_json = { name1: 'Michael Jackson', name2: '迈克尔·杰克逊' }.to_json
286
- stub_request(:post, 'https://api.rosette.com/rest/v1/name-similarity')
287
- .with(body: name_similarity_json,
288
- headers: { 'Accept' => 'application/json',
289
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
290
- 'Content-Type' => 'application/json',
291
- 'User-Agent' => @user_agent,
292
- 'X-Rosetteapi-Key' => '0123456789',
293
- 'X-Rosetteapi-Binding' => 'ruby',
294
- 'X-Rosetteapi-Binding-Version' => '1.12.1' })
295
- .to_return(status: 200, body: '{"test": "name-similarity"}', headers: {})
296
- end
297
- it 'test name similarity' do
298
- params = NameSimilarityParameters.new('Michael Jackson', '迈克尔·杰克逊')
299
- response = RosetteAPI.new('0123456789').get_name_similarity(params)
300
- expect(response).instance_of? Hash
301
- end
302
-
303
- it 'badRequestFormat: name1 option can only be an instance of a String or NameParameter' do
304
- params = NameSimilarityParameters.new(123, 'Michael Jackson')
305
- expect { RosetteAPI.new('0123456789').get_name_similarity(params) }.to raise_error(BadRequestError)
306
- end
307
-
308
- it 'badRequestFormat: name2 option can only be an instance of a String or NameParameter' do
309
- params = NameSimilarityParameters.new('Michael Jackson', 123)
310
- expect { RosetteAPI.new('0123456789').get_name_similarity(params) }.to raise_error(BadRequestError)
311
- end
312
-
313
- it 'badRequest: Expects NameSimilarityParameters type as an argument' do
314
- params = NameTranslationParameters.new('معمر محمد أبو منيار القذاف'.encode('UTF-8'), 'eng')
315
- expect { RosetteAPI.new('0123456789').get_name_similarity(params) }.to raise_error(BadRequestError)
316
- end
317
- end
318
-
319
- describe '.name_deduplication' do
320
- names = ['John Smith', 'Johnathon Smith', 'Fred Jones'].map { |n| NameParameter.new(n) }
321
- before do
322
- names_json = { names: names.map(&:load_param), threshold: 0.75 }.to_json
323
-
324
- stub_request(:post, 'https://api.rosette.com/rest/v1/name-deduplication')
325
- .with(body: names_json,
326
- headers: {'Accept' => 'application/json',
327
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
328
- 'Content-Type' => 'application/json',
329
- 'User-Agent' => @user_agent,
330
- 'X-Rosetteapi-Key' => '0123456789',
331
- 'X-Rosetteapi-Binding' => 'ruby',
332
- 'X-Rosetteapi-Binding-Version' => '1.12.1' })
333
- .to_return(status: 200, body: '{"test": "name-deduplication"}', headers: {})
334
-
335
- nothresh_json = { names: names.map(&:load_param) }.to_json
336
-
337
- stub_request(:post, 'https://api.rosette.com/rest/v1/name-deduplication')
338
- .with(body: nothresh_json,
339
- headers: {'Accept' => 'application/json',
340
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
341
- 'Content-Type' => 'application/json',
342
- 'User-Agent' => @user_agent,
343
- 'X-Rosetteapi-Key' => '0123456789',
344
- 'X-Rosetteapi-Binding' => 'ruby',
345
- 'X-Rosetteapi-Binding-Version' => '1.12.1' })
346
- .to_return(status: 200, body: '{"test": "name-deduplication"}', headers: {})
347
- end
348
- it 'test name deduplication' do
349
- params = NameDeduplicationParameters.new(names, 0.75)
350
- response = RosetteAPI.new('0123456789').get_name_deduplication(params)
351
- expect(response).instance_of? Hash
352
- end
353
-
354
- it 'test null threshold' do
355
- params = NameDeduplicationParameters.new(names, nil)
356
- response = RosetteAPI.new('0123456789').get_name_deduplication(params)
357
- expect(response).instance_of? Hash
358
- end
359
-
360
- it 'badRequestFormat: names must be an array of name_parameter' do
361
- params = NameDeduplicationParameters.new('Michael Jackson', 0.75)
362
- expect { RosetteAPI.new('0123456789').get_name_deduplication(params) }.to raise_error(BadRequestError)
363
- end
364
-
365
- it 'badRequestFormat: threshold must be a float' do
366
- params = NameDeduplicationParameters.new(names, 123)
367
- expect { RosetteAPI.new('0123456789').get_name_deduplication(params) }.to raise_error(BadRequestError)
368
- end
369
-
370
- it 'badRequest: threshold must be in the range of 0 to 1' do
371
- params = NameDeduplicationParameters.new(names, 1.5)
372
- expect { RosetteAPI.new('0123456789').get_name_deduplication(params) }.to raise_error(BadRequestError)
373
- end
374
-
375
- it 'badRequest: rosette_options can only be an instance of a Hash' do
376
- params = NameDeduplicationParameters.new(names, 0.5)
377
- params.rosette_options = 1
378
- expect { RosetteAPI.new('0123456789').get_name_deduplication(params) }.to raise_error(BadRequestError)
379
- end
380
- end
381
-
382
- describe '.transliteration' do
383
- content = 'Kareem Abdul Jabbar holds the record for most points in the NBA'
384
-
385
- before do
386
- transliteration_json = { content: content }.to_json
387
-
388
- stub_request(:post, 'https://api.rosette.com/rest/v1/transliteration')
389
- .with(body: transliteration_json,
390
- headers: {'Accept' => 'application/json',
391
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
392
- 'Content-Type' => 'application/json',
393
- 'User-Agent' => @user_agent,
394
- 'X-Rosetteapi-Key' => '0123456789',
395
- 'X-Rosetteapi-Binding' => 'ruby',
396
- 'X-Rosetteapi-Binding-Version' => '1.12.1' })
397
- .to_return(status: 200, body: '{"test": "transliteration"}', headers: {})
398
- end
399
- it 'test transliteration' do
400
- params = DocumentParameters.new
401
- params.content = content
402
- response = RosetteAPI.new('0123456789').get_transliteration(params)
403
- expect(response).instance_of? Hash
404
- end
405
-
406
- it 'badRequest: content must be provided' do
407
- params = DocumentParameters.new
408
- expect { RosetteAPI.new('0123456789').get_transliteration(params) }.to raise_error(BadRequestFormatError)
409
- end
410
-
411
- it 'badRequest: rosette_options can only be an instance of a Hash' do
412
- params = DocumentParameters.new
413
- params.content = content
414
- params.rosette_options = 1
415
- expect { RosetteAPI.new('0123456789').get_transliteration(params) }.to raise_error(BadRequestError)
416
- end
417
- end
418
-
419
- describe '.get_tokens' do
420
- before do
421
- stub_request(:post, 'https://api.rosette.com/rest/v1/tokens')
422
- .with(body: @json,
423
- headers: { 'Accept' => 'application/json',
424
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
425
- 'Content-Type' => 'application/json',
426
- 'User-Agent' => @user_agent,
427
- 'X-Rosetteapi-Key' => '0123456789',
428
- 'X-Rosetteapi-Binding' => 'ruby',
429
- 'X-Rosetteapi-Binding-Version' => '1.12.1' })
430
- .to_return(status: 200, body: '{"test": "tokens"}', headers: {})
431
- end
432
- it 'test tokens' do
433
- params = DocumentParameters.new
434
- params.content = @content
435
- response = RosetteAPI.new('0123456789').get_tokens(params)
436
- expect(response).instance_of? Hash
437
- end
438
- end
439
-
440
- describe '.get_topics' do
441
- before do
442
- stub_request(:post, 'https://api.rosette.com/rest/v1/topics')
443
- .with(body: @json,
444
- headers: { 'Accept' => 'application/json',
445
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
446
- 'Content-Type' => 'application/json',
447
- 'User-Agent' => @user_agent,
448
- 'X-Rosetteapi-Key' => '0123456789',
449
- 'X-Rosetteapi-Binding' => 'ruby',
450
- 'X-Rosetteapi-Binding-Version' => '1.12.1' })
451
- .to_return(status: 200, body: '{"test": "topics"}', headers: {})
452
- end
453
- it 'test topics' do
454
- params = DocumentParameters.new
455
- params.content = @content
456
- response = RosetteAPI.new('0123456789').get_topics(params)
457
- expect(response).instance_of? Hash
458
- end
459
- end
460
-
461
- describe '.get_sentences' do
462
- before do
463
- stub_request(:post, 'https://api.rosette.com/rest/v1/sentences')
464
- .with(body: @json,
465
- headers: { 'Accept' => 'application/json',
466
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
467
- 'Content-Type' => 'application/json',
468
- 'User-Agent' => @user_agent,
469
- 'X-Rosetteapi-Key' => '0123456789',
470
- 'X-Rosetteapi-Binding' => 'ruby',
471
- 'X-Rosetteapi-Binding-Version' => '1.12.1' })
472
- .to_return(status: 200, body: '{"test": "sentences"}', headers: {})
473
- end
474
- it 'test sentences' do
475
- params = DocumentParameters.new
476
- params.content = @content
477
- response = RosetteAPI.new('0123456789').get_sentences(params)
478
- expect(response).instance_of? Hash
479
- end
480
- end
481
-
482
- describe '.info' do
483
- before do
484
- stub_request(:get, 'https://api.rosette.com/rest/v1/info')
485
- .with(headers: { 'Accept' => '*/*',
486
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
487
- 'User-Agent' => @user_agent,
488
- 'X-Rosetteapi-Key' => '0123456789' })
489
- .to_return(status: 200, body: '{"test": "info"}', headers: {})
490
- end
491
- it 'test info' do
492
- response = RosetteAPI.new('0123456789').info
493
- expect(response).instance_of? Hash
494
- end
495
- end
496
-
497
- describe '.ping' do
498
- before do
499
- stub_request(:get, 'https://api.rosette.com/rest/v1/ping')
500
- .with(headers: { 'Accept' => '*/*',
501
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
502
- 'User-Agent' => @user_agent,
503
- 'X-Rosetteapi-Key' => '0123456789' })
504
- .to_return(status: 200, body: '{"test": "ping"}', headers: {})
505
- end
506
- it 'test ping' do
507
- response = RosetteAPI.new('0123456789').ping
508
- expect(response).instance_of? Hash
509
- end
510
- end
511
-
512
- describe '.get_language_custom_header' do
513
- before do
514
- stub_request(:post, 'https://api.rosette.com/rest/v1/language')
515
- .with(body: @json,
516
- headers: { 'Accept' => 'application/json',
517
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
518
- 'Content-Type' => 'application/json',
519
- 'User-Agent' => @user_agent,
520
- 'X-Rosetteapi-Key' => '0123456789',
521
- 'X-Rosetteapi-Binding' => 'ruby',
522
- 'X-Rosetteapi-Binding-Version' => '1.12.1',
523
- 'X-RosetteApi-App' => 'ruby-app' })
524
- .to_return(status: 200, body: '{"test": "language"}', headers: {})
525
- end
526
-
527
- it 'test custom_headers is invalid' do
528
- params = DocumentParameters.new
529
- params.content = 'Por favor Senorita, says the man.?'
530
- params.custom_headers = {'test' => 'ruby-app'}
531
- expect { RosetteAPI.new('0123456789').get_language(params) }.to raise_error(RosetteAPIError)
532
- end
533
- end
534
-
535
- describe '.error_409_incompatible_client_version' do
536
- before do
537
- stub_request(:get, 'https://api.rosette.com/rest/v1/info')
538
- .with(headers: { 'Accept' => '*/*',
539
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
540
- 'User-Agent' => @user_agent,
541
- 'X-Rosetteapi-Key' => '0123456789' })
542
- .to_return(status: 409, body: '{"code": "incompatibleClientVersion"}', headers: {})
543
- end
544
- it 'test error 409 properly handled' do
545
- expect { RosetteAPI.new('0123456789').info }.to raise_error(RosetteAPIError)
546
- end
547
- end
548
-
549
- describe '.get_similar_terms' do
550
- before do
551
- stub_request(:post, 'https://api.rosette.com/rest/v1/semantics/similar')
552
- .with(body: @json,
553
- headers: { 'Accept' => 'application/json',
554
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
555
- 'Content-Type' => 'application/json',
556
- 'User-Agent' => @user_agent,
557
- 'X-Rosetteapi-Key' => '0123456789',
558
- 'X-Rosetteapi-Binding' => 'ruby',
559
- 'X-Rosetteapi-Binding-Version' => '1.12.1' })
560
- .to_return(status: 200, body: '{"test": "language"}', headers: {})
561
- end
562
- it 'test similar_terms' do
563
- params = DocumentParameters.new(content: @content, options: { "resultLanguages" => [ "spa", "deu", "jpn" ] })
564
- response = RosetteAPI.new('0123456789').get_similar_terms(params)
565
- expect(response).instance_of? Hash
566
- end
567
- end
568
-
569
- describe '.get_semantic_vectors' do
570
- before do
571
- stub_request(:post, 'https://api.rosette.com/rest/v1/semantics/vector')
572
- .with(body: @json,
573
- headers: { 'Accept' => 'application/json',
574
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
575
- 'Content-Type' => 'application/json',
576
- 'User-Agent' => @user_agent,
577
- 'X-Rosetteapi-Key' => '0123456789',
578
- 'X-Rosetteapi-Binding' => 'ruby',
579
- 'X-Rosetteapi-Binding-Version' => '1.12.1' })
580
- .to_return(status: 200, body: '{"test": "language"}', headers: {})
581
- end
582
- it 'test semantic_vectors' do
583
- params = DocumentParameters.new
584
- params.content = @content
585
- response = RosetteAPI.new('0123456789').get_semantic_vectors(params)
586
- expect(response).instance_of? Hash
587
- end
588
- end
589
-
590
- describe '.get_syntax_dependencies' do
591
- before do
592
- stub_request(:post, 'https://api.rosette.com/rest/v1/syntax/dependencies')
593
- .with(body: @json,
594
- headers: { 'Accept' => 'application/json',
595
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
596
- 'Content-Type' => 'application/json',
597
- 'User-Agent' => @user_agent,
598
- 'X-Rosetteapi-Key' => '0123456789',
599
- 'X-Rosetteapi-Binding' => 'ruby',
600
- 'X-Rosetteapi-Binding-Version' => '1.12.1' })
601
- .to_return(status: 200, body: '{"test": "language"}', headers: {})
602
- end
603
- it 'test syntax_dependencies' do
604
- params = DocumentParameters.new
605
- params.content = @content
606
- response = RosetteAPI.new('0123456789').get_syntax_dependencies(params)
607
- expect(response).instance_of? Hash
608
- end
609
- end
610
-
611
- end