Class: AjaxCat::Request::Suggestion

Inherits:
Raw
  • Object
show all
Defined in:
lib/ajax-cat/request/suggestion.rb

Constant Summary collapse

@@rows =
5
@@suggestion_length =
3

Instance Attribute Summary

Attributes inherited from Raw

#lock, #processed, #sentence

Instance Method Summary collapse

Methods inherited from Raw

parse_position, #tokenize

Constructor Details

#initialize(sentence, covered, translated) ⇒ Suggestion

Returns a new instance of Suggestion.



10
11
12
13
14
15
16
17
# 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

Instance Method Details

#prepare_moses_requestObject



19
20
21
# File 'lib/ajax-cat/request/suggestion.rb', line 19

def prepare_moses_request
	"#{@translated} ||| #{@covered} ||| #{@sentence}"
end

#process_line(line) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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

#resultObject



23
24
25
26
27
# File 'lib/ajax-cat/request/suggestion.rb', line 23

def result
	{
		"suggestions" => @suggestions
	}
end