Class: Lingo24::PremiumMTAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/lingo24/premium_mt_api.rb

Overview

PremiumMTAPI is an API wrapper for the Lingo24 Premium Machine Translation API (developer.lingo24.com/premium-machine-translation-api).

Machine Translation (MT) is a cost-effective, quick translation option for large volumes of content, or cases where it is not feasible to use a professional human translator.

The Lingo24 Premium Machine Translation API provides direct, secure, high volume access to our Premium Machine Translation Engines. Encrypted using SSL and with no data storage at Lingo24, you can translate safely with no data privacy concerns.

We have developed a range of Premium MT engines focusing on specific language combinations and subject areas, including Law, Information Technology, Pharmaceuticals, Business, IT and many more. This focused approach results in much higher-quality output than generic engines from big-name translators, with the API selecting the best suited engine based on the content of the text for translation. Ideal for those scenarios where no post-editing is required, such as gisting (getting a basic understanding of a source text), real-time translation (tweets, IM chat, etc) or sentiment analysis, the Premium MT API enables easy access to raw machine translation.

Constant Summary collapse

BASE_API_URL =
"https://api.lingo24.com/mt/v1/"

Instance Method Summary collapse

Constructor Details

#initialize(user_key) ⇒ PremiumMTAPI

Creates a new API client to handle calls to the Lingo24 Premium Machine Translation API.

Parameters: user_key - a string containing the user_key issued by the Lingo24 developer portal for your application.



29
30
31
# File 'lib/lingo24/premium_mt_api.rb', line 29

def initialize(user_key)
  @user_key = user_key
end

Instance Method Details

#get_source_langs(target = nil) ⇒ Object

Returns a list of the supported source languages for PremiumMTAPI. This method will return a list containing Lingo24::Language objects which provide access to both the ISO-639-1 code as well as a friendly name.

If the target is nil, the list will contain all possible source languages. If the target is set, the list will contain only the source languages that can generate the target language.



82
83
84
85
86
87
88
89
90
# File 'lib/lingo24/premium_mt_api.rb', line 82

def get_source_langs(target = nil)
  if (target.nil?)
    params = { :user_key => @user_key }
  else
    params = { :user_key => @user_key, :target => target }
  end
  source_langs = handle_request('sourcelangs', params, 'source_langs')
  source_langs.map { |code, name| Lingo24::Language.new(code, name) }
end

#get_target_langs(source = nil) ⇒ Object

Returns a list of the supported target languages for PremiumMTAPI. This method will return a list containing Lingo24::Language objects which provide access to both the ISO-639-1 code as well as a friendly name.

If source is nil, the list will contain all possible target languages. If source is set, the list will contain only the target languages that can generate the source language.



99
100
101
102
103
104
105
106
107
# File 'lib/lingo24/premium_mt_api.rb', line 99

def get_target_langs(source = nil)
  if (source.nil?)
    params = { :user_key => @user_key }
  else
    params = { :user_key => @user_key, :source => source }
  end
  target_langs = handle_request('targetlangs', params, 'target_langs')
  target_langs.map { |code, name| Lingo24::Language.new(code, name) }
end

#translate(text, source, target) ⇒ Object

Synchronous call to translate text using the Lingo24 Premium Machine Translation API. When calling this method the text sent is analysed and routed to the engine most likely to produce the highest quality output.

NOTE: Customers who have custom engines for specific business domains will have these prioritised ahead of Lingo24 vertical engines.

Options: text - a string for translation source - a string containing the ISO-639-1 code for the source language target - a string containing the ISO-639-1 code for the target language



43
44
45
46
# File 'lib/lingo24/premium_mt_api.rb', line 43

def translate(text, source, target)
  params = {:q => text, :source => source, :target => target, :user_key => @user_key}
  handle_request('translate', params, 'translation')
end

#translate_language(text, source, target) ⇒ Object

Synchronous call to translate text using the Lingo24 Premium Machine Translation API. When calling this method the text sent is analysed and routed to the engine most likely to produce the highest quality output.

NOTE: Customers who have custom engines for specific business domains will have these prioritised ahead of Lingo24 vertical engines.

Options: text - a string for translation source - a Lingo24::Language containing the source language target - a Lingo24::Language containing the target language



58
59
60
61
# File 'lib/lingo24/premium_mt_api.rb', line 58

def translate_language(text, source, target)
  params = {:q => text, :source => source.code, :target => target.code, :user_key => @user_key}
  handle_request('translate', params, 'translation')
end

#translate_specific(text, id) ⇒ Object

Synchronous call to translate text using a specific Lingo24 Premium Machine Translation engine. This method is typically used by customers who have a custom engine and want to ignore the automatic classification..

Options: text - a string for translation source - a Lingo24::Language containing the source language target - a Lingo24::Language containing the target language



70
71
72
73
# File 'lib/lingo24/premium_mt_api.rb', line 70

def translate_specific(text, id)
  params = {:q => text, :id => id, :user_key => @user_key}
  handle_request('translate', params, 'translation')
end