diff options
author | Patrick Simianer <p@simianer.de> | 2015-01-14 19:11:37 +0100 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2015-01-14 19:11:37 +0100 |
commit | 4056a888e184f1d4cada48b79370c52fc0e313b1 (patch) | |
tree | c77812f3aa267a73bde7560cba5afbad311ca99a /prototype | |
parent | 16c0aaafae5847b0fc712fbd25a25b8f7ad61bad (diff) |
fixes to prototype
Diffstat (limited to 'prototype')
-rw-r--r-- | prototype/grammar.rb | 6 | ||||
-rwxr-xr-x | prototype/test_parse.rb | 10 | ||||
-rwxr-xr-x | prototype/weaver.rb | 6 |
3 files changed, 11 insertions, 11 deletions
diff --git a/prototype/grammar.rb b/prototype/grammar.rb index 05224f4..abccb15 100644 --- a/prototype/grammar.rb +++ b/prototype/grammar.rb @@ -42,7 +42,7 @@ class NT end class Rule - attr_accessor :lhs, :rhs, :target, :map, :f + attr_accessor :lhs, :rhs, :target, :map, :f, :arity def initialize lhs=NT.new, rhs=[], target=[], map=[], f=SparseVector.new, arity=0 @lhs = lhs @@ -116,7 +116,7 @@ class Grammar @rules.map { |r| r.to_s }.join "\n" end - def add_glue + def add_glue_rules @rules.map { |r| r.lhs.symbol }.select { |s| s != 'S' }.uniq.each { |symbol| @rules << Rule.new(NT.new('S'), [NT.new(symbol, 0)], [NT.new(symbol, 0)], [0]) @start_nt << @rules.last @@ -125,7 +125,7 @@ class Grammar } end - def add_pass_through a + def add_pass_through_rules a return if !a a.each { |word| @rules << Rule.new(NT.new('X'), [T.new(word)], [T.new(word)]) diff --git a/prototype/test_parse.rb b/prototype/test_parse.rb index 0d8e625..cae6168 100755 --- a/prototype/test_parse.rb +++ b/prototype/test_parse.rb @@ -10,13 +10,13 @@ def main n = input.size STDERR.write "> reading grammar\n" - grammar = Grammar::Grammar.new '../example/toy/grammar' - #grammar = Grammar::Grammar.new '../example/toy/grammar-test' + #grammar = Grammar::Grammar.new '../example/toy/grammar' + grammar = Grammar::Grammar.new '../example/toy/grammar-test' #grammar = Grammar::Grammar.new '../example/glue/grammar' - #grammar = Grammar::Grammar.new '../example/3/grammar.3.gz' + #grammar = Grammar::Grammar.new '../example/3/grammar' 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 @@ -30,7 +30,7 @@ def main Parse::parse input, n, active_chart, passive_chart, grammar puts "\n---\npassive chart" - Parse::visit(1, 0, 5) { |i,j| puts "#{i},#{j}"; passive_chart.at(i,j).each { |item| puts " #{j} #{item.to_s}" }; puts } + Parse::visit(1, 0, n) { |i,j| k=0; puts "#{i},#{j}"; passive_chart.at(i,j).each { |item| puts " #{k} #{item.to_s}"; k+=1 }; puts } weights_file = '../example/toy/weights' #weights_file = '../example/glue/weights' diff --git a/prototype/weaver.rb b/prototype/weaver.rb index 5afdb93..5cda844 100755 --- a/prototype/weaver.rb +++ b/prototype/weaver.rb @@ -9,11 +9,11 @@ def read_grammar fn, add_glue, add_pass_through, input=nil grammar = Grammar::Grammar.new fn if add_glue STDERR.write ">> adding glue rules\n" - grammar.add_glue + grammar.add_glue_rules end if add_pass_through STDERR.write ">> adding pass-through rules\n" - grammar.add_pass_through input + grammar.add_pass_through_rules input end return grammar end @@ -51,7 +51,7 @@ def main if sgm_input && x['grammar'] grammar = read_grammar x['grammar'], cfg[:add_glue], cfg[:add_pass_through], input elsif cfg[:add_pass_through] - grammar.add_pass_through input + grammar.add_pass_through_rules input end |