zipf 1.0.3 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4aac67c7168dbcf85aa211ec579cd47316ba3e3d
4
- data.tar.gz: 5263572ce34158227f6615ead03755e36a3175f6
3
+ metadata.gz: fdbe716da58c6e94e0f7066226378cc113799088
4
+ data.tar.gz: 9c7a4d0c26ad22a5df8e51a3b794b3bcbf348883
5
5
  SHA512:
6
- metadata.gz: 587d0e910acf176725667123b9cfffcd1692decaaddb11cb1656066d08dd862da120a86065c3e28b5f9e8fd79d7c86e9c3efd90654cb396133d023da2e9c7b63
7
- data.tar.gz: 39688a72137f1c1741a442b168002defd1134394ec87e25c0101ff38cf1cef03ebbccab70053c2f75eae6084f5c573deac864cc026d18d4a37d4f55b4e57c680
6
+ metadata.gz: 170b92d1d017ca7ac701e77723fd79b4a4a9c74414b5c6445da0929e89ff919c59006be4493b641f0a96c63b073b9c7258c65b4497f9071fbd96c209f2820ce8
7
+ data.tar.gz: 8267eeeb569ce8b9f92a2d1471825a39f8d786802caccdd9c66164e459b2648a950eb828135d0011b29d1e4e6744815ccbee48c7c71151335d04bd3f09edff8b
@@ -1,16 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'zipf/stringutil'
3
+ require 'zipf/bleu'
4
+ require 'zipf/dag'
4
5
  require 'zipf/fileutil'
6
+ require 'zipf/hypergraph'
7
+ require 'zipf/misc'
8
+ require 'zipf/semirings'
5
9
  require 'zipf/SparseVector'
10
+ require 'zipf/stringutil'
6
11
  require 'zipf/tfidf'
7
12
  require 'zipf/Translation'
8
- require 'zipf/dag'
9
- require 'zipf/semirings'
10
- require 'zipf/bleu'
11
- require 'zipf/misc'
12
- require 'zipf/hg'
13
- require 'zipf/grammar'
14
13
 
15
14
  STDIN.set_encoding 'utf-8'
16
15
  STDOUT.set_encoding 'utf-8'
@@ -1,6 +1,5 @@
1
1
  require 'json'
2
2
 
3
-
4
3
  class SparseVector < Hash
5
4
 
6
5
  def initialize arg=nil
@@ -1,6 +1,5 @@
1
1
  module BLEU
2
2
 
3
-
4
3
  class BLEU::NgramCounts
5
4
  attr_accessor :sum, :clipped, :ref_len, :hyp_len, :n
6
5
 
@@ -125,6 +124,5 @@ def BLEU::per_sentence_bleu hypothesis, reference, n=4, smooth=0.0
125
124
  return Math.exp logbleu
126
125
  end
127
126
 
128
-
129
127
  end #module
130
128
 
@@ -2,7 +2,6 @@ module DAG
2
2
 
3
3
  require 'json'
4
4
 
5
-
6
5
  class DAG::Node
7
6
  attr_accessor :label, :outgoing, :incoming, :score, :mark
8
7
 
@@ -200,6 +199,5 @@ def DAG::read_graph_from_json fn, semiring=RealSemiring.new
200
199
  return graph, nodes_by_label
201
200
  end
202
201
 
203
-
204
202
  end #module
205
203
 
@@ -1,6 +1,5 @@
1
1
  require 'zlib'
2
2
 
3
-
4
3
  class ReadFile
5
4
 
6
5
  def initialize fn, encoding='utf-8'
@@ -3,10 +3,8 @@
3
3
  require_relative 'semirings'
4
4
  require 'json'
5
5
 
6
-
7
6
  module HG
8
7
 
9
-
10
8
  class HG::Node
11
9
  attr_accessor :label, :cat, :outgoing, :incoming, :score
12
10
 
@@ -168,6 +166,5 @@ def HG::all_paths hypergraph, root, semiring=ViterbiSemiring.new
168
166
  return paths
169
167
  end
170
168
 
171
-
172
169
  end #module
173
170
 
@@ -1,6 +1,5 @@
1
1
  require 'timeout'
2
2
 
3
-
4
3
  class Array
5
4
  def max_index
6
5
  self.index(self.max)
@@ -1,6 +1,5 @@
1
1
  module TFIDF
2
2
 
3
-
4
3
  # returns key='raw frequency' for an
5
4
  # array-like object
6
5
  def TFIDF::tf array, stopwords=[]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zipf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Simianer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-17 00:00:00.000000000 Z
11
+ date: 2014-09-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: NLP related tools and classes
14
14
  email: p@simianer.de
@@ -19,12 +19,11 @@ files:
19
19
  - lib/zipf.rb
20
20
  - lib/zipf/stringutil.rb
21
21
  - lib/zipf/misc.rb
22
- - lib/zipf/grammar.rb
23
- - lib/zipf/hg.rb
24
22
  - lib/zipf/fileutil.rb
25
23
  - lib/zipf/semirings.rb
26
24
  - lib/zipf/dag.rb
27
25
  - lib/zipf/SparseVector.rb
26
+ - lib/zipf/hypergraph.rb
28
27
  - lib/zipf/tfidf.rb
29
28
  - lib/zipf/bleu.rb
30
29
  - lib/zipf/Translation.rb
@@ -48,7 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
47
  version: '0'
49
48
  requirements: []
50
49
  rubyforge_project:
51
- rubygems_version: 2.0.3
50
+ rubygems_version: 2.0.14
52
51
  signing_key:
53
52
  specification_version: 4
54
53
  summary: zipf
@@ -1,123 +0,0 @@
1
- module Grammar
2
-
3
-
4
- class T
5
- attr_accessor :word
6
-
7
- def initialize word
8
- @word = word
9
- end
10
-
11
- def to_s
12
- "T<#{@word}>"
13
- end
14
- end
15
-
16
- class NT
17
- attr_accessor :symbol, :index, :span
18
-
19
- def initialize symbol, index=0
20
- @symbol = symbol
21
- @index = index
22
- @span = Span.new
23
- end
24
-
25
- def to_s
26
- "NT(#{@span.left},#{@span.right})<#{@symbol},#{@index}>"
27
- end
28
- end
29
-
30
- class Rule
31
- attr_accessor :lhs, :rhs, :e
32
-
33
- def initialize lhs=nil, rhs=[], e=''
34
- @lhs = lhs
35
- @rhs = rhs
36
- @e = e
37
- end
38
-
39
- def to_s
40
- "#{lhs} -> #{rhs.map{ |i| i.to_s }.join ' '} [arity=#{arity}] ||| #{@e}"
41
- end
42
-
43
- def arity
44
- rhs.select { |i| i.class == NT }.size
45
- end
46
-
47
- def from_s s
48
- _ = splitpipe s, 3
49
- @lhs = NT.new _[0].strip.gsub!(/(\[|\])/, "")
50
- _[1].split.each { |x|
51
- x.strip!
52
- if x[0]=='[' && x[x.size-1] == ']'
53
- @rhs << NT.new(x.gsub!(/(\[|\])/, "").split(',')[0])
54
- else
55
- @rhs << T.new(x)
56
- end
57
- }
58
- @e = _[2]
59
- end
60
-
61
- def self.from_s s
62
- r = self.new
63
- r.from_s s
64
- return r
65
- end
66
- end
67
-
68
- class Span
69
- attr_accessor :left, :right
70
-
71
- def initialize left=nil, right=nil
72
- @left = left
73
- @right = right
74
- end
75
- end
76
-
77
- class Grammar
78
- attr_accessor :rules, :startn, :startt, :flat
79
-
80
- def initialize fn
81
- @rules = []; @startn = []; @startt = [] ;@flat = []
82
- ReadFile.readlines_strip(fn).each_with_index { |s,i|
83
- STDERR.write '.'; STDERR.write " #{i+1}\n" if (i+1)%80==0
84
- @rules << Rule.from_s(s)
85
- if @rules.last.rhs.first.class == NT
86
- @startn << @rules.last
87
- else
88
- if rules.last.arity == 0
89
- @flat << @rules.last
90
- else
91
- @startt << @rules.last
92
- end
93
- end
94
- }
95
- STDERR.write "\n"
96
- end
97
-
98
- def to_s
99
- s = ''
100
- @rules.each { |r| s += r.to_s+"\n" }
101
- return s
102
- end
103
-
104
- def add_glue_rules
105
- @rules.map { |r| r.lhs.symbol }.select { |s| s != 'S' }.uniq.each { |symbol|
106
- @rules << Rule.new(NT.new('S'), [NT.new(symbol)])
107
- @startn << @rules.last
108
- @rules << Rule.new(NT.new('S'), [NT.new('S'), NT.new('X')])
109
- @startn << @rules.last
110
- }
111
- end
112
-
113
- def add_pass_through_rules s
114
- s.each { |word|
115
- @rules << Rule.new(NT.new('X'), [T.new(word)])
116
- @flat << @rules.last
117
- }
118
- end
119
- end
120
-
121
-
122
- end #module
123
-