From d76b8947471087992ac945bdb5eb5620869672d1 Mon Sep 17 00:00:00 2001 From: Patrick Simianer
Date: Fri, 23 May 2014 20:06:34 +0200 Subject: before new visit --- example/grammar | 1 - grammar.rb | 2 +- parse.rb | 27 ++++++++++++++------------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/example/grammar b/example/grammar index 4a3c93c..81d41c7 100644 --- a/example/grammar +++ b/example/grammar @@ -1,5 +1,4 @@ [S] ||| [NP,1] [VP,2] ||| [1] [2] ||| logp=0 -[S] ||| ich sah ein [NN,1] ||| [NP] ||| ich ||| i ||| logp=-0.5 use_i=1.0 [NP] ||| ein [NN,1] ||| a [1] ||| logp=0 use_a=1.0 [NN] ||| kleines haus ||| small house ||| logp=0 use_house=1 diff --git a/grammar.rb b/grammar.rb index b7d2408..52d0fba 100644 --- a/grammar.rb +++ b/grammar.rb @@ -70,7 +70,7 @@ class Grammar def initialize fn @rules = []; @startn = []; @startt = [] ;@flat = [] ReadFile.readlines_strip(fn).each_with_index { |s,i| - STDERR.write '.'; STDERR.write "\n" if (i+1)%80==0 + STDERR.write '.'; STDERR.write " #{i+1}\n" if (i+1)%80==0 @rules << Rule.from_s(s) if @rules.last.rhs.first.class == NT @startn << @rules.last diff --git a/parse.rb b/parse.rb index cb428d1..152299c 100644 --- a/parse.rb +++ b/parse.rb @@ -77,7 +77,16 @@ def scan item, input, limit, passive_chart return true end +def visit i, l, r, x=1 + i.upto(r-x) { |span| + l.upto(r-span) { |k| + yield k, k+span + } + } +end + def parse input, n, active_chart, passive_chart, grammar + #visit(2, 0, 5) { |i,j| 2.upto(n) { |span| # outer loops 0.upto(n-span) { |k| @@ -96,6 +105,7 @@ def parse input, n, active_chart, passive_chart, grammar } active_chart.at(k,k+span).each { |active_item| + #visit(1, k, k+span) { |k,l| 1.upto(span-1) { |span2| # inner loops k.upto((k+span)-span2) { |l| @@ -150,24 +160,15 @@ def parse input, n, active_chart, passive_chart, grammar } end -def visit n, depth, skip=0 # FIXME - (depth-skip).times { |i| - i += skip - 0.upto(n-(i+1)) { |j| - yield j, j+i+1 - } - } -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.new 'example/grammar.3.gz' + grammar = Grammar.new 'example/grammar' STDERR.write ">> adding glue grammar\n" grammar.add_glue_rules STDERR.write ">> adding pass-through grammar\n" @@ -182,7 +183,7 @@ def main parse input, n, active_chart, passive_chart, grammar puts "\n---\npassive chart" - visit(n, n, 0) { |i,j| puts "#{i},#{j}"; passive_chart.at(i,j).each { |item| puts ' '+item.to_s }; puts } + visit(1, 0, 5, 0) { |i,j| puts "#{i},#{j}"; passive_chart.at(i,j).each { |item| puts ' '+item.to_s }; puts } end -- cgit v1.2.3