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.14.4'- LANGUAGE_ENDPOINT =
Rosette API language endpoint
'/language'- MORPHOLOGY_ENDPOINT =
Rosette API morphology endpoint
'/morphology'- ENTITIES_ENDPOINT =
Rosette API entities endpoint
'/entities'- CATEGORIES_ENDPOINT =
Rosette API categories endpoint
'/categories'- RELATIONSHIPS_ENDPOINT =
Rosette API relationships endpoint
'/relationships'- SENTIMENT_ENDPOINT =
Rosette API sentiment endpoint
'/sentiment'- NAME_DEDUPLICATION_ENDPOINT =
Name Deduplication endpoint
'/name-deduplication'- NAME_TRANSLATION_ENDPOINT =
Rosette API name-translation endpoint
'/name-translation'- NAME_SIMILARITY_ENDPOINT =
Rosette API name-similarity endpoint
'/name-similarity'- ADDRESS_SIMILARITY_ENDPOINT =
Rosette API address-similarity endpoint
'/address-similarity'- TOKENS_ENDPOINT =
Rosette API tokens endpoint
'/tokens'- SENTENCES_ENDPOINT =
Rosette API sentences endpoint
'/sentences'- INFO =
Rosette API info endpoint
'/info'- PING =
Rosette API ping endpoint
'/ping'- TEXT_EMBEDDING =
Text Embedding endpoint (deprecated)
'/text-embedding'- SEMANTIC_VECTORS =
Semantic Vectors endpoint (replaces /text-embedding)
'/semantics/vector'- SIMILAR_TERMS_ENDPOINT =
Similar Terms endpoint
'/semantics/similar'- SYNTACTIC_DEPENDENCIES_ENDPOINT =
Syntactic Dependencies endpoint
'/syntax/dependencies'- TRANSLITERATION_ENDPOINT =
Transliteration endpoint
'/transliteration'- TOPICS_ENDPOINT =
Topics endpoint
'/topics'
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_address_similarity(params) ⇒ Object
Compares two addresses and returns a match score from 0 to 1.
-
#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.
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rosette_api.rb', line 67 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
61 62 63 |
# File 'lib/rosette_api.rb', line 61 def alternate_url @alternate_url end |
#custom_headers ⇒ Object
custom Rosette API headers
63 64 65 |
# File 'lib/rosette_api.rb', line 63 def custom_headers @custom_headers end |
#url_parameters ⇒ Object
URL query parameter(s)
65 66 67 |
# File 'lib/rosette_api.rb', line 65 def url_parameters @url_parameters end |
#user_key ⇒ Object
Rosette API key
59 60 61 |
# File 'lib/rosette_api.rb', line 59 def user_key @user_key end |
Instance Method Details
#get_address_similarity(params) ⇒ Object
Compares two addresses and returns a match score from 0 to 1.
Attributes
-
params- AddressSimilarityParameters helps to build the request body in RequestBuilder.
Returns the confidence score of matching 2 addresses.
341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/rosette_api.rb', line 341 def get_address_similarity(params) check_params params, 'Expects a AddressSimilarityParameters type as an argument', AddressSimilarityParameters params = params.load_params RequestBuilder.new(@user_key, @alternate_url + ADDRESS_SIMILARITY_ENDPOINT, @http_client, BINDING_VERSION, params, @url_parameters) .send_post_request end |
#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.
226 227 228 229 230 231 232 233 234 |
# File 'lib/rosette_api.rb', line 226 def get_categories(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + CATEGORIES_ENDPOINT, @http_client, BINDING_VERSION, params, @url_parameters) .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.
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/rosette_api.rb', line 129 def get_compound_components(params) check_params params params = params.load_params endpoint = MORPHOLOGY_ENDPOINT + '/compound-components' RequestBuilder.new(@user_key, @alternate_url + endpoint, @http_client, BINDING_VERSION, params, @url_parameters) .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.
207 208 209 210 211 212 213 214 215 216 |
# File 'lib/rosette_api.rb', line 207 def get_entities(params) check_params params params = params.load_params endpoint = ENTITIES_ENDPOINT RequestBuilder.new(@user_key, @alternate_url + endpoint, @http_client, BINDING_VERSION, params, @url_parameters) .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.
149 150 151 152 153 154 155 156 157 158 |
# File 'lib/rosette_api.rb', line 149 def get_han_readings(params) check_params params params = params.load_params endpoint = MORPHOLOGY_ENDPOINT + '/han-readings' RequestBuilder.new(@user_key, @alternate_url + endpoint, @http_client, BINDING_VERSION, params, @url_parameters) .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.
89 90 91 92 93 94 95 96 97 |
# File 'lib/rosette_api.rb', line 89 def get_language(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + LANGUAGE_ENDPOINT, @http_client, BINDING_VERSION, params, @url_parameters) .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.
168 169 170 171 172 173 174 175 176 177 |
# File 'lib/rosette_api.rb', line 168 def get_lemmas(params) check_params params params = params.load_params endpoint = MORPHOLOGY_ENDPOINT + '/lemmas' RequestBuilder.new(@user_key, @alternate_url + endpoint, @http_client, BINDING_VERSION, params, @url_parameters) .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.
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/rosette_api.rb', line 109 def get_morphology_complete(params) check_params params params = params.load_params endpoint = MORPHOLOGY_ENDPOINT + '/complete' RequestBuilder.new(@user_key, @alternate_url + endpoint, @http_client, BINDING_VERSION, params, @url_parameters) .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.
280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/rosette_api.rb', line 280 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, BINDING_VERSION, params, @url_parameters) .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.
321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/rosette_api.rb', line 321 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, BINDING_VERSION, params, @url_parameters) .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.
300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/rosette_api.rb', line 300 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, BINDING_VERSION, params, @url_parameters) .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.
188 189 190 191 192 193 194 195 196 197 |
# File 'lib/rosette_api.rb', line 188 def get_parts_of_speech(params) check_params params params = params.load_params endpoint = MORPHOLOGY_ENDPOINT + '/parts-of-speech' RequestBuilder.new(@user_key, @alternate_url + endpoint, @http_client, BINDING_VERSION, params, @url_parameters) .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.
244 245 246 247 248 249 250 251 252 |
# File 'lib/rosette_api.rb', line 244 def get_relationships(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + RELATIONSHIPS_ENDPOINT, @http_client, BINDING_VERSION, params, @url_parameters) .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.
419 420 421 422 423 424 425 |
# File 'lib/rosette_api.rb', line 419 def get_semantic_vectors(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + SEMANTIC_VECTORS, @http_client, BINDING_VERSION, params, @url_parameters) .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.
379 380 381 382 383 384 385 386 387 |
# File 'lib/rosette_api.rb', line 379 def get_sentences(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + SENTENCES_ENDPOINT, @http_client, BINDING_VERSION, params, @url_parameters) .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.
262 263 264 265 266 267 268 269 270 |
# File 'lib/rosette_api.rb', line 262 def get_sentiment(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + SENTIMENT_ENDPOINT, @http_client, BINDING_VERSION, params, @url_parameters) .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
494 495 496 497 498 499 500 501 502 |
# File 'lib/rosette_api.rb', line 494 def get_similar_terms(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + SIMILAR_TERMS_ENDPOINT, @http_client, BINDING_VERSION, params, @url_parameters) .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.
436 437 438 439 440 441 442 443 444 445 |
# File 'lib/rosette_api.rb', line 436 def get_syntax_dependencies(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + SYNTACTIC_DEPENDENCIES_ENDPOINT, @http_client, BINDING_VERSION, params, @url_parameters) .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.
400 401 402 403 404 405 406 407 408 |
# File 'lib/rosette_api.rb', line 400 def (params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + TEXT_EMBEDDING, @http_client, BINDING_VERSION, params, @url_parameters) .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.
361 362 363 364 365 366 367 368 369 |
# File 'lib/rosette_api.rb', line 361 def get_tokens(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + TOKENS_ENDPOINT, @http_client, BINDING_VERSION, params, @url_parameters) .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.
476 477 478 479 480 481 482 483 484 |
# File 'lib/rosette_api.rb', line 476 def get_topics(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + TOPICS_ENDPOINT, @http_client, BINDING_VERSION, params, @url_parameters) .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.
456 457 458 459 460 461 462 463 464 465 466 |
# File 'lib/rosette_api.rb', line 456 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, BINDING_VERSION, params, @url_parameters) .send_post_request end |
#info ⇒ Object
Gets information about the Rosette API, returns name, build number and build time.
506 507 508 509 510 |
# File 'lib/rosette_api.rb', line 506 def info RequestBuilder.new(@user_key, @alternate_url + INFO, @http_client, BINDING_VERSION, @url_parameters) .send_get_request end |
#ping ⇒ Object
Pings the Rosette API for a response indicting that the service is available.
514 515 516 517 518 |
# File 'lib/rosette_api.rb', line 514 def ping RequestBuilder.new(@user_key, @alternate_url + PING, @http_client, BINDING_VERSION, @url_parameters) .send_get_request end |
#user_agent ⇒ Object
Gets the User-Agent string
521 522 523 524 |
# File 'lib/rosette_api.rb', line 521 def user_agent RequestBuilder.new(@user_key, @alternate_url + PING, @http_client, BINDING_VERSION, @url_parameters).user_agent end |