Class: RosetteAPI
- Inherits:
-
Object
- Object
- RosetteAPI
- Defined in:
- lib/rosette_api.rb
Overview
This class allows you to access all Rosette API endpoints.
Constant Summary collapse
- BINDING_VERSION =
Version of Ruby binding
'1.12.1'- LANGUAGE_ENDPOINT =
Rosette API language endpoint
'/language'.freeze
- MORPHOLOGY_ENDPOINT =
Rosette API morphology endpoint
'/morphology'.freeze
- ENTITIES_ENDPOINT =
Rosette API entities endpoint
'/entities'.freeze
- CATEGORIES_ENDPOINT =
Rosette API categories endpoint
'/categories'.freeze
- RELATIONSHIPS_ENDPOINT =
Rosette API relationships endpoint
'/relationships'.freeze
- SENTIMENT_ENDPOINT =
Rosette API sentiment endpoint
'/sentiment'.freeze
- NAME_DEDUPLICATION_ENDPOINT =
Name Deduplication endpoint
'/name-deduplication'.freeze
- NAME_TRANSLATION_ENDPOINT =
Rosette API name-translation endpoint
'/name-translation'.freeze
- NAME_SIMILARITY_ENDPOINT =
Rosette API name-similarity endpoint
'/name-similarity'.freeze
- TOKENS_ENDPOINT =
Rosette API tokens endpoint
'/tokens'.freeze
- SENTENCES_ENDPOINT =
Rosette API sentences endpoint
'/sentences'.freeze
- INFO =
Rosette API info endpoint
'/info'.freeze
- PING =
Rosette API ping endpoint
'/ping'.freeze
- TEXT_EMBEDDING =
Text Embedding endpoint (deprecated)
'/text-embedding'.freeze
- SEMANTIC_VECTORS =
Semantic Vectors endpoint (replaces /text-embedding)
'/semantics/vector'.freeze
- SIMILAR_TERMS_ENDPOINT =
Similar Terms endpoint
'/semantics/similar'.freeze
- SYNTACTIC_DEPENDENCIES_ENDPOINT =
Syntactic Dependencies endpoint
'/syntax/dependencies'.freeze
- TRANSLITERATION_ENDPOINT =
Transliteration endpoint
'/transliteration'.freeze
- TOPICS_ENDPOINT =
Topics endpoint
'/topics'.freeze
Instance Attribute Summary collapse
-
#alternate_url ⇒ Object
Alternate Rosette API URL.
-
#custom_headers ⇒ Object
custom Rosette API headers.
-
#url_parameters ⇒ Object
URL query parameter(s).
-
#user_key ⇒ Object
Rosette API key.
Instance Method Summary collapse
-
#get_categories(params) ⇒ Object
Extracts Tier 1 contextual categories from the input.
-
#get_compound_components(params) ⇒ Object
Extracts compound-components from the input.
-
#get_entities(params) ⇒ Object
Extracts entities from the input.
-
#get_han_readings(params) ⇒ Object
Extracts Han-readings from the input.
-
#get_language(params) ⇒ Object
Identifies in which language(s) the input is written.
-
#get_lemmas(params) ⇒ Object
Extracts lemmas from the input.
-
#get_morphology_complete(params) ⇒ Object
Extracts parts-of-speech, lemmas (dictionary form), compound components, and Han-readings for each token in the input.
-
#get_name_deduplication(params) ⇒ Object
De-duplicates a list of names.
-
#get_name_similarity(params) ⇒ Object
Compares two entity names (person, location, or organization) and returns a match score from 0 to 1.
-
#get_name_translation(params) ⇒ Object
Translates a given name to a supported specified language.
-
#get_parts_of_speech(params) ⇒ Object
Extracts parts-of-speech from the input.
-
#get_relationships(params) ⇒ Object
Extracts relationships from the input.
-
#get_semantic_vectors(params) ⇒ Object
Returns the vectors associated with the text.
-
#get_sentences(params) ⇒ Object
Divides the input into sentences.
-
#get_sentiment(params) ⇒ Object
Analyzes the positive and negative sentiment expressed by the input.
-
#get_similar_terms(params) ⇒ Object
Returns the terms similar to the input.
-
#get_syntax_dependencies(params) ⇒ Object
Returns the syntactic structure of the text.
-
#get_text_embedding(params) ⇒ Object
Returns the vectors associated with the text.
-
#get_tokens(params) ⇒ Object
Divides the input into tokens.
-
#get_topics(params) ⇒ Object
Divides the input into topics (key phrases and concepts).
-
#get_transliteration(params) ⇒ Object
Returns the transliteration of the content.
-
#info ⇒ Object
Gets information about the Rosette API, returns name, build number and build time.
-
#initialize(user_key, alternate_url = 'https://api.rosette.com/rest/v1') ⇒ RosetteAPI
constructor
A new instance of RosetteAPI.
-
#ping ⇒ Object
Pings the Rosette API for a response indicting that the service is available.
-
#user_agent ⇒ Object
Gets the User-Agent string.
Constructor Details
#initialize(user_key, alternate_url = 'https://api.rosette.com/rest/v1') ⇒ RosetteAPI
Returns a new instance of RosetteAPI.
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rosette_api.rb', line 63 def initialize(user_key, alternate_url = 'https://api.rosette.com/rest/v1') @user_key = user_key @alternate_url = alternate_url @url_parameters = nil if @alternate_url.to_s.end_with?('/') @alternate_url = alternate_url.to_s.slice(0..-2) end uri = URI.parse alternate_url @http_client = Net::HTTP.new uri.host, uri.port @http_client.use_ssl = uri.scheme == 'https' end |
Instance Attribute Details
#alternate_url ⇒ Object
Alternate Rosette API URL
57 58 59 |
# File 'lib/rosette_api.rb', line 57 def alternate_url @alternate_url end |
#custom_headers ⇒ Object
custom Rosette API headers
59 60 61 |
# File 'lib/rosette_api.rb', line 59 def custom_headers @custom_headers end |
#url_parameters ⇒ Object
URL query parameter(s)
61 62 63 |
# File 'lib/rosette_api.rb', line 61 def url_parameters @url_parameters end |
#user_key ⇒ Object
Rosette API key
55 56 57 |
# File 'lib/rosette_api.rb', line 55 def user_key @user_key end |
Instance Method Details
#get_categories(params) ⇒ Object
Extracts Tier 1 contextual categories from the input.
Attributes
params- DocumentParameters helps to build the request body in RequestBuilder.
Returns the contextual categories identified in the input.
202 203 204 205 206 207 208 209 |
# File 'lib/rosette_api.rb', line 202 def get_categories(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + CATEGORIES_ENDPOINT, @http_client, params, @url_parameters, BINDING_VERSION) .send_post_request end |
#get_compound_components(params) ⇒ Object
Extracts compound-components from the input.
Attributes
params- DocumentParameters helps to build the request body in RequestBuilder.
Returns list of components for each compound word of the input for supported languages.
119 120 121 122 123 124 125 126 |
# File 'lib/rosette_api.rb', line 119 def get_compound_components(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/compound-components', @http_client, params, @url_parameters, BINDING_VERSION) .send_post_request end |
#get_entities(params) ⇒ Object
Extracts entities from the input.
Attributes
params- DocumentParameters helps to build the request body in RequestBuilder.
Returns each entity extracted from the input.
185 186 187 188 189 190 191 192 193 |
# File 'lib/rosette_api.rb', line 185 def get_entities(params) check_params params params = params.load_params endpoint = ENTITIES_ENDPOINT RequestBuilder.new(@user_key, @alternate_url + endpoint, @http_client, params, @url_parameters, BINDING_VERSION) .send_post_request end |
#get_han_readings(params) ⇒ Object
Extracts Han-readings from the input.
Attributes
params- DocumentParameters helps to build the request body in RequestBuilder.
Returns list of Han-readings which provide pronunciation information for Han script, in both Chinese and Japanese input text.
136 137 138 139 140 141 142 143 |
# File 'lib/rosette_api.rb', line 136 def get_han_readings(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/han-readings', @http_client, params, @url_parameters, BINDING_VERSION) .send_post_request end |
#get_language(params) ⇒ Object
Identifies in which language(s) the input is written.
Attributes
params- DocumentParameters helps to build the request body in RequestBuilder.
Returns list of candidate languages in order of descending confidence.
84 85 86 87 88 89 90 91 |
# File 'lib/rosette_api.rb', line 84 def get_language(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + LANGUAGE_ENDPOINT, @http_client, params, @url_parameters, BINDING_VERSION) .send_post_request end |
#get_lemmas(params) ⇒ Object
Extracts lemmas from the input.
Attributes
params- DocumentParameters helps to build the request body in RequestBuilder.
Returns list of lemmas for each token of the input for supported languages.
152 153 154 155 156 157 158 159 |
# File 'lib/rosette_api.rb', line 152 def get_lemmas(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/lemmas', @http_client, params, @url_parameters, BINDING_VERSION) .send_post_request end |
#get_morphology_complete(params) ⇒ Object
Extracts parts-of-speech, lemmas (dictionary form), compound components, and Han-readings for each token in the input.
Attributes
params- DocumentParameters helps to build the request body in RequestBuilder.
Returns the lemmas, compound components, Han-readings, and parts-of-speech tags of the input for supported languages.
102 103 104 105 106 107 108 109 |
# File 'lib/rosette_api.rb', line 102 def get_morphology_complete(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/complete', @http_client, params, @url_parameters, BINDING_VERSION) .send_post_request end |
#get_name_deduplication(params) ⇒ Object
De-duplicates a list of names.
Attributes
params- NameDeduplicationParameters helps to build the request body in RequestBuilder.
Returns the list of deduplicated names.
250 251 252 253 254 255 256 257 |
# File 'lib/rosette_api.rb', line 250 def get_name_deduplication(params) check_params params, 'Expects a NameDeduplicationParameters type as an argument', NameDeduplicationParameters params = params.load_params RequestBuilder.new(@user_key, @alternate_url + NAME_DEDUPLICATION_ENDPOINT, @http_client, params, @url_parameters, BINDING_VERSION) .send_post_request end |
#get_name_similarity(params) ⇒ Object
Compares two entity names (person, location, or organization) and returns a match score from 0 to 1.
Attributes
params- NameSimilarityParameters helps to build the request body in RequestBuilder.
Returns the confidence score of matching 2 names.
283 284 285 286 287 288 289 290 |
# File 'lib/rosette_api.rb', line 283 def get_name_similarity(params) check_params params, 'Expects a NameSimilarityParameters type as an argument', NameSimilarityParameters params = params.load_params RequestBuilder.new(@user_key, @alternate_url + NAME_SIMILARITY_ENDPOINT, @http_client, params, @url_parameters, BINDING_VERSION) .send_post_request end |
#get_name_translation(params) ⇒ Object
Translates a given name to a supported specified language.
Attributes
params- NameTranslationParameters helps to build the request body in RequestBuilder.
Returns the translation of a name.
266 267 268 269 270 271 272 273 |
# File 'lib/rosette_api.rb', line 266 def get_name_translation(params) check_params params, 'Expects a NameTranslationParameters type as an argument', NameTranslationParameters params = params.load_params RequestBuilder.new(@user_key, @alternate_url + NAME_TRANSLATION_ENDPOINT, @http_client, params, @url_parameters, BINDING_VERSION) .send_post_request end |
#get_parts_of_speech(params) ⇒ Object
Extracts parts-of-speech from the input.
Attributes
params- DocumentParameters helps to build the request body in RequestBuilder.
Returns list of part-of-speech (POS) tags for each of the words of the input, depending on the context of how it is used.
169 170 171 172 173 174 175 176 |
# File 'lib/rosette_api.rb', line 169 def get_parts_of_speech(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + MORPHOLOGY_ENDPOINT + '/parts-of-speech', @http_client, params, @url_parameters, BINDING_VERSION) .send_post_request end |
#get_relationships(params) ⇒ Object
Extracts relationships from the input.
Attributes
params- DocumentParameters helps to build the request body in RequestBuilder.
Returns each relationship extracted from the input.
218 219 220 221 222 223 224 225 |
# File 'lib/rosette_api.rb', line 218 def get_relationships(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + RELATIONSHIPS_ENDPOINT, @http_client, params, @url_parameters, BINDING_VERSION) .send_post_request end |
#get_semantic_vectors(params) ⇒ Object
Returns the vectors associated with the text
Attributes
params- DocumentParameters helps to build the request body in RequestBuilder.
Returns the text embedding representation of the input.
351 352 353 354 355 356 |
# File 'lib/rosette_api.rb', line 351 def get_semantic_vectors(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + SEMANTIC_VECTORS, @http_client, params, @url_parameters, BINDING_VERSION) .send_post_request end |
#get_sentences(params) ⇒ Object
Divides the input into sentences.
Attributes
params- DocumentParameters helps to build the request body in RequestBuilder.
Returns list of linguistic sentences of the input.
315 316 317 318 319 320 321 322 |
# File 'lib/rosette_api.rb', line 315 def get_sentences(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + SENTENCES_ENDPOINT, @http_client, params, @url_parameters, BINDING_VERSION) .send_post_request end |
#get_sentiment(params) ⇒ Object
Analyzes the positive and negative sentiment expressed by the input.
Attributes
params- DocumentParameters helps to build the request body in RequestBuilder.
Returns sentiment analysis results.
234 235 236 237 238 239 240 241 |
# File 'lib/rosette_api.rb', line 234 def get_sentiment(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + SENTIMENT_ENDPOINT, @http_client, params, @url_parameters, BINDING_VERSION) .send_post_request end |
#get_similar_terms(params) ⇒ Object
Returns the terms similar to the input
Attributes
params- DocumentParameters helps to build the request body in RequestBuilder.
Returns a mapping of languageCode to similar terms
415 416 417 418 419 420 421 422 |
# File 'lib/rosette_api.rb', line 415 def get_similar_terms(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + SIMILAR_TERMS_ENDPOINT, @http_client, params, @url_parameters, BINDING_VERSION) .send_post_request end |
#get_syntax_dependencies(params) ⇒ Object
Returns the syntactic structure of the text
Attributes
params- DocumentParameters helps to build the request body in RequestBuilder.
Returns list of linguistic sentences of the input.
366 367 368 369 370 371 372 373 |
# File 'lib/rosette_api.rb', line 366 def get_syntax_dependencies(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + SYNTACTIC_DEPENDENCIES_ENDPOINT, @http_client, params, @url_parameters, BINDING_VERSION) .send_post_request end |
#get_text_embedding(params) ⇒ Object
Returns the vectors associated with the text
Deprecated. Please use get_semantic_vectors instead
Attributes
params- DocumentParameters helps to build the request body in RequestBuilder.
Returns the text embedding representation of the input.
334 335 336 337 338 339 340 341 |
# File 'lib/rosette_api.rb', line 334 def (params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + TEXT_EMBEDDING, @http_client, params, @url_parameters, BINDING_VERSION) .send_post_request end |
#get_tokens(params) ⇒ Object
Divides the input into tokens.
Attributes
params- DocumentParameters helps to build the request body in RequestBuilder.
Returns list of tokens of the input.
299 300 301 302 303 304 305 306 |
# File 'lib/rosette_api.rb', line 299 def get_tokens(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + TOKENS_ENDPOINT, @http_client, params, @url_parameters, BINDING_VERSION) .send_post_request end |
#get_topics(params) ⇒ Object
Divides the input into topics (key phrases and concepts).
Attributes
params- DocumentParameters helps to build the request body in RequestBuilder.
Returns list of topics of the input.
399 400 401 402 403 404 405 406 |
# File 'lib/rosette_api.rb', line 399 def get_topics(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + TOPICS_ENDPOINT, @http_client, params, @url_parameters, BINDING_VERSION) .send_post_request end |
#get_transliteration(params) ⇒ Object
Returns the transliteration of the content
Attributes
params- DocumentParameters helps to build the request body in RequestBuilder.
Returns the transliteration of the input.
383 384 385 386 387 388 389 390 |
# File 'lib/rosette_api.rb', line 383 def get_transliteration(params) check_params params, 'Expects a DocumentParameters type as an argument', DocumentParameters params = params.load_params RequestBuilder.new(@user_key, @alternate_url + TRANSLITERATION_ENDPOINT, @http_client, params, @url_parameters, BINDING_VERSION) .send_post_request end |
#info ⇒ Object
Gets information about the Rosette API, returns name, build number and build time.
426 427 428 429 |
# File 'lib/rosette_api.rb', line 426 def info RequestBuilder.new(@user_key, @alternate_url + INFO, @http_client, @url_parameters, BINDING_VERSION) .send_get_request end |
#ping ⇒ Object
Pings the Rosette API for a response indicting that the service is available.
433 434 435 436 |
# File 'lib/rosette_api.rb', line 433 def ping RequestBuilder.new(@user_key, @alternate_url + PING, @http_client, @url_parameters, BINDING_VERSION) .send_get_request end |
#user_agent ⇒ Object
Gets the User-Agent string
439 440 441 |
# File 'lib/rosette_api.rb', line 439 def user_agent RequestBuilder.new(@user_key, @alternate_url + PING, @http_client, @url_parameters, BINDING_VERSION).user_agent end |