summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--example/json/test.json12
-rw-r--r--hg.rb2
-rw-r--r--parse.rb32
-rwxr-xr-xtest_hg.rb (renamed from test.rb)0
4 files changed, 9 insertions, 37 deletions
diff --git a/example/json/test.json b/example/json/test.json
index d865fa0..c58c249 100644
--- a/example/json/test.json
+++ b/example/json/test.json
@@ -22,12 +22,12 @@
{"head":2, "rule":"[JJ] ||| kleines ||| little ||| logp=0.0 use_little=1.0", "tails":[ -1 ], "f":{"logp":0.0, "use_little":1.0}, "weight":1.0 },
{"head":3, "rule":"[NN] ||| kleines haus ||| small house ||| logp=0.0 use_house=1.0", "tails":[ -1 ], "f":{"logp":0.0, "use_house":1.0}, "weight":1.0 },
{"head":3, "rule":"[NN] ||| kleines haus ||| little house ||| logp=0.0 use_house=1.0", "tails":[ -1 ], "f":{"logp":0.0, "use_house":1.0}, "weight":1.0 },
-{"head":3, "rule":"[NN] ||| [JJ,1] haus ||| [1] house ||| logp=0.0 use_house=1.0", "tails":[ 2 ], "f":{"logp":0.0, "use_house":1.0}, "weight":1.0 },
-{"head":3, "rule":"[NN] ||| [JJ,1] haus ||| [1] shell ||| logp=0.0 use_shell=1.0", "tails":[ 2 ], "f":{"logp":0.0, "use_shell":1.0}, "weight":2.71828182846 },
-{"head":4, "rule":"[NP] ||| ein [NN,1] ||| a [1] ||| logp=0.0 use_a=1.0", "tails":[ 3 ], "f":{"logp":0.0, "use_a":1.0}, "weight":1.0 },
-{"head":5, "rule":"[VP] ||| [V,1] [NP,2] ||| [1] [2] ||| logp=0.0", "tails":[ 1,4 ], "f":{"logp":0.0}, "weight":1.0 },
-{"head":6, "rule":"[S] ||| [NP,1] [VP,2] ||| [1] [2] ||| logp=0.0", "tails":[ 0,5 ], "f":{"logp":0.0}, "weight":1.0 },
-{"head":7, "rule":"[Goal] ||| [S,1] ||| [1] ||| ", "tails":[ 6 ], "f":{}, "weight":1.0 }
+{"head":3, "rule":"[NN] ||| [JJ,1] haus ||| [JJ,1] house ||| logp=0.0 use_house=1.0", "tails":[ 2 ], "f":{"logp":0.0, "use_house":1.0}, "weight":1.0 },
+{"head":3, "rule":"[NN] ||| [JJ,1] haus ||| [JJ,1] shell ||| logp=0.0 use_shell=1.0", "tails":[ 2 ], "f":{"logp":0.0, "use_shell":1.0}, "weight":2.71828182846 },
+{"head":4, "rule":"[NP] ||| ein [NN,1] ||| a [NN,1] ||| logp=0.0 use_a=1.0", "tails":[ 3 ], "f":{"logp":0.0, "use_a":1.0}, "weight":1.0 },
+{"head":5, "rule":"[VP] ||| [V,1] [NP,2] ||| [V,1] [NP,2] ||| logp=0.0", "tails":[ 1,4 ], "f":{"logp":0.0}, "weight":1.0 },
+{"head":6, "rule":"[S] ||| [NP,1] [VP,2] ||| [VP,1] [NP,2] ||| logp=0.0", "tails":[ 0,5 ], "f":{"logp":0.0}, "weight":1.0 },
+{"head":7, "rule":"[Goal] ||| [S,1] ||| [S,1] ||| ", "tails":[ 6 ], "f":{}, "weight":1.0 }
]
}
diff --git a/hg.rb b/hg.rb
index 43dbf79..b73d860 100644
--- a/hg.rb
+++ b/hg.rb
@@ -151,7 +151,7 @@ def HG::derive path, cur, carry
j = 0
edge.rule.target.each { |i|
if i.class == Grammar::NT
- derive path, edge.tails[j], carry
+ derive path, edge.tails[edge.rule.map[j]], carry
j += 1
else
carry << i
diff --git a/parse.rb b/parse.rb
index 6adf2c0..24b98c6 100644
--- a/parse.rb
+++ b/parse.rb
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby
require 'nlp_ruby'
+require_relative 'grammar'
class Chart
@@ -30,7 +31,7 @@ class Chart
end
class Item < Grammar::Rule
- attr_accessor :lhs, :rhs, :dot, :e
+ attr_accessor :dot
def initialize rule_or_item, left, right, dot
@lhs = Grammar::NT.new rule_or_item.lhs.symbol
@@ -154,32 +155,3 @@ def parse input, n, active_chart, passive_chart, grammar
}
end
-def main
- STDERR.write "> reading input from TODO\n"
- #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
- n = input.size
-
- STDERR.write "> reading grammar\n"
- grammar = Grammar::Grammar.new 'example/grammars/grammar.3.gz'
- STDERR.write ">> adding glue grammar\n"
- #grammar.add_glue_rules
- STDERR.write ">> adding pass-through grammar\n"
- #grammar.add_pass_through_rules input
-
- STDERR.write "> initializing charts\n"
- passive_chart = Chart.new n
- active_chart = Chart.new n
- init input, n, active_chart, passive_chart, grammar
-
- STDERR.write "> parsing\n"
- parse input, n, active_chart, passive_chart, grammar
-
- puts "\n---\npassive chart"
- visit(1, 0, 5) { |i,j| puts "#{i},#{j}"; passive_chart.at(i,j).each { |item| puts ' '+item.to_s }; puts }
-end
-
-
-main
-
diff --git a/test.rb b/test_hg.rb
index e65c9b3..e65c9b3 100755
--- a/test.rb
+++ b/test_hg.rb