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, post_data

Instance Method Details

#alternative_langs(lang) ⇒ Object

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



19
20
21
22
23
24
# File 'lib/nlp_toolz/helpers/lang.rb', line 19

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

#get_language(text = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/nlp_toolz/helpers/lang.rb', line 5

def get_language(text = nil)
  uri = build_url("arielle.tm.informatik.uni-leipzig.de", 55700, "/langid", nil)

  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