class RosetteAPI

This class allows you to access all Rosette API endpoints.

Constants

ADDRESS_SIMILARITY_ENDPOINT

Rosette API address-similarity endpoint

BINDING_VERSION

Version of Ruby binding

CATEGORIES_ENDPOINT

Rosette API categories endpoint

ENTITIES_ENDPOINT

Rosette API entities endpoint

INFO

Rosette API info endpoint

LANGUAGE_ENDPOINT

Rosette API language endpoint

MORPHOLOGY_ENDPOINT

Rosette API morphology endpoint

NAME_DEDUPLICATION_ENDPOINT

Name Deduplication endpoint

NAME_SIMILARITY_ENDPOINT

Rosette API name-similarity endpoint

NAME_TRANSLATION_ENDPOINT

Rosette API name-translation endpoint

PING

Rosette API ping endpoint

RELATIONSHIPS_ENDPOINT

Rosette API relationships endpoint

SEMANTIC_VECTORS

Semantic Vectors endpoint (replaces /text-embedding)

SENTENCES_ENDPOINT

Rosette API sentences endpoint

SENTIMENT_ENDPOINT

Rosette API sentiment endpoint

SIMILAR_TERMS_ENDPOINT

Similar Terms endpoint

SYNTACTIC_DEPENDENCIES_ENDPOINT

Syntactic Dependencies endpoint

TEXT_EMBEDDING

Text Embedding endpoint (deprecated)

TOKENS_ENDPOINT

Rosette API tokens endpoint

TOPICS_ENDPOINT

Topics endpoint

TRANSLITERATION_ENDPOINT

Transliteration endpoint

Attributes

alternate_url[RW]

Alternate Rosette API URL

custom_headers[RW]

custom Rosette API headers

url_parameters[RW]

URL query parameter(s)

user_key[RW]

Rosette API key

Public Class Methods

new(user_key, alternate_url = 'https://api.rosette.com/rest/v1') click to toggle source
# File rosette_api.rb, line 68
def initialize(user_key, alternate_url = 'https://api.rosette.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

Public Instance Methods

get_address_similarity(params) click to toggle source

Compares two addresses and returns a match score from 0 to 1.

Attributes

Returns the confidence score of matching 2 addresses.

# File 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) click to toggle source

Extracts Tier 1 contextual categories from the input.

Attributes

Returns the contextual categories identified in the input.

# File 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) click to toggle source

Extracts compound-components from the input.

Attributes

Returns list of components for each compound word of the input for supported languages.

# File 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) click to toggle source

Extracts entities from the input.

Attributes

Returns each entity extracted from the input.

# File 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) click to toggle source

Extracts Han-readings from the input.

Attributes

Returns list of Han-readings which provide pronunciation information for Han script, in both Chinese and Japanese input text.

# File 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) click to toggle source

Identifies in which language(s) the input is written.

Attributes

Returns list of candidate languages in order of descending confidence.

# File 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) click to toggle source

Extracts lemmas from the input.

Attributes

Returns list of lemmas for each token of the input for supported languages.

# File 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) click to toggle source

Extracts parts-of-speech, lemmas (dictionary form), compound components, and Han-readings for each token in the input.

Attributes

Returns the lemmas, compound components, Han-readings, and parts-of-speech tags of the input for supported languages.

# File 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) click to toggle source

De-duplicates a list of names.

Attributes

Returns the list of deduplicated names.

# File 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) click to toggle source

Compares two entity names (person, location, or organization) and returns a match score from 0 to 1.

Attributes

Returns the confidence score of matching 2 names.

# File 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) click to toggle source

Translates a given name to a supported specified language.

Attributes

Returns the translation of a name.

# File 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) click to toggle source

Extracts parts-of-speech from the input.

Attributes

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.

# File 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) click to toggle source

Extracts relationships from the input.

Attributes

Returns each relationship extracted from the input.

# File 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) click to toggle source

Returns the vectors associated with the text

Attributes

Returns the text embedding representation of the input.

# File 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) click to toggle source

Divides the input into sentences.

Attributes

Returns list of linguistic sentences of the input.

# File 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) click to toggle source

Analyzes the positive and negative sentiment expressed by the input.

Attributes

Returns sentiment analysis results.

# File 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) click to toggle source

Returns the terms similar to the input

Attributes

Returns a mapping of languageCode to similar terms

# File 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) click to toggle source

Returns the syntactic structure of the text

Attributes

Returns list of linguistic sentences of the input.

# File 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) click to toggle source

Returns the vectors associated with the text

Deprecated. Please use ‘get_semantic_vectors` instead

Attributes

Returns the text embedding representation of the input.

# File rosette_api.rb, line 400
def get_text_embedding(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) click to toggle source

Divides the input into tokens.

Attributes

Returns list of tokens of the input.

# File 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) click to toggle source

Divides the input into topics (key phrases and concepts).

Attributes

Returns list of topics of the input.

# File 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) click to toggle source

Returns the transliteration of the content

Attributes

Returns the transliteration of the input.

# File 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() click to toggle source

Gets information about the Rosette API, returns name, build number and build time.

# File 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() click to toggle source

Pings the Rosette API for a response indicting that the service is available.

# File 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() click to toggle source

Gets the User-Agent string

# File rosette_api.rb, line 521
def user_agent
  RequestBuilder.new(@user_key, @alternate_url + PING, @http_client,
                     BINDING_VERSION, @url_parameters).user_agent
end