class AjaxCat::Request::Suggestion

Public Class Methods

new(sentence, covered, translated) click to toggle source
Calls superclass method AjaxCat::Request::Raw::new
# File lib/ajax-cat/request/suggestion.rb, line 10
def initialize(sentence, covered, translated)
        super(sentence)
        @covered = covered
        @translated = translated
        @translated_length = tokenize(translated).length
        @suggestions = []
        @suggested_phrases = []
end

Public Instance Methods

prepare_moses_request() click to toggle source
# File lib/ajax-cat/request/suggestion.rb, line 19
def prepare_moses_request
        "#{@translated} ||| #{@covered} ||| #{@sentence}"
end
process_line(line) click to toggle source
# File lib/ajax-cat/request/suggestion.rb, line 29
def process_line(line)
        words = line.split(" ||| ")[1].strip.split(" ")
        if @suggestions.length < @@rows
                alignment = line.split(" ||| ")[4].strip.split(" ").first
                phrase = Phrase.new(words, alignment)
                suggestion = {
                        "text" => phrase.words,
                        "from" => phrase.from,
                        "to" => phrase.to
                }
                if not @suggested_phrases.member?(suggestion['text'])
                        @suggested_phrases.push(suggestion['text'])
                        @suggestions.push(suggestion)
                end
        end
end
result() click to toggle source
# File lib/ajax-cat/request/suggestion.rb, line 23
def result
        {
                "suggestions" => @suggestions
        }
end