class Machinereading::Element

Attributes

lang[RW]
text[RW]

Public Class Methods

new(input_text, input_lang) click to toggle source
# File lib/machinereading/element.rb, line 10
def initialize(input_text, input_lang)
  @text = input_text
  @lang = input_lang
end

Public Instance Methods

automatic_categorization() click to toggle source
# File lib/machinereading/element.rb, line 44
def automatic_categorization
  JSON.parse call("automatic_categorization", text: self.text, lang: self.lang)
end
keyword_extractor(maxRetrieve = 15) click to toggle source
# File lib/machinereading/element.rb, line 40
def keyword_extractor(maxRetrieve = 15)
  JSON.parse call("keyword_extractor", text: self.text, lang: self.lang, maxRetrieve: maxRetrieve)
end
language_detector() click to toggle source
# File lib/machinereading/element.rb, line 36
def language_detector
  JSON.parse call("language_detector", text: self.text)
end
lemmatizer() click to toggle source
# File lib/machinereading/element.rb, line 27
def lemmatizer
  # replace "/" with " " to avoid problem during response split
  call("lemmatizer", text: self.text.gsub("/", " "), lang: self.lang).split("/")
end
pos_tagger_stanford(format = "vertical") click to toggle source
# File lib/machinereading/element.rb, line 19
def pos_tagger_stanford(format = "vertical")
  call("pos_tagger_stanford", text: self.text, lang: self.lang, format: format)
end
sequence_surprisal() click to toggle source
# File lib/machinereading/element.rb, line 32
def sequence_surprisal
  JSON.parse call("sequence_surprisal", text: self.text, lang: self.lang)
end
syntactic_parser_stanford() click to toggle source
# File lib/machinereading/element.rb, line 23
def syntactic_parser_stanford
  call("syntactic_parser_stanford", text: self.text, lang: self.lang)
end
tokenizer() click to toggle source
# File lib/machinereading/element.rb, line 15
def tokenizer
  call("tokenizer", text: self.text, lang: self.lang)
end
voice_tags() click to toggle source
# File lib/machinereading/element.rb, line 48
def voice_tags
  JSON.parse call("voice_tags", text: self.text, lang: self.lang)
end

Protected Instance Methods

call(endpoint, params) click to toggle source
# File lib/machinereading/element.rb, line 54
def call(endpoint, params)
  begin
    params = params.merge({api_key: Machinereading.config.api_key})
    conn = Faraday.new(url: Machinereading.config.endpoint) do |faraday|
      faraday.request  :url_encoded
      # faraday.response :json, :content_type => /\bjson$/
      faraday.adapter  Faraday.default_adapter
    end
    response = conn.post "/#{endpoint}", params
    response.body
  rescue Exception => e
    raise Machinereading::BadResponse
  end
end