diff options
author | Patrick Simianer <p@simianer.de> | 2014-06-04 20:32:43 +0200 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2014-06-04 20:32:43 +0200 |
commit | bc71d67647ac9b124cc666a43fc819cad20cfe06 (patch) | |
tree | 9a795836390bdcb5436e638ef750ad0324490f19 | |
parent | a10db22ce00bd004682a00322b4d177b694082b7 (diff) |
pretty
-rw-r--r-- | grammar.rb | 16 | ||||
-rw-r--r-- | hg.rb | 17 |
2 files changed, 17 insertions, 16 deletions
@@ -17,9 +17,9 @@ class NT def initialize symbol=nil, index=nil, left=nil, right=nil @symbol = symbol - @index = index - @left = left - @right = right + @index = index + @left = left + @right = right end def from_s s @@ -47,19 +47,19 @@ class Rule attr_accessor :lhs, :rhs, :target, :map def initialize lhs=nil, rhs=[], target=[] - @lhs = lhs - @rhs = rhs + @lhs = lhs + @rhs = rhs @target = target @arity_ = nil end def to_s - "#{@lhs} -> #{@rhs.map{ |i| i.to_s }.join ' '} ||| #{@target.map{ |i| i.to_s }.join ' '} [arity=#{arity}]" #FIXME + "#{@lhs} -> #{@rhs.map{ |i| i.to_s }.join ' '} ||| #{@target.map{ |i| i.to_s }.join ' '} [arity=#{arity}]" end def arity - return @arity_ if @arity_ - rhs.select { |i| i.class == NT }.size + @arity_ = rhs.select { |i| i.class == NT }.size if !@arity_ + return @arity_ end def read_right_ s @@ -1,7 +1,6 @@ #!/usr/bin/env ruby require 'nlp_ruby' -require 'json' require_relative 'grammar' @@ -9,7 +8,7 @@ module HG class HG::Node - attr_accessor :id, :cat, :outgoing, :incoming, :score + attr_accessor :id, :outgoing, :incoming, :score def initialize id=nil, cat=nil, outgoing=[], incoming=[], score=nil @id = id @@ -19,7 +18,7 @@ class HG::Node end def to_s - "Node<id:#{@id}, cat:\"#{@cat}\", outgoing:#{@outgoing.size}, incoming:#{@incoming.size}>" + "Node<id:#{@id}, outgoing:#{@outgoing.size}, incoming:#{@incoming.size}>" end end @@ -27,12 +26,14 @@ class HG::Hypergraph attr_accessor :nodes, :edges def initialize nodes=[], edges=[] - @nodes = nodes - @edges = edges + @nodes = nodes + @edges = edges + @arity_ = nil end def arity - @edges.map { |e| e.arity }.max + @arity_ = @edges.map { |e| e.arity }.max if !@arity_ + return @arity_ end def reset @@ -40,7 +41,7 @@ class HG::Hypergraph end def to_s - "Hypergraph<nodes:[#{@nodes.to_s}], edges:[#{@edges.to_s}], arity:#{arity}>" + "Hypergraph<nodes:#{@nodes.size}, edges:#{@edges.size}, arity:#{arity}>" end end @@ -53,7 +54,7 @@ class HG::Hyperedge @score = score @f = f @mark = 0 - @rule = Grammar::Rule.from_s rule if rule + @rule = (rule ? Grammar::Rule.from_s(rule) : nil) end def arity |