From 6af0e08e8fdec9d6a97244da8d136501022a6c93 Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Tue, 3 Jun 2014 15:13:42 +0200 Subject: get rid of that silly translation stuff.. --- lib/nlp_ruby/hg.rb | 8 +++----- test/hg/hg-toy-with-target.json | 31 ------------------------------- 2 files changed, 3 insertions(+), 36 deletions(-) delete mode 100644 test/hg/hg-toy-with-target.json diff --git a/lib/nlp_ruby/hg.rb b/lib/nlp_ruby/hg.rb index 66e3b13..b8b147e 100644 --- a/lib/nlp_ruby/hg.rb +++ b/lib/nlp_ruby/hg.rb @@ -43,13 +43,12 @@ end class HG::Hyperedge attr_accessor :head, :tails, :weight, :f, :mark, :rule, :left, :right - def initialize head=nil, tails=[], weight=0.0, f={}, rule=nil, left=nil, right=nil + def initialize head=nil, tails=[], weight=0.0, f={} @head = head @tails = tails @weight = weight @f = f @mark = 0 - @rule = Grammar::Rule.from_s rule if rule end def arity @@ -61,7 +60,7 @@ class HG::Hyperedge end def to_s - "Hyperedge" + "Hyperedge" end end @@ -136,8 +135,7 @@ def HG::read_hypergraph_from_json fn, semiring=RealSemiring.new, log_weights=fal e = Hyperedge.new(nodes_by_label[i['head']], \ i['tails'].map{|j| nodes_by_label[j]}.to_a, \ semiring.convert.call(i['weight'].to_f), \ - {}, \ - i['rule'], i['left'], i['right']) + {}) e.f = SparseVector.from_h i['f'] if log_weights e.weight = Math.exp(w.dot(e.f)) diff --git a/test/hg/hg-toy-with-target.json b/test/hg/hg-toy-with-target.json deleted file mode 100644 index 1fb4b3d..0000000 --- a/test/hg/hg-toy-with-target.json +++ /dev/null @@ -1,31 +0,0 @@ -{ -"weights":{ -"logp":2.0, "use_house":0.0, "use_shell":1.0 -}, -"nodes": -[ -{ "label":"root", "cat":"root" }, -{ "label":"0", "cat":"NP" }, -{ "label":"1", "cat":"V" }, -{ "label":"2", "cat":"JJ" }, -{ "label":"3", "cat":"NN" }, -{ "label":"4", "cat":"NP" }, -{ "label":"5", "cat":"VP" }, -{ "label":"6", "cat":"S" }, -{ "label":"7", "cat":"Goal" } -], -"edges": -[ -{"head":"0", "trule":"[NP] ||| ich ||| i ||| logp=-0.5 use_i=1.0", "left":0, "right":1, "tails":[ "root" ], "f":{"logp":-0.5, "use_i":1.0}, "weight":0.367879441171 }, -{"head":"1", "trule":"[V] ||| sah ||| saw ||| logp=-0.25 use_saw=1.0", "left":1, "right":2, "tails":[ "root" ], "f":{"logp":-0.25, "use_saw":1.0}, "weight":0.606530659713 }, -{"head":"2", "trule":"[JJ] ||| kleines ||| small ||| logp=0.0 use_small=1.0", "left":3, "right":4, "tails":[ "root" ], "f":{"logp":0.0, "use_small":1.0}, "weight":1.0 }, -{"head":"2", "trule":"[JJ] ||| kleines ||| little ||| logp=0.0 use_little=1.0", "left":3, "right":4, "tails":[ "root" ], "f":{"logp":0.0, "use_little":1.0}, "weight":1.0 }, -{"head":"3", "trule":"[NN] ||| [JJ,1] haus ||| [1] house ||| logp=0.0 use_house=1.0", "left":3, "right":5, "tails":[ "2" ], "f":{"logp":0.0, "use_house":1.0}, "weight":1.0 }, -{"head":"3", "trule":"[NN] ||| [JJ,1] haus ||| [1] shell ||| logp=0.0 use_shell=1.0", "left":3, "right":5, "tails":[ "2" ], "f":{"logp":0.0, "use_shell":1.0}, "weight":2.71828182846 }, -{"head":"4", "trule":"[NP] ||| ein [NN,1] ||| a [1] ||| logp=0.0 use_a=1.0", "left":2, "right":5, "tails":[ "3" ], "f":{"logp":0.0, "use_a":1.0}, "weight":1.0 }, -{"head":"5", "trule":"[VP] ||| [V,1] [NP,2] ||| [1] [2] ||| logp=0.0", "left":1, "right":5, "tails":[ "1","4" ], "f":{"logp":0.0}, "weight":1.0 }, -{"head":"6", "trule":"[S] ||| [NP,1] [VP,2] ||| [1] [2] ||| logp=0.0", "left":0, "right":5, "tails":[ "0","5" ], "f":{"logp":0.0}, "weight":1.0 }, -{"head":"7", "trule":"[Goal] ||| [S,1] ||| [1] ||| ", "left":0, "right":5, "tails":[ "6" ], "f":{}, "weight":1.0 } -] -} - -- cgit v1.2.3