summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--example/toy-reorder/grammar6
-rw-r--r--example/toy-reorder/in1
-rw-r--r--example/toy-reorder/weights.toy1
-rw-r--r--prototype/hypergraph.rb4
-rwxr-xr-xprototype/ow_proto.rb6
5 files changed, 12 insertions, 6 deletions
diff --git a/example/toy-reorder/grammar b/example/toy-reorder/grammar
new file mode 100644
index 0000000..d93d98c
--- /dev/null
+++ b/example/toy-reorder/grammar
@@ -0,0 +1,6 @@
+[S] ||| [NP,1] [VP,2] ||| [NP,1] [VP,2] ||| logp=0
+[NP] ||| er ||| he ||| logp=-0.5
+[NP] ||| das [NN,1] ||| the [NN,1] ||| logp=0
+[NN] ||| buch ||| book ||| logp=0
+[VP] ||| [NP,1] [V,2] ||| [V,2] [NP,1] ||| logp=0
+[V] ||| liest ||| reads ||| logp=-0.25
diff --git a/example/toy-reorder/in b/example/toy-reorder/in
new file mode 100644
index 0000000..6eeb3a9
--- /dev/null
+++ b/example/toy-reorder/in
@@ -0,0 +1 @@
+er das buch liest
diff --git a/example/toy-reorder/weights.toy b/example/toy-reorder/weights.toy
new file mode 100644
index 0000000..3eb2502
--- /dev/null
+++ b/example/toy-reorder/weights.toy
@@ -0,0 +1 @@
+logp 2
diff --git a/prototype/hypergraph.rb b/prototype/hypergraph.rb
index fd72393..fdaba5a 100644
--- a/prototype/hypergraph.rb
+++ b/prototype/hypergraph.rb
@@ -196,11 +196,9 @@ def HG::derive path, cur, carry
edge = path.select { |e| e.head.symbol==cur.symbol \
&& e.head.left==cur.left \
&& e.head.right==cur.right }.first
- j = 0
edge.rule.target.each { |i|
if i.class == Grammar::NT
- derive path, edge.tails[edge.rule.map[j]], carry
- j += 1
+ derive path, edge.tails[edge.rule.map.index(i.index)], carry
else
carry << i
end
diff --git a/prototype/ow_proto.rb b/prototype/ow_proto.rb
index 912090b..41fe683 100755
--- a/prototype/ow_proto.rb
+++ b/prototype/ow_proto.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
-require 'trollop'
-require 'xmlsimple'
+require 'optimist'
+begin; require 'xmlsimple'; rescue LoadError; end
require_relative 'parse'
def read_grammar fn, add_glue, add_pass_through, input=nil
@@ -19,7 +19,7 @@ def read_grammar fn, add_glue, add_pass_through, input=nil
end
def main
- cfg = Trollop::options do
+ cfg = Optimist::options do
opt :input, "", :type => :string, :default => '-', :short => '-i'
opt :grammar, "", :type => :string, :required => true, :short => '-g'
opt :weights, "", :type => :string, :required => true, :short => '-w'