summaryrefslogtreecommitdiff
path: root/prototype
diff options
context:
space:
mode:
authorPatrick Simianer <patrick@lilt.com>2026-02-24 17:07:57 +0100
committerPatrick Simianer <patrick@lilt.com>2026-02-24 17:07:57 +0100
commit77666a09c0f82b231605da463a946a5a5fcd09b6 (patch)
tree44d0e96bac774b491290b548358b65176f5dec94 /prototype
parentc13b5650ac4bee7e674d263fcb778599bb449bff (diff)
Fix reordering bug in derive and add test example
derive used a sequential counter to index into the source-side NT map, which only worked for monotone rules. Now looks up tails by the target NT's own index via map.index(i.index). Adds toy-reorder example (German verb-final -> English SVO) to exercise the fix. Also updates trollop -> optimist and guards xmlsimple require. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'prototype')
-rw-r--r--prototype/hypergraph.rb4
-rwxr-xr-xprototype/ow_proto.rb6
2 files changed, 4 insertions, 6 deletions
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'