Class: AjaxCat::Request::Table
Constant Summary collapse
- @@rows =
5
Instance Attribute Summary
Attributes inherited from Raw
Instance Method Summary collapse
-
#initialize(sentence) ⇒ Table
constructor
A new instance of Table.
- #process_line(line) ⇒ Object
- #result ⇒ Object
Methods inherited from Raw
parse_position, #prepare_moses_request, #tokenize
Constructor Details
#initialize(sentence) ⇒ Table
Returns a new instance of Table.
9 10 11 12 13 14 15 |
# File 'lib/ajax-cat/request/table.rb', line 9 def initialize(sentence) super(sentence) @ret = {} @ret["source"] = @sentence.strip.split(" ") @buckets = [] @ret["source"].size.times {@buckets.push([])} end |
Instance Method Details
#process_line(line) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ajax-cat/request/table.rb', line 46 def process_line(line) splited = line.split(" ||| ") words = splited[1].strip.split(" ") alignment = splited[4].strip.split(" ") alignment.each do |al| phrase = Phrase.new(words, al) finded = @buckets[phrase.from].find do |el| el.words == phrase.words and el.to == phrase.to end @buckets[phrase.from].push(phrase) if finded == nil end end |
#result ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ajax-cat/request/table.rb', line 17 def result @ret["table"] = [] @@rows.times do |row_number| i = 0 free_space = 0 row = [] while i < @buckets.size el = @buckets[i].shift if el if free_space > 0 row.push({"w" => free_space}) end this_space = el.to - el.from + 1 row.push({ "str" => el.words, "w" => this_space }) free_space = 0 i += this_space else free_space += 1 i += 1 end end @ret["table"].push(row) if row.size > 0 end return @ret end |