rosette_api 1.12.1 → 1.14.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +13 -0
- data/README.md +38 -0
- data/examples/README.md +36 -0
- data/examples/address_similarity.rb +35 -0
- data/examples/categories.rb +24 -0
- data/examples/entities.rb +31 -0
- data/examples/info.rb +20 -0
- data/examples/language.rb +23 -0
- data/examples/language_multilingual.rb +33 -0
- data/examples/morphology_complete.rb +23 -0
- data/examples/morphology_compound_components.rb +24 -0
- data/examples/morphology_han_readings.rb +22 -0
- data/examples/morphology_lemmas.rb +24 -0
- data/examples/morphology_parts_of_speech.rb +24 -0
- data/examples/name_deduplication.rb +27 -0
- data/examples/name_similarity.rb +28 -0
- data/examples/name_translation.rb +26 -0
- data/examples/ping.rb +20 -0
- data/examples/relationships.rb +31 -0
- data/examples/semantic_vectors.rb +22 -0
- data/examples/sentences.rb +28 -0
- data/examples/sentiment.rb +32 -0
- data/examples/similar_terms.rb +23 -0
- data/examples/syntax_dependencies.rb +25 -0
- data/examples/tokens.rb +22 -0
- data/examples/topics.rb +29 -0
- data/examples/transliteration.rb +25 -0
- data/lib/address_parameter.rb +117 -0
- data/lib/address_similarity_parameters.rb +49 -0
- data/lib/bad_request_error.rb +2 -0
- data/lib/bad_request_format_error.rb +2 -0
- data/lib/document_parameters.rb +20 -11
- data/lib/name_deduplication_parameters.rb +15 -7
- data/lib/name_parameter.rb +6 -3
- data/lib/name_similarity_parameters.rb +14 -6
- data/lib/name_translation_parameters.rb +12 -6
- data/lib/request_builder.rb +43 -18
- data/lib/rosette_api.rb +156 -71
- data/lib/rosette_api_error.rb +3 -1
- metadata +43 -13
- data/.rubocop.yml +0 -312
- data/tests/tests_spec.rb +0 -611
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rosette_api'
|
4
|
+
|
5
|
+
api_key, url = ARGV
|
6
|
+
|
7
|
+
rosette_api = if url
|
8
|
+
RosetteAPI.new(api_key, url)
|
9
|
+
else
|
10
|
+
RosetteAPI.new(api_key)
|
11
|
+
end
|
12
|
+
|
13
|
+
translated_name_data = 'معمر محمد أبو منيار القذاف'
|
14
|
+
begin
|
15
|
+
params = NameTranslationParameters.new(
|
16
|
+
translated_name_data,
|
17
|
+
'eng',
|
18
|
+
target_script: 'Latn'
|
19
|
+
)
|
20
|
+
response = rosette_api.get_name_translation(params)
|
21
|
+
puts JSON.pretty_generate(response)
|
22
|
+
rescue RosetteAPIError => e
|
23
|
+
printf('Rosette API Error (%<status_code>s): %<message>s',
|
24
|
+
status_code: e.status_code,
|
25
|
+
message: e.message)
|
26
|
+
end
|
data/examples/ping.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rosette_api'
|
4
|
+
|
5
|
+
api_key, url = ARGV
|
6
|
+
|
7
|
+
rosette_api = if url
|
8
|
+
RosetteAPI.new(api_key, url)
|
9
|
+
else
|
10
|
+
RosetteAPI.new(api_key)
|
11
|
+
end
|
12
|
+
|
13
|
+
begin
|
14
|
+
response = rosette_api.ping
|
15
|
+
puts JSON.pretty_generate(response)
|
16
|
+
rescue RosetteAPIError => e
|
17
|
+
printf('Rosette API Error (%<status_code>s): %<message>s',
|
18
|
+
status_code: e.status_code,
|
19
|
+
message: e.message)
|
20
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rosette_api'
|
4
|
+
|
5
|
+
api_key, url = ARGV
|
6
|
+
|
7
|
+
rosette_api = if url
|
8
|
+
RosetteAPI.new(api_key, url)
|
9
|
+
else
|
10
|
+
RosetteAPI.new(api_key)
|
11
|
+
end
|
12
|
+
|
13
|
+
relationships_text_data = 'FLIR Systems is headquartered in Oregon and ' \
|
14
|
+
'produces thermal imaging, night vision, and infrared cameras and sensor ' \
|
15
|
+
'systems. According to the SEC\'s order instituting a settled ' \
|
16
|
+
'administrative proceeding, FLIR entered into a multi-million dollar ' \
|
17
|
+
'contract to provide thermal binoculars to the Saudi government in ' \
|
18
|
+
'November 2008. Timms and Ramahi were the primary sales employees ' \
|
19
|
+
'responsible for the contract, and also were involved in negotiations to ' \
|
20
|
+
'sell FLIR\'s security cameras to the same government officials. At the ' \
|
21
|
+
'time, Timms was the head of FLIR\'s Middle East office in Dubai.'
|
22
|
+
|
23
|
+
begin
|
24
|
+
params = DocumentParameters.new(content: relationships_text_data)
|
25
|
+
response = rosette_api.get_relationships(params)
|
26
|
+
puts JSON.pretty_generate(response)
|
27
|
+
rescue RosetteAPIError => e
|
28
|
+
printf('Rosette API Error (%<status_code>s): %<message>s',
|
29
|
+
status_code: e.status_code,
|
30
|
+
message: e.message)
|
31
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rosette_api'
|
4
|
+
|
5
|
+
api_key, url = ARGV
|
6
|
+
|
7
|
+
rosette_api = if url
|
8
|
+
RosetteAPI.new(api_key, url)
|
9
|
+
else
|
10
|
+
RosetteAPI.new(api_key)
|
11
|
+
end
|
12
|
+
|
13
|
+
semantic_vectors_data = 'Cambridge, Massachusetts'
|
14
|
+
begin
|
15
|
+
params = DocumentParameters.new(content: semantic_vectors_data)
|
16
|
+
response = rosette_api.get_semantic_vectors(params)
|
17
|
+
puts JSON.pretty_generate(response)
|
18
|
+
rescue RosetteAPIError => e
|
19
|
+
printf('Rosette API Error (%<status_code>s): %<message>s',
|
20
|
+
status_code: e.status_code,
|
21
|
+
message: e.message)
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rosette_api'
|
4
|
+
|
5
|
+
api_key, url = ARGV
|
6
|
+
|
7
|
+
rosette_api = if url
|
8
|
+
RosetteAPI.new(api_key, url)
|
9
|
+
else
|
10
|
+
RosetteAPI.new(api_key)
|
11
|
+
end
|
12
|
+
|
13
|
+
sentences_data = 'This land is your land. This land is my land, from ' \
|
14
|
+
'California to the New York island; from the red wood forest to the Gulf ' \
|
15
|
+
'Stream waters. This land was made for you and Me. As I was walking that ' \
|
16
|
+
'ribbon of highway, I saw above me that endless skyway: I saw below me ' \
|
17
|
+
'that golden valley: This land was made for you and me.'
|
18
|
+
|
19
|
+
begin
|
20
|
+
params = DocumentParameters.new
|
21
|
+
params.content = sentences_data
|
22
|
+
response = rosette_api.get_sentences(params)
|
23
|
+
puts JSON.pretty_generate(response)
|
24
|
+
rescue RosetteAPIError => e
|
25
|
+
printf('Rosette API Error (%<status_code>s): %<message>s',
|
26
|
+
status_code: e.status_code,
|
27
|
+
message: e.message)
|
28
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
require 'rosette_api'
|
5
|
+
|
6
|
+
api_key, url = ARGV
|
7
|
+
|
8
|
+
rosette_api = if url
|
9
|
+
RosetteAPI.new(api_key, url)
|
10
|
+
else
|
11
|
+
RosetteAPI.new(api_key)
|
12
|
+
end
|
13
|
+
|
14
|
+
file = Tempfile.new(%w[foo .html])
|
15
|
+
sentiment_file_data =
|
16
|
+
'<html><head><title>New Ghostbusters Film</title></head><body><p>Original ' \
|
17
|
+
'Ghostbuster Dan Aykroyd, who also co-wrote the 1984 Ghostbusters film, ' \
|
18
|
+
'couldn\'t be more pleased with the new all-female Ghostbusters cast, ' \
|
19
|
+
'telling The Hollywood Reporter, "The Aykroyd family is delighted by this ' \
|
20
|
+
'inheritance of the Ghostbusters torch by these most magnificent women in ' \
|
21
|
+
'comedy."</p></body></html>'
|
22
|
+
file.write(sentiment_file_data)
|
23
|
+
file.close
|
24
|
+
begin
|
25
|
+
params = DocumentParameters.new(file_path: file.path, language: 'eng')
|
26
|
+
response = rosette_api.get_sentiment(params)
|
27
|
+
puts JSON.pretty_generate(response)
|
28
|
+
rescue RosetteAPIError => e
|
29
|
+
printf('Rosette API Error (%<status_code>s): %<message>s',
|
30
|
+
status_code: e.status_code,
|
31
|
+
message: e.message)
|
32
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rosette_api'
|
4
|
+
|
5
|
+
api_key, url = ARGV
|
6
|
+
|
7
|
+
rosette_api = if url
|
8
|
+
RosetteAPI.new(api_key, url)
|
9
|
+
else
|
10
|
+
RosetteAPI.new(api_key)
|
11
|
+
end
|
12
|
+
|
13
|
+
similar_terms_data = 'spy'
|
14
|
+
begin
|
15
|
+
params = DocumentParameters.new(content: similar_terms_data)
|
16
|
+
params.rosette_options = { 'resultLanguages' => %w[spa deu jpn] }
|
17
|
+
response = rosette_api.get_similar_terms(params)
|
18
|
+
puts JSON.pretty_generate(response)
|
19
|
+
rescue RosetteAPIError => e
|
20
|
+
printf('Rosette API Error (%<status_code>s): %<message>s',
|
21
|
+
status_code: e.status_code,
|
22
|
+
message: e.message)
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rosette_api'
|
4
|
+
|
5
|
+
api_key, url = ARGV
|
6
|
+
|
7
|
+
rosette_api = if url
|
8
|
+
RosetteAPI.new(api_key, url)
|
9
|
+
else
|
10
|
+
RosetteAPI.new(api_key)
|
11
|
+
end
|
12
|
+
|
13
|
+
syntax_dependencies_data =
|
14
|
+
'Yoshinori Ohsumi, a Japanese cell biologist, was awarded the Nobel Prize ' \
|
15
|
+
'in Physiology or Medicine on Monday.'
|
16
|
+
|
17
|
+
begin
|
18
|
+
params = DocumentParameters.new(content: syntax_dependencies_data)
|
19
|
+
response = rosette_api.get_syntax_dependencies(params)
|
20
|
+
puts JSON.pretty_generate(response)
|
21
|
+
rescue RosetteAPIError => e
|
22
|
+
printf('Rosette API Error (%<status_code>s): %<message>s',
|
23
|
+
status_code: e.status_code,
|
24
|
+
message: e.message)
|
25
|
+
end
|
data/examples/tokens.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rosette_api'
|
4
|
+
|
5
|
+
api_key, url = ARGV
|
6
|
+
|
7
|
+
rosette_api = if url
|
8
|
+
RosetteAPI.new(api_key, url)
|
9
|
+
else
|
10
|
+
RosetteAPI.new(api_key)
|
11
|
+
end
|
12
|
+
|
13
|
+
tokens_data = '北京大学生物系主任办公室内部会议'
|
14
|
+
begin
|
15
|
+
params = DocumentParameters.new(content: tokens_data)
|
16
|
+
response = rosette_api.get_tokens(params)
|
17
|
+
puts JSON.pretty_generate(response)
|
18
|
+
rescue RosetteAPIError => e
|
19
|
+
printf('Rosette API Error (%<status_code>s): %<message>s',
|
20
|
+
status_code: e.status_code,
|
21
|
+
message: e.message)
|
22
|
+
end
|
data/examples/topics.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rosette_api'
|
4
|
+
|
5
|
+
api_key, url = ARGV
|
6
|
+
|
7
|
+
rosette_api = if url
|
8
|
+
RosetteAPI.new(api_key, url)
|
9
|
+
else
|
10
|
+
RosetteAPI.new(api_key)
|
11
|
+
end
|
12
|
+
|
13
|
+
topics_data =
|
14
|
+
'Lily Collins is in talks to join Nicholas Hoult in Chernin Entertainment ' \
|
15
|
+
"and Fox Searchlight's J.R.R. Tolkien biopic Tolkien. Anthony Boyle, known " \
|
16
|
+
'for playing Scorpius Malfoy in the British play Harry Potter and the ' \
|
17
|
+
'Cursed Child, also has signed on for the film centered on the famed ' \
|
18
|
+
'author. In Tolkien, Hoult will play the author of the Hobbit and Lord of ' \
|
19
|
+
'the Rings book series that were later adapted into two Hollywood ' \
|
20
|
+
'trilogies from Peter Jackson. Dome Karukoski is directing the project.'
|
21
|
+
begin
|
22
|
+
params = DocumentParameters.new(content: topics_data)
|
23
|
+
response = rosette_api.get_topics(params)
|
24
|
+
puts JSON.pretty_generate(response)
|
25
|
+
rescue RosetteAPIError => e
|
26
|
+
printf('Rosette API Error (%<status_code>s): %<message>s',
|
27
|
+
status_code: e.status_code,
|
28
|
+
message: e.message)
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rosette_api'
|
4
|
+
|
5
|
+
api_key, url = ARGV
|
6
|
+
|
7
|
+
rosette_api = if url
|
8
|
+
RosetteAPI.new(api_key, url)
|
9
|
+
else
|
10
|
+
RosetteAPI.new(api_key)
|
11
|
+
end
|
12
|
+
|
13
|
+
transliteration_content_data =
|
14
|
+
'Kareem Abdul Jabbar holds the records for most points in the NBA'
|
15
|
+
|
16
|
+
begin
|
17
|
+
params = DocumentParameters.new
|
18
|
+
params.content = transliteration_content_data
|
19
|
+
response = rosette_api.get_transliteration(params)
|
20
|
+
puts JSON.pretty_generate(response)
|
21
|
+
rescue RosetteAPIError => e
|
22
|
+
printf('Rosette API Error (%<status_code>s): %<message>s',
|
23
|
+
status_code: e.status_code,
|
24
|
+
message: e.message)
|
25
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This class represents an address in Rosette API.
|
4
|
+
class AddressParameter
|
5
|
+
# house (optional)
|
6
|
+
attr_accessor :house
|
7
|
+
# house_number (optional)
|
8
|
+
attr_accessor :house_number
|
9
|
+
# road (optional)
|
10
|
+
attr_accessor :road
|
11
|
+
# unit (optional)
|
12
|
+
attr_accessor :unit
|
13
|
+
# level (optional)
|
14
|
+
attr_accessor :level
|
15
|
+
# staircase (optional)
|
16
|
+
attr_accessor :staircase
|
17
|
+
# entrance (optional)
|
18
|
+
attr_accessor :entrance
|
19
|
+
# suburb (optional)
|
20
|
+
attr_accessor :suburb
|
21
|
+
# city_district (optional)
|
22
|
+
attr_accessor :city_district
|
23
|
+
# city (optional)
|
24
|
+
attr_accessor :city
|
25
|
+
# island (optional)
|
26
|
+
attr_accessor :island
|
27
|
+
# state_district (optional)
|
28
|
+
attr_accessor :state_district
|
29
|
+
# state (optional)
|
30
|
+
attr_accessor :state
|
31
|
+
# country_region (optional)
|
32
|
+
attr_accessor :country_region
|
33
|
+
# country (optional)
|
34
|
+
attr_accessor :country
|
35
|
+
# world_region (optional)
|
36
|
+
attr_accessor :world_region
|
37
|
+
# post_code (optional)
|
38
|
+
attr_accessor :post_code
|
39
|
+
# po_box (optional)
|
40
|
+
attr_accessor :po_box
|
41
|
+
|
42
|
+
def initialize(options = {}) #:notnew:
|
43
|
+
options = {
|
44
|
+
house: nil,
|
45
|
+
house_number: nil,
|
46
|
+
road: nil,
|
47
|
+
unit: nil,
|
48
|
+
level: nil,
|
49
|
+
staircase: nil,
|
50
|
+
entrance: nil,
|
51
|
+
suburb: nil,
|
52
|
+
city_district: nil,
|
53
|
+
city: nil,
|
54
|
+
island: nil,
|
55
|
+
state_district: nil,
|
56
|
+
state: nil,
|
57
|
+
country_region: nil,
|
58
|
+
country: nil,
|
59
|
+
world_region: nil,
|
60
|
+
post_code: nil,
|
61
|
+
po_box: nil
|
62
|
+
}.update options
|
63
|
+
@house = options[:house]
|
64
|
+
@house_number = options[:house_number]
|
65
|
+
@road = options[:road]
|
66
|
+
@unit = options[:unit]
|
67
|
+
@level = options[:level]
|
68
|
+
@staircase = options[:staircase]
|
69
|
+
@entrance = options[:entrance]
|
70
|
+
@suburb = options[:suburb]
|
71
|
+
@city_district = options[:city_district]
|
72
|
+
@city = options[:city]
|
73
|
+
@island = options[:island]
|
74
|
+
@state_district = options[:state_district]
|
75
|
+
@state = options[:state]
|
76
|
+
@country_region = options[:country_region]
|
77
|
+
@country = options[:country]
|
78
|
+
@world_region = options[:world_region]
|
79
|
+
@post_code = options[:post_code]
|
80
|
+
@po_box = options[:po_box]
|
81
|
+
end
|
82
|
+
|
83
|
+
# Converts this class to Hash with its keys in lower CamelCase.
|
84
|
+
#
|
85
|
+
# Returns the new Hash.
|
86
|
+
def load_param
|
87
|
+
to_hash.select { |_key, value| value }
|
88
|
+
.map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] }
|
89
|
+
.to_h
|
90
|
+
end
|
91
|
+
|
92
|
+
# Converts this class to Hash.
|
93
|
+
#
|
94
|
+
# Returns the new Hash.
|
95
|
+
def to_hash
|
96
|
+
{
|
97
|
+
house: @house,
|
98
|
+
house_number: @house_number,
|
99
|
+
road: @road,
|
100
|
+
unit: @unit,
|
101
|
+
level: @level,
|
102
|
+
staircase: @staircase,
|
103
|
+
entrance: @entrance,
|
104
|
+
suburb: @suburb,
|
105
|
+
city_district: @city_district,
|
106
|
+
city: @city,
|
107
|
+
island: @island,
|
108
|
+
state_district: @state_district,
|
109
|
+
state: @state,
|
110
|
+
country_region: @country_region,
|
111
|
+
country: @country,
|
112
|
+
world_region: @world_region,
|
113
|
+
post_code: @post_code,
|
114
|
+
po_box: @po_box
|
115
|
+
}
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'bad_request_error'
|
4
|
+
require_relative 'address_parameter'
|
5
|
+
|
6
|
+
# This class encapsulates parameters that are needed for address-similarity in
|
7
|
+
# Rosette API.
|
8
|
+
class AddressSimilarityParameters
|
9
|
+
# Address to be compared to address2
|
10
|
+
attr_accessor :address1
|
11
|
+
# Address to be compared to address1
|
12
|
+
attr_accessor :address2
|
13
|
+
|
14
|
+
def initialize(address1, address2) #:notnew:
|
15
|
+
@address1 = address1
|
16
|
+
@address2 = address2
|
17
|
+
end
|
18
|
+
|
19
|
+
# Validates the parameters by checking if address1 and address2 are instances
|
20
|
+
# of AddressParameter.
|
21
|
+
def validate_params
|
22
|
+
a1_msg = 'address1 option can only be an instance of an AddressParameter'
|
23
|
+
raise BadRequestError.new(a1_msg) if [AddressParameter].none? { |clazz| @address1.is_a? clazz }
|
24
|
+
|
25
|
+
a2_msg = 'address2 option can only be an instance of an AddressParameter'
|
26
|
+
raise BadRequestError.new(a2_msg) if [AddressParameter].none? { |clazz| @address2.is_a? clazz }
|
27
|
+
end
|
28
|
+
|
29
|
+
# Converts this class to Hash with its keys in lower CamelCase.
|
30
|
+
#
|
31
|
+
# Returns the new Hash.
|
32
|
+
def load_params
|
33
|
+
validate_params
|
34
|
+
to_hash
|
35
|
+
.reject { |_key, value| value.nil? }
|
36
|
+
.map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] }
|
37
|
+
.to_h
|
38
|
+
end
|
39
|
+
|
40
|
+
# Converts this class to Hash.
|
41
|
+
#
|
42
|
+
# Returns the new Hash.
|
43
|
+
def to_hash
|
44
|
+
{
|
45
|
+
address1: @address1.is_a?(AddressParameter) ? @address1.load_param : @address1,
|
46
|
+
address2: @address2.is_a?(AddressParameter) ? @address2.load_param : @address2
|
47
|
+
}
|
48
|
+
end
|
49
|
+
end
|