summaryrefslogtreecommitdiff
path: root/main.rb
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-06-18 16:19:32 +0200
committerPatrick Simianer <p@simianer.de>2014-06-18 16:19:32 +0200
commitf9106c8353aeaf6456a3eb0ea0c1e429f5de7650 (patch)
tree9b4c2baad153d189821633ef6649647d0992a1fa /main.rb
parent33fda7f79c02b8ef152b88a11f3810c9a25a7381 (diff)
integration
Diffstat (limited to 'main.rb')
-rwxr-xr-xmain.rb24
1 files changed, 11 insertions, 13 deletions
diff --git a/main.rb b/main.rb
index 229454a..1bf2203 100755
--- a/main.rb
+++ b/main.rb
@@ -5,16 +5,16 @@ require 'xmlsimple'
require_relative 'parse'
-def read_grammar fn, add_glue, add_pass_through
+def read_grammar fn, add_glue, add_pass_through, input=nil
STDERR.write "> reading grammar '#{fn}'\n"
grammar = Grammar::Grammar.new fn
if add_glue
- STDERR.write ">> adding glue grammar\n"
- grammar.add_glue_rules
+ STDERR.write ">> adding glue rules\n"
+ grammar.add_glue
end
if add_pass_through
- STDERR.write ">> adding pass-through grammar\n"
- grammar.add_pass_through_rules input
+ STDERR.write ">> adding pass-through rules\n"
+ grammar.add_pass_through input
end
return grammar
end
@@ -24,7 +24,7 @@ def main
opt :input, "", :type => :string, :default => '-', :short => '-i'
opt :grammar, "", :type => :string, :default => nil, :short => '-g'
opt :weights, "", :type => :string, :default => nil, :short => '-w'
- opt :add_glue, "", :type => :bool, :default => false, :short => '-h'
+ opt :add_glue, "", :type => :bool, :default => false, :short => '-l'
opt :add_pass_through, "", :type => :bool, :default => false, :short => '-p'
end
@@ -41,7 +41,7 @@ def main
n = input.size
if x['grammar']
- grammar = read_grammar x['grammar'], cfg[:add_glue], cfg[:add_pass_through]
+ grammar = read_grammar x['grammar'], cfg[:add_glue], cfg[:add_pass_through], input
end
STDERR.write "> initializing charts\n"
@@ -57,16 +57,14 @@ def main
weights = SparseVector.new
end
- hypergraph, nodes_by_id = passive_chart.to_hg weights
+ hypergraph = passive_chart.to_hg weights
+ puts hypergraph.to_json weights
STDERR.write "> viterbi\n"
semiring = ViterbiSemiring.new
- path, score = HG::viterbi_path hypergraph, nodes_by_id[-1], semiring
+ path, score = HG::viterbi_path hypergraph, hypergraph.nodes_by_id[-1], semiring
s = HG::derive path, path.last.head, []
- puts "#{s.map { |i| i.word }.join ' '}"
- puts Math.log score
- puts
-
+ STDERR.write " #{s.map { |i| i.word }.join ' '} ||| #{Math.log score}\n"
}
end