diff options
author | Patrick Simianer <p@simianer.de> | 2014-06-12 14:29:51 +0200 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2014-06-12 14:29:51 +0200 |
commit | 7d267062cd109ac27cff8a818ff368b949d7f6a0 (patch) | |
tree | 56b043be1e4dd85987b5476644d2f6f7063e8d08 /test_parse.rb | |
parent | a981df066484f799637c8a0b88209110038e3148 (diff) |
cleanup
Diffstat (limited to 'test_parse.rb')
-rwxr-xr-x | test_parse.rb | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/test_parse.rb b/test_parse.rb index 51eb32a..18afd55 100755 --- a/test_parse.rb +++ b/test_parse.rb @@ -3,7 +3,7 @@ require_relative 'parse' -def chart2json passive_chart +def chart2json passive_chart, n id = 0 spancat2id = {} puts "{" @@ -11,7 +11,7 @@ def chart2json passive_chart puts "\"nodes\":" puts "[" # nodes - visit(1, 0, 5) { |i,j| + visit(1, 0, n) { |i,j| seen = {} passive_chart.at(i,j).each { |item| if !seen[item.lhs.symbol] @@ -27,12 +27,12 @@ def chart2json passive_chart puts "\"edges\":" puts "[" a = [] - visit(1, 0, 5) { |i,j| + visit(1, 0, n) { |i,j| passive_chart.at(i,j).each { |item| if item.tail_spans.empty? - a << "{ \"head\":#{spancat2id[item.lhs.symbol+','+i.to_s+','+j.to_s]}, \"rule\":\"[#{item.lhs.symbol}] ||| #{item.rhs.map{|x|(x.class==Grammar::NT ? '['+x.symbol+','+x.index.to_s+']' : x.word)}.join(' ')} ||| #{item.target.map{|x|(x.class==Grammar::NT ? '['+x.symbol+','+(x.index+1).to_s+']' : x.word)}.join(' ')}\ |||\", \"tails\":[-1], \"f\":#{item.f.to_s.gsub('=>',':')} }" + a << "{ \"head\":#{spancat2id[item.lhs.symbol+','+i.to_s+','+j.to_s]}, \"rule\":\"[#{item.lhs.symbol}] ||| #{item.rhs.map{|x|(x.class==Grammar::NT ? '['+x.symbol+','+x.index.to_s+']' : x.word.gsub('"','\"'))}.join(' ')} ||| #{item.target.map{|x|(x.class==Grammar::NT ? '['+x.symbol+','+(x.index+0).to_s+']' : x.word.gsub('"', '\"'))}.join(' ')}\ |||\", \"tails\":[-1], \"f\":#{item.f.to_s.gsub('=>',':')} }" else - a << "{ \"head\":#{spancat2id[item.lhs.symbol+','+i.to_s+','+j.to_s]}, \"rule\":\"[#{item.lhs.symbol}] ||| #{item.rhs.map{|x|(x.class==Grammar::NT ? '['+x.symbol+','+x.index.to_s+']' : x.word)}.join(' ')} ||| #{item.target.map{|x|(x.class==Grammar::NT ? '['+x.symbol+','+(x.index+1).to_s+']' : x.word)}.join(' ')}\ |||\", \"tails\":[#{item.rhs.zip((0..item.rhs.size-1).map{|q|item.tail_spans[q]}).select{|x|x[0].class==Grammar::NT}.map{|x|spancat2id[x[0].symbol+','+x[1].left.to_s+','+x[1].right.to_s]}.join ', '}], \"f\":#{item.f.to_s.gsub('=>',':')} }" + a << "{ \"head\":#{spancat2id[item.lhs.symbol+','+i.to_s+','+j.to_s]}, \"rule\":\"[#{item.lhs.symbol}] ||| #{item.rhs.map{|x|(x.class==Grammar::NT ? '['+x.symbol+','+x.index.to_s+']' : x.word.gsub('"','\"'))}.join(' ')} ||| #{item.target.map{|x|(x.class==Grammar::NT ? '['+x.symbol+','+(x.index+1).to_s+']' : x.word.gsub('"', '\"'))}.join(' ')}\ |||\", \"tails\":[#{item.rhs.zip((0..item.rhs.size-1).map{|q|item.tail_spans[q]}).select{|x|x[0].class==Grammar::NT}.map{|x|spancat2id[x[0].symbol+','+x[1].left.to_s+','+x[1].right.to_s]}.join ', '}], \"f\":#{item.f.to_s.gsub('=>',':')} }" end } } @@ -44,15 +44,15 @@ end def main STDERR.write "> reading input from TODO\n" - input = 'ich sah ein kleines haus'.split + #input = 'ich sah ein kleines haus'.split #input = 'lebensmittel schuld an europäischer inflation'.split - #input = 'offizielle prognosen sind von nur 3 prozent ausgegangen , meldete bloomberg .'.split + input = 'offizielle prognosen sind von nur 3 prozent ausgegangen , meldete bloomberg .'.split n = input.size STDERR.write "> reading grammar\n" - grammar = Grammar::Grammar.new 'example/toy/grammar' + grammar = Grammar::Grammar.new 'example/grammars/grammar.3.gz' STDERR.write ">> adding glue grammar\n" - #grammar.add_glue_rules + grammar.add_glue_rules STDERR.write ">> adding pass-through grammar\n" #grammar.add_pass_through_rules input @@ -67,7 +67,7 @@ def main #puts "\n---\npassive chart" #visit(1, 0, 5) { |i,j| puts "#{i},#{j}"; passive_chart.at(i,j).each { |item| puts " #{j} #{item.to_s}" }; puts } - chart2json passive_chart + chart2json passive_chart, n end |