lsi4r 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c34d7f418bac80657aa021566b252720cffa221c
4
- data.tar.gz: c4a66f3dda978161ede1c8621973295bcb541de8
3
+ metadata.gz: 11274faeb5bb9ff57ac6a754557277e8909f364d
4
+ data.tar.gz: 5c847ce88b0cede7bb61484093ca0b8b2206d280
5
5
  SHA512:
6
- metadata.gz: df1f502ca56b19e70f2dfeaaf099223950dae3d17939f5bb716bec7db2b4fd2d1adfbcc78c74c2042c12dee70e616c4a4ca28d3b529dd32e408905cc0795c92c
7
- data.tar.gz: 01998370603677234cc9dbc7ff1f18773a16e8923ec7ebb0517567eb8cd3f5a26699dd97e44bfe82172c2cd245ce8356ed85357b0ce2483a8eeca716157ae29e
6
+ metadata.gz: b799a06192727adcf04984a9afa1379f055d72f081264c6bde2c99db350f6bee43b152b316e7ecd27a62ce3e436114002d27cf31308015daa3ddbddf6a5f5f2d
7
+ data.tar.gz: b0111b1e1d78b1ba1dbcd89cdbe2613a960f0cf9e99461c5d4e8f82111f1321a5ffa234457301f359ed9154e9ca0f8a41c498fd33aa2b9d697c25585067a0a81
data/ChangeLog CHANGED
@@ -2,7 +2,11 @@
2
2
 
3
3
  = Revision history for lsi4r
4
4
 
5
- == 0.0.2 [unreleased]
5
+ == 0.0.3 [2015-08-14]
6
+
7
+ * Refactored Lsi4R#each_vector and Lsi4R::Doc#initialize.
8
+
9
+ == 0.0.2 [2014-12-19]
6
10
 
7
11
  * Fixed Lsi4R::Doc#transform= with regard to non-Symbol/String transforms.
8
12
  * Added Lsi4R#each_vector, extracted from Lsi4R#each_term.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to lsi4r version 0.0.2
5
+ This documentation refers to lsi4r version 0.0.3
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -27,7 +27,7 @@ Travis CI:: https://travis-ci.org/blackwinter/lsi4r
27
27
 
28
28
  == LICENSE AND COPYRIGHT
29
29
 
30
- Copyright (C) 2014 Jens Wille
30
+ Copyright (C) 2014-2015 Jens Wille
31
31
 
32
32
  lsi4r is free software: you can redistribute it and/or modify it
33
33
  under the terms of the GNU Affero General Public License as published by
@@ -3,7 +3,7 @@
3
3
  # #
4
4
  # lsi4r -- Latent semantic indexing for Ruby #
5
5
  # #
6
- # Copyright (C) 2014 Jens Wille #
6
+ # Copyright (C) 2014-2015 Jens Wille #
7
7
  # #
8
8
  # Authors: #
9
9
  # Jens Wille <jens.wille@gmail.com> #
@@ -83,11 +83,16 @@ class Lsi4R
83
83
  def each_vector(key = nil, norm = true)
84
84
  return enum_for(:each_vector, key, norm) unless block_given?
85
85
 
86
- (key ? [self[key]] : docs).each { |doc|
87
- if doc && vec = norm ? doc.norm : doc.vector
88
- yield doc, vec
89
- end
86
+ block = lambda { |doc|
87
+ vec = norm ? doc.norm : doc.vector
88
+ yield doc, vec if vec
90
89
  }
90
+
91
+ key.nil? ? docs.each(&block) : begin
92
+ doc = self[key] and block[doc]
93
+ end
94
+
95
+ self
91
96
  end
92
97
 
93
98
  # min:: minimum value to consider
@@ -117,6 +122,8 @@ class Lsi4R
117
122
  each_term(key, options.merge(norm: true), &block)
118
123
  end
119
124
 
125
+ alias_method :each, :each_norm
126
+
120
127
  def related(key, num = 5)
121
128
  each_vector(key) { |_, vec|
122
129
  tmp, del = block_given? ? yield(vec) :
@@ -147,6 +154,8 @@ class Lsi4R
147
154
  def reset
148
155
  @hash, @list, @freq, @invlist =
149
156
  {}, Hash.new { |h, k| h[k] = h.size }, Hash.new(0), {}
157
+
158
+ self
150
159
  end
151
160
 
152
161
  def inspect
@@ -3,7 +3,7 @@
3
3
  # #
4
4
  # lsi4r -- Latent semantic indexing for Ruby #
5
5
  # #
6
- # Copyright (C) 2014 Jens Wille #
6
+ # Copyright (C) 2014-2015 Jens Wille #
7
7
  # #
8
8
  # Authors: #
9
9
  # Jens Wille <jens.wille@gmail.com> #
@@ -59,12 +59,11 @@ class Lsi4R
59
59
  end
60
60
 
61
61
  def initialize(key, value, list, freq)
62
- @key, @list, @freq, @total = key, list, freq, 1
62
+ @key, @list, @freq, @total, @map = key, list, freq, 1, hash = Hash.new(0)
63
63
 
64
- @map = !value.is_a?(Hash) ? build_hash(value, list) :
65
- value.inject({}) { |h, (k, v)| h[list[k]] = v; h }
66
-
67
- @map.each_key { |k| freq[k] += 1 }
64
+ value.is_a?(Hash) ?
65
+ value.each { |k, v| hash[i = list[k]] = v; freq[i] += 1 } :
66
+ build_hash(value, list, hash).each_key { |i| freq[i] += 1 }
68
67
 
69
68
  self.vector = raw_vector
70
69
  end
@@ -110,7 +109,7 @@ class Lsi4R
110
109
 
111
110
  private
112
111
 
113
- def build_hash(value, list, hash = Hash.new(0))
112
+ def build_hash(value, list, hash)
114
113
  build_enum(value).each { |i| hash[list[i]] += 1 }
115
114
  hash
116
115
  end
@@ -4,7 +4,7 @@ class Lsi4R
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 0
7
- TINY = 2
7
+ TINY = 3
8
8
 
9
9
  class << self
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lsi4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Wille
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-19 00:00:00.000000000 Z
11
+ date: 2015-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rb-gsl
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: '0.8'
34
34
  - - ">="
35
35
  - !ruby/object:Gem::Version
36
- version: 0.8.1
36
+ version: 0.8.3
37
37
  type: :development
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0.8'
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: 0.8.1
46
+ version: 0.8.3
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -80,15 +80,13 @@ licenses:
80
80
  metadata: {}
81
81
  post_install_message: |2+
82
82
 
83
- lsi4r-0.0.2 [unreleased]:
83
+ lsi4r-0.0.3 [2015-08-14]:
84
84
 
85
- * Fixed Lsi4R::Doc#transform= with regard to non-Symbol/String transforms.
86
- * Added Lsi4R#each_vector, extracted from Lsi4R#each_term.
87
- * Refactored Lsi4R#related and Lsi4R#related_score.
85
+ * Refactored Lsi4R#each_vector and Lsi4R::Doc#initialize.
88
86
 
89
87
  rdoc_options:
90
88
  - "--title"
91
- - lsi4r Application documentation (v0.0.2)
89
+ - lsi4r Application documentation (v0.0.3)
92
90
  - "--charset"
93
91
  - UTF-8
94
92
  - "--line-numbers"
@@ -109,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
107
  version: '0'
110
108
  requirements: []
111
109
  rubyforge_project:
112
- rubygems_version: 2.4.5
110
+ rubygems_version: 2.4.8
113
111
  signing_key:
114
112
  specification_version: 4
115
113
  summary: Latent semantic indexing for Ruby.