Module: Lang

Includes:
UrlHandler
Included in:
NlpToolz, NlpToolz::Parser, NlpToolz::PosTags, NlpToolz::Sentences, NlpToolz::Tokens
Defined in:
lib/nlp_toolz/helpers/lang.rb

Instance Method Summary collapse

Methods included from UrlHandler

#build_url, included, #post_data

Instance Method Details

#alternative_langs(lang) ⇒ Object

ToDo 2013-02-26: make different lang identifier available



29
30
31
32
33
34
# File 'lib/nlp_toolz/helpers/lang.rb', line 29

def alternative_langs lang
  langs = {
    en: [:eng, :english],
    de: [:ger, :german]
  }.each.collect{|x| x.flatten}
end

#get_language(text = nil) ⇒ Object

get language of input



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/nlp_toolz/helpers/lang.rb', line 5

def get_language(text = nil)
  environment = ENV['ENV_NAME'] || 'development'
  # ToDo 2013-03-14: respect environment
  case environment
  when 'development'
    # development -> local
    # uri = build_url("localhost", 9292, "/langid", nil)
    uri = build_url("arielle.tm.informatik.uni-leipzig.de", 55700, "/langid", nil)
  when 'production'
    # production
    uri = build_url("arielle.tm.informatik.uni-leipzig.de", 55700, "/langid", nil)
  end

  if @input
    asv_response = post_data(URI.escape(@input),uri,{'Content-type'=>'text/plain;charset=utf-8'})
  elsif text
    asv_response = post_data(URI.escape(text),uri,{'Content-type'=>'text/plain;charset=utf-8'})
  end
  response = MultiJson.load(asv_response.body)

  response["lang"]
end