Class: RosetteAPI
- Inherits:
-
Object
- Object
- RosetteAPI
- Defined in:
- lib/rosette_api.rb
Overview
This class allows you to access all Analytics API endpoints.
Constant Summary collapse
- BINDING_VERSION =
Version of Ruby binding
'1.37.0'- ADDRESS_SIMILARITY_ENDPOINT =
API address-similarity endpoint
'/address-similarity'- CATEGORIES_ENDPOINT =
API categories endpoint
'/categories'- ENTITIES_ENDPOINT =
API entities endpoint
'/entities'- EVENTS_ENDPOINT =
API events endpoint
'/events'- INFO =
API info endpoint
'/info'- LANGUAGE_ENDPOINT =
API language endpoint
'/language'- MORPHOLOGY_ENDPOINT =
API morphology endpoint
'/morphology'- NAME_DEDUPLICATION_ENDPOINT =
Name Deduplication endpoint
'/name-deduplication'- NAME_SIMILARITY_ENDPOINT =
API name-similarity endpoint
'/name-similarity'- NAME_TRANSLATION_ENDPOINT =
API name-translation endpoint
'/name-translation'- PING =
API ping endpoint
'/ping'- RECORD_SIMILARITY_ENDPOINT =
Record Similarity endpoint
'/record-similarity'- RELATIONSHIPS_ENDPOINT =
API relationships endpoint
'/relationships'- SEMANTIC_VECTORS =
Semantic Vectors endpoint (replaces deprecated /text-embedding)
'/semantics/vector'- SENTENCES_ENDPOINT =
API sentences endpoint
'/sentences'- SENTIMENT_ENDPOINT =
API sentiment endpoint
'/sentiment'- SIMILAR_TERMS_ENDPOINT =
Similar Terms endpoint
'/semantics/similar'- SYNTACTIC_DEPENDENCIES_ENDPOINT =
Syntactic Dependencies endpoint
'/syntax/dependencies'- TOKENS_ENDPOINT =
API tokens endpoint
'/tokens'- TOPICS_ENDPOINT =
Topics endpoint
'/topics'- TRANSLITERATION_ENDPOINT =
Transliteration endpoint
'/transliteration'
Instance Attribute Summary collapse
-
#alternate_url ⇒ Object
Alternate API URL.
-
#custom_headers ⇒ Object
custom API headers.
-
#url_parameters ⇒ Object
URL query parameter(s).
-
#user_key ⇒ Object
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_events(params) ⇒ Object
Returns the events of 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_record_similarity(params) ⇒ Object
Compares records and returns similarity information.
-
#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 API, returns name, build number and build time.
-
#initialize(user_key, alternate_url = 'https://analytics.babelstreet.com/rest/v1') ⇒ RosetteAPI
constructor
A new instance of RosetteAPI.
-
#ping ⇒ Object
Pings the 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://analytics.babelstreet.com/rest/v1') ⇒ RosetteAPI
Returns a new instance of RosetteAPI.
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rosette_api.rb', line 71 def initialize(user_key, alternate_url = 'https://analytics.babelstreet.com/rest/v1') @log = Logger.new($stdout) @user_key = user_key @alternate_url = alternate_url @url_parameters = nil @alternate_url = alternate_url.to_s.slice(0..-2) if @alternate_url.to_s.end_with?('/') 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 API URL
65 66 67 |
# File 'lib/rosette_api.rb', line 65 def alternate_url @alternate_url end |
#custom_headers ⇒ Object
custom API headers
67 68 69 |
# File 'lib/rosette_api.rb', line 67 def custom_headers @custom_headers end |
#url_parameters ⇒ Object
URL query parameter(s)
69 70 71 |
# File 'lib/rosette_api.rb', line 69 def url_parameters @url_parameters end |
#user_key ⇒ Object
API key
63 64 65 |
# File 'lib/rosette_api.rb', line 63 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.
344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/rosette_api.rb', line 344 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.
229 230 231 232 233 234 235 236 237 |
# File 'lib/rosette_api.rb', line 229 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.
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/rosette_api.rb', line 132 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.
210 211 212 213 214 215 216 217 218 219 |
# File 'lib/rosette_api.rb', line 210 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_events(params) ⇒ Object
Returns the events of the input
Attributes
-
params- DocumentParameters helps to build the request body in RequestBuilder.
Returns the events of the input
530 531 532 533 534 535 536 537 538 |
# File 'lib/rosette_api.rb', line 530 def get_events(params) check_params params params = params.load_params RequestBuilder.new(@user_key, @alternate_url + EVENTS_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.
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/rosette_api.rb', line 152 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.
92 93 94 95 96 97 98 99 100 |
# File 'lib/rosette_api.rb', line 92 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.
171 172 173 174 175 176 177 178 179 180 |
# File 'lib/rosette_api.rb', line 171 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.
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/rosette_api.rb', line 112 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.
283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/rosette_api.rb', line 283 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.
324 325 326 327 328 329 330 331 332 333 334 |
# File 'lib/rosette_api.rb', line 324 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.
303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/rosette_api.rb', line 303 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.
191 192 193 194 195 196 197 198 199 200 |
# File 'lib/rosette_api.rb', line 191 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_record_similarity(params) ⇒ Object
Compares records and returns similarity information.
Attributes
-
params- RecordSimilarityParameters helps to build the request body in RequestBuilder.
Returns record similarity results.
364 365 366 367 368 369 370 371 372 373 374 |
# File 'lib/rosette_api.rb', line 364 def get_record_similarity(params) check_params params, 'Expects a RecordSimilarityParameters type as an argument', RecordSimilarityParameters params = params.load_params RequestBuilder.new(@user_key, @alternate_url + RECORD_SIMILARITY_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.
247 248 249 250 251 252 253 254 255 |
# File 'lib/rosette_api.rb', line 247 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.
437 438 439 440 441 442 443 |
# File 'lib/rosette_api.rb', line 437 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.
402 403 404 405 406 407 408 409 410 |
# File 'lib/rosette_api.rb', line 402 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.
265 266 267 268 269 270 271 272 273 |
# File 'lib/rosette_api.rb', line 265 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
512 513 514 515 516 517 518 519 520 |
# File 'lib/rosette_api.rb', line 512 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.
454 455 456 457 458 459 460 461 462 463 |
# File 'lib/rosette_api.rb', line 454 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.
423 424 425 426 |
# File 'lib/rosette_api.rb', line 423 def (params) @log.warn('get_text_embedding is deprecated. Please use get_semantic_vectors instead.') get_semantic_vectors(params) 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.
384 385 386 387 388 389 390 391 392 |
# File 'lib/rosette_api.rb', line 384 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.
494 495 496 497 498 499 500 501 502 |
# File 'lib/rosette_api.rb', line 494 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.
474 475 476 477 478 479 480 481 482 483 484 |
# File 'lib/rosette_api.rb', line 474 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 API, returns name, build number and build time.
542 543 544 545 546 |
# File 'lib/rosette_api.rb', line 542 def info RequestBuilder.new(@user_key, @alternate_url + INFO, @http_client, BINDING_VERSION, @url_parameters) .send_get_request end |
#ping ⇒ Object
Pings the API for a response indicting that the service is available.
550 551 552 553 554 |
# File 'lib/rosette_api.rb', line 550 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
557 558 559 560 |
# File 'lib/rosette_api.rb', line 557 def user_agent RequestBuilder.new(@user_key, @alternate_url + PING, @http_client, BINDING_VERSION, @url_parameters).user_agent end |