summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-09-27 15:17:43 +0100
committerPatrick Simianer <p@simianer.de>2014-09-27 15:17:43 +0100
commitf65e428784cfd2264f3fdfddd574c37acd38f54f (patch)
tree6a98f82964cbce52957a2d62f8b2c5b7ff8be095 /lib
parentf28694f9bdd5059050e420cca2ca2694cbb0dda4 (diff)
cosmetic changes, bump to 1.1
Diffstat (limited to 'lib')
-rwxr-xr-xlib/zipf.rb3
-rw-r--r--lib/zipf/SparseVector.rb1
-rw-r--r--lib/zipf/bleu.rb2
-rw-r--r--lib/zipf/dag.rb2
-rw-r--r--lib/zipf/fileutil.rb1
-rw-r--r--lib/zipf/grammar.rb123
-rw-r--r--lib/zipf/hypergraph.rb (renamed from lib/zipf/hg.rb)3
-rw-r--r--lib/zipf/misc.rb1
-rw-r--r--lib/zipf/tfidf.rb1
9 files changed, 1 insertions, 136 deletions
diff --git a/lib/zipf.rb b/lib/zipf.rb
index 2f59ccc..681e2cd 100755
--- a/lib/zipf.rb
+++ b/lib/zipf.rb
@@ -9,8 +9,7 @@ require 'zipf/dag'
require 'zipf/semirings'
require 'zipf/bleu'
require 'zipf/misc'
-require 'zipf/hg'
-require 'zipf/grammar'
+require 'zipf/hypergraph'
STDIN.set_encoding 'utf-8'
STDOUT.set_encoding 'utf-8'
diff --git a/lib/zipf/SparseVector.rb b/lib/zipf/SparseVector.rb
index 3f950c4..e9af799 100644
--- a/lib/zipf/SparseVector.rb
+++ b/lib/zipf/SparseVector.rb
@@ -1,6 +1,5 @@
require 'json'
-
class SparseVector < Hash
def initialize arg=nil
diff --git a/lib/zipf/bleu.rb b/lib/zipf/bleu.rb
index 69de00b..c07315e 100644
--- a/lib/zipf/bleu.rb
+++ b/lib/zipf/bleu.rb
@@ -1,6 +1,5 @@
module BLEU
-
class BLEU::NgramCounts
attr_accessor :sum, :clipped, :ref_len, :hyp_len, :n
@@ -125,6 +124,5 @@ def BLEU::per_sentence_bleu hypothesis, reference, n=4, smooth=0.0
return Math.exp logbleu
end
-
end #module
diff --git a/lib/zipf/dag.rb b/lib/zipf/dag.rb
index 45ede20..a0edde7 100644
--- a/lib/zipf/dag.rb
+++ b/lib/zipf/dag.rb
@@ -2,7 +2,6 @@ module DAG
require 'json'
-
class DAG::Node
attr_accessor :label, :outgoing, :incoming, :score, :mark
@@ -200,6 +199,5 @@ def DAG::read_graph_from_json fn, semiring=RealSemiring.new
return graph, nodes_by_label
end
-
end #module
diff --git a/lib/zipf/fileutil.rb b/lib/zipf/fileutil.rb
index eb69136..ac701da 100644
--- a/lib/zipf/fileutil.rb
+++ b/lib/zipf/fileutil.rb
@@ -1,6 +1,5 @@
require 'zlib'
-
class ReadFile
def initialize fn, encoding='utf-8'
diff --git a/lib/zipf/grammar.rb b/lib/zipf/grammar.rb
deleted file mode 100644
index 568b9fc..0000000
--- a/lib/zipf/grammar.rb
+++ /dev/null
@@ -1,123 +0,0 @@
-module Grammar
-
-
-class T
- attr_accessor :word
-
- def initialize word
- @word = word
- end
-
- def to_s
- "T<#{@word}>"
- end
-end
-
-class NT
- attr_accessor :symbol, :index, :span
-
- def initialize symbol, index=0
- @symbol = symbol
- @index = index
- @span = Span.new
- end
-
- def to_s
- "NT(#{@span.left},#{@span.right})<#{@symbol},#{@index}>"
- end
-end
-
-class Rule
- attr_accessor :lhs, :rhs, :e
-
- def initialize lhs=nil, rhs=[], e=''
- @lhs = lhs
- @rhs = rhs
- @e = e
- end
-
- def to_s
- "#{lhs} -> #{rhs.map{ |i| i.to_s }.join ' '} [arity=#{arity}] ||| #{@e}"
- end
-
- def arity
- rhs.select { |i| i.class == NT }.size
- end
-
- def from_s s
- _ = splitpipe s, 3
- @lhs = NT.new _[0].strip.gsub!(/(\[|\])/, "")
- _[1].split.each { |x|
- x.strip!
- if x[0]=='[' && x[x.size-1] == ']'
- @rhs << NT.new(x.gsub!(/(\[|\])/, "").split(',')[0])
- else
- @rhs << T.new(x)
- end
- }
- @e = _[2]
- end
-
- def self.from_s s
- r = self.new
- r.from_s s
- return r
- end
-end
-
-class Span
- attr_accessor :left, :right
-
- def initialize left=nil, right=nil
- @left = left
- @right = right
- end
-end
-
-class Grammar
- attr_accessor :rules, :startn, :startt, :flat
-
- def initialize fn
- @rules = []; @startn = []; @startt = [] ;@flat = []
- ReadFile.readlines_strip(fn).each_with_index { |s,i|
- STDERR.write '.'; STDERR.write " #{i+1}\n" if (i+1)%80==0
- @rules << Rule.from_s(s)
- if @rules.last.rhs.first.class == NT
- @startn << @rules.last
- else
- if rules.last.arity == 0
- @flat << @rules.last
- else
- @startt << @rules.last
- end
- end
- }
- STDERR.write "\n"
- end
-
- def to_s
- s = ''
- @rules.each { |r| s += r.to_s+"\n" }
- return s
- end
-
- def add_glue_rules
- @rules.map { |r| r.lhs.symbol }.select { |s| s != 'S' }.uniq.each { |symbol|
- @rules << Rule.new(NT.new('S'), [NT.new(symbol)])
- @startn << @rules.last
- @rules << Rule.new(NT.new('S'), [NT.new('S'), NT.new('X')])
- @startn << @rules.last
- }
- end
-
- def add_pass_through_rules s
- s.each { |word|
- @rules << Rule.new(NT.new('X'), [T.new(word)])
- @flat << @rules.last
- }
- end
-end
-
-
-end #module
-
diff --git a/lib/zipf/hg.rb b/lib/zipf/hypergraph.rb
index f86bf60..6666062 100644
--- a/lib/zipf/hg.rb
+++ b/lib/zipf/hypergraph.rb
@@ -3,10 +3,8 @@
require_relative 'semirings'
require 'json'
-
module HG
-
class HG::Node
attr_accessor :label, :cat, :outgoing, :incoming, :score
@@ -168,6 +166,5 @@ def HG::all_paths hypergraph, root, semiring=ViterbiSemiring.new
return paths
end
-
end #module
diff --git a/lib/zipf/misc.rb b/lib/zipf/misc.rb
index 0319a5f..4d29a06 100644
--- a/lib/zipf/misc.rb
+++ b/lib/zipf/misc.rb
@@ -1,6 +1,5 @@
require 'timeout'
-
class Array
def max_index
self.index(self.max)
diff --git a/lib/zipf/tfidf.rb b/lib/zipf/tfidf.rb
index 13a40a3..7fb92c9 100644
--- a/lib/zipf/tfidf.rb
+++ b/lib/zipf/tfidf.rb
@@ -1,6 +1,5 @@
module TFIDF
-
# returns key='raw frequency' for an
# array-like object
def TFIDF::tf array, stopwords=[]