pms 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e737f3b6406adce6fe95366111056f19aa66a0a8
4
+ data.tar.gz: 08778e9a99a3c8097ae295f5d3602e8d45d34ad3
5
+ SHA512:
6
+ metadata.gz: 5a35f3969576b684d09317f79a8bd11fc14b9ab7a1347fa0935ff81a3c0ee5564a1de7af8b6d5f3133a47ce63790a666d3a50c4cd78b49c4d2277c6d6a6b08d7
7
+ data.tar.gz: 9509b550351d1606f039a14a531dfe1b72b19d1e610140ad52ad796f12948020527591e07a70f613a21b8bfe4864b4c87fe22b75aded7aa0ccdcdcc3bcc4faa0
data/ChangeLog CHANGED
@@ -1,5 +1,16 @@
1
+ # markup: rd
2
+
1
3
  = Revision history for pms
2
4
 
5
+ == 0.0.6 [2013-12-19]
6
+
7
+ * Added LSI support.
8
+ * Housekeeping and fixes.
9
+
10
+ == 0.0.5 [2011-04-29]
11
+
12
+ * Housekeeping.
13
+
3
14
  == 0.0.4 [2010-10-24]
4
15
 
5
16
  * Some code cleanup.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to pms version 0.0.5
5
+ This documentation refers to pms version 0.0.6
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -45,19 +45,19 @@ You can find more examples in the <tt>spec/</tt> directory.
45
45
  == LINKS
46
46
 
47
47
  <b></b>
48
- Documentation:: http://pms.rubyforge.org/
49
- Source code:: http://github.com/blackwinter/pms
50
- RubyForge project:: http://rubyforge.org/projects/pms
48
+ Documentation:: http://blackwinter.github.com/pms
49
+ Source code:: http://github.com/blackwinter/pms
50
+ RubyGem:: http://rubygems.org/gems/pms
51
51
 
52
52
 
53
53
  == AUTHORS
54
54
 
55
- * Jens Wille <mailto:jens.wille@uni-koeln.de>
55
+ * Jens Wille <mailto:jens.wille@gmail.com>
56
56
 
57
57
 
58
58
  == LICENSE AND COPYRIGHT
59
59
 
60
- Copyright (C) 2008-2011 Jens Wille
60
+ Copyright (C) 2008-2013 Jens Wille
61
61
 
62
62
  pms is free software: you can redistribute it and/or modify it under the
63
63
  terms of the GNU Affero General Public License as published by the Free
data/Rakefile CHANGED
@@ -4,15 +4,15 @@ begin
4
4
  require 'hen'
5
5
 
6
6
  Hen.lay! {{
7
- :rubyforge => {
8
- :project => %q{pms}
9
- },
10
-
11
7
  :gem => {
12
- :version => PMS::VERSION,
13
- :summary => %q{Poor Man's Search},
14
- :author => %q{Jens Wille},
15
- :email => %q{jens.wille@uni-koeln.de}
8
+ :name => %q{pms},
9
+ :version => PMS::VERSION,
10
+ :summary => %q{Poor Man's Search},
11
+ :author => %q{Jens Wille},
12
+ :email => %q{jens.wille@gmail.com},
13
+ :license => %q{AGPL-3.0},
14
+ :homepage => :blackwinter,
15
+ :dependencies => %w[unicode] << ['ruby-nuggets', '>= 0.9.4']
16
16
  }
17
17
  }}
18
18
  rescue LoadError => err
data/lib/pms.rb CHANGED
@@ -3,10 +3,10 @@
3
3
  # #
4
4
  # pms - Poor Man's Search. #
5
5
  # #
6
- # Copyright (C) 2008-2011 Jens Wille #
6
+ # Copyright (C) 2008-2013 Jens Wille #
7
7
  # #
8
8
  # Authors: #
9
- # Jens Wille <jens.wille@uni-koeln.de> #
9
+ # Jens Wille <jens.wille@gmail.com> #
10
10
  # #
11
11
  # pms is free software; you can redistribute it and/or modify it under the #
12
12
  # terms of the GNU Affero General Public License as published by the Free #
@@ -32,9 +32,9 @@ class PMS
32
32
 
33
33
  attr_reader :input, :index
34
34
 
35
- def initialize(input)
35
+ def initialize(input, options = {})
36
36
  @input = input
37
- @index = Index.new(input)
37
+ @index = Index.new(input, options)
38
38
  end
39
39
 
40
40
  def search(token = nil, &block)
@@ -3,10 +3,10 @@
3
3
  # #
4
4
  # A component of pms, Poor Man's Search. #
5
5
  # #
6
- # Copyright (C) 2008-2011 Jens Wille #
6
+ # Copyright (C) 2008-2013 Jens Wille #
7
7
  # #
8
8
  # Authors: #
9
- # Jens Wille <jens.wille@uni-koeln.de> #
9
+ # Jens Wille <jens.wille@gmail.com> #
10
10
  # #
11
11
  # pms is free software; you can redistribute it and/or modify it under the #
12
12
  # terms of the GNU Affero General Public License as published by the Free #
@@ -3,10 +3,10 @@
3
3
  # #
4
4
  # A component of pms, Poor Man's Search. #
5
5
  # #
6
- # Copyright (C) 2008-2011 Jens Wille #
6
+ # Copyright (C) 2008-2013 Jens Wille #
7
7
  # #
8
8
  # Authors: #
9
- # Jens Wille <jens.wille@uni-koeln.de> #
9
+ # Jens Wille <jens.wille@gmail.com> #
10
10
  # #
11
11
  # pms is free software; you can redistribute it and/or modify it under the #
12
12
  # terms of the GNU Affero General Public License as published by the Free #
@@ -24,19 +24,23 @@
24
24
  ###############################################################################
25
25
  #++
26
26
 
27
+ require 'unicode'
28
+
27
29
  class PMS
28
30
 
29
31
  class Index
30
32
 
31
33
  TOKEN_RE = %r{\w+}
32
34
 
35
+ DEFAULT_LSI = 0.05
36
+
33
37
  attr_reader :input, :index, :entries
34
38
 
35
- def initialize(input)
36
- raise ArgumentError, "input must implement #each" unless input.respond_to?(:each)
39
+ def initialize(input, options = {})
40
+ @input = input.respond_to?(:each) ? input : input.is_a?(String) ?
41
+ input.each_line : raise(ArgumentError, 'input must implement #each')
37
42
 
38
- @input = input
39
- build_index
43
+ build_index(options)
40
44
  end
41
45
 
42
46
  def doc_nums_with_positions(token)
@@ -53,7 +57,7 @@ class PMS
53
57
  res
54
58
  else
55
59
  raise TypeError, "expected String or Regexp, got #{token.class}"
56
- end
60
+ end.each { |_, positions| positions.compact! }
57
61
  end
58
62
 
59
63
  alias_method :results_with_positions, :doc_nums_with_positions
@@ -64,7 +68,7 @@ class PMS
64
68
 
65
69
  alias_method :results, :doc_nums
66
70
 
67
- def documents(doc_nums = default = Object.new)
71
+ def documents(doc_nums = default = true)
68
72
  @documents ||= get_documents
69
73
  default ? @documents : @documents.values_at(*doc_nums)
70
74
  end
@@ -79,7 +83,14 @@ class PMS
79
83
 
80
84
  private
81
85
 
82
- def build_index
86
+ def build_index(options)
87
+ if lsi = options[:lsi]
88
+ require 'nuggets/lsi'
89
+
90
+ lsi = DEFAULT_LSI if lsi == true
91
+ map = Hash.new { |h, k| h[k] = [] }
92
+ end
93
+
83
94
  @documents, @entries, doc_num = nil, [], -1
84
95
  index = Hash.new { |h, k| h[k] = Hash.new { |i, j| i[j] = [] } }
85
96
 
@@ -88,10 +99,15 @@ class PMS
88
99
  pos = -1
89
100
 
90
101
  doc.scan(TOKEN_RE) { |token|
91
- index[mangle_token(token)][doc_num] << pos += 1
102
+ index[term = mangle_token(token)][doc_num] << pos += 1
103
+ map[doc_num] << term if map
92
104
  }
93
105
  }
94
106
 
107
+ Nuggets::LSI.each_norm(map, :min => lsi, :new => true) { |d, k, _|
108
+ index[mangle_token(k)][d.key] << nil
109
+ } if lsi
110
+
95
111
  @index = index
96
112
  end
97
113
 
@@ -104,7 +120,7 @@ class PMS
104
120
  end
105
121
 
106
122
  def mangle_token(token)
107
- token.downcase
123
+ Unicode.downcase(token)
108
124
  end
109
125
 
110
126
  end
@@ -3,10 +3,10 @@
3
3
  # #
4
4
  # A component of pms, Poor Man's Search. #
5
5
  # #
6
- # Copyright (C) 2008-2011 Jens Wille #
6
+ # Copyright (C) 2008-2013 Jens Wille #
7
7
  # #
8
8
  # Authors: #
9
- # Jens Wille <jens.wille@uni-koeln.de> #
9
+ # Jens Wille <jens.wille@gmail.com> #
10
10
  # #
11
11
  # pms is free software; you can redistribute it and/or modify it under the #
12
12
  # terms of the GNU Affero General Public License as published by the Free #
@@ -131,6 +131,15 @@ class PMS
131
131
  alias_method :adj, :adjacent
132
132
  alias_method :^, :adjacent
133
133
 
134
+ private
135
+
136
+ def clone_with_results(results)
137
+ clone = super
138
+ clone.instance_variable_set(:@results_with_positions,
139
+ @results_with_positions.dup.delete_if { |k, _| !results.include?(k) })
140
+ clone
141
+ end
142
+
134
143
  end
135
144
 
136
145
  end
@@ -4,7 +4,7 @@ class PMS
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 0
7
- TINY = 5
7
+ TINY = 6
8
8
 
9
9
  class << self
10
10
 
@@ -44,7 +44,7 @@ shared_examples_for 'most Searchables' do
44
44
 
45
45
  end
46
46
 
47
- describe String, ' when extended by pms' do
47
+ describe String, 'when extended by pms' do
48
48
 
49
49
  before :each do
50
50
  @searchable = File.read(FOX)
@@ -55,7 +55,7 @@ describe String, ' when extended by pms' do
55
55
 
56
56
  end
57
57
 
58
- describe IO, ' when extended by pms' do
58
+ describe IO, 'when extended by pms' do
59
59
 
60
60
  before :each do
61
61
  @searchable = File.open(FOX)
@@ -66,7 +66,7 @@ describe IO, ' when extended by pms' do
66
66
 
67
67
  end
68
68
 
69
- describe Array, ' when extended by pms' do
69
+ describe Array, 'when extended by pms' do
70
70
 
71
71
  before :each do
72
72
  @searchable = File.readlines(FOX)
@@ -77,7 +77,7 @@ describe Array, ' when extended by pms' do
77
77
 
78
78
  end
79
79
 
80
- describe File, ' when extended by pms' do
80
+ describe File, 'when extended by pms' do
81
81
 
82
82
  before :each do
83
83
  @searchable = File
@@ -16,7 +16,7 @@ describe PMS::Index do
16
16
 
17
17
  end
18
18
 
19
- describe PMS::Index, ' with exhaustable input' do
19
+ describe PMS::Index, 'with exhaustable input' do
20
20
 
21
21
  before :each do
22
22
  # already seeks to EOF in #build_index
@@ -28,3 +28,11 @@ describe PMS::Index, ' with exhaustable input' do
28
28
  end
29
29
 
30
30
  end
31
+
32
+ describe PMS::Index, 'with invalid input' do
33
+
34
+ it 'should raise an error' do
35
+ lambda { PMS::Index.new(123) }.should raise_error(ArgumentError)
36
+ end
37
+
38
+ end
@@ -107,3 +107,22 @@ describe PMS do
107
107
  end
108
108
 
109
109
  end
110
+
111
+ describe PMS, 'with LSI' do
112
+
113
+ before :each do
114
+ @pms1 = PMS.new(File.read(FOX))
115
+ @pms2 = PMS.new(File.read(FOX), :lsi => true)
116
+ end
117
+
118
+ it 'should find more ducks' do
119
+ @pms1.search('ducks').results.should == [1]
120
+ @pms2.search('ducks').results.should == [1, 4, 5]
121
+ end
122
+
123
+ it 'should not report positions for LSI terms' do
124
+ @pms1.search('ducks').results_with_positions.values.flatten.should == [12]
125
+ @pms2.search('ducks').results_with_positions.values.flatten.should == [12]
126
+ end
127
+
128
+ end
metadata CHANGED
@@ -1,89 +1,104 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pms
3
- version: !ruby/object:Gem::Version
4
- hash: 21
5
- prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 5
10
- version: 0.0.5
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Jens Wille
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2011-04-29 00:00:00 Z
19
- dependencies: []
20
-
11
+ date: 2013-12-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: unicode
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-nuggets
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.4
21
41
  description: Poor Man's Search
22
- email: jens.wille@uni-koeln.de
42
+ email: jens.wille@gmail.com
23
43
  executables: []
24
-
25
44
  extensions: []
26
-
27
- extra_rdoc_files:
45
+ extra_rdoc_files:
28
46
  - README
29
47
  - COPYING
30
48
  - ChangeLog
31
- files:
49
+ files:
32
50
  - lib/pms.rb
51
+ - lib/pms/ext.rb
33
52
  - lib/pms/index.rb
34
53
  - lib/pms/proxy.rb
35
- - lib/pms/ext.rb
36
54
  - lib/pms/version.rb
37
- - README
55
+ - COPYING
38
56
  - ChangeLog
57
+ - README
39
58
  - Rakefile
40
- - COPYING
41
- - spec/pms/index_spec.rb
59
+ - spec/fox.txt
42
60
  - spec/pms/ext_spec.rb
61
+ - spec/pms/index_spec.rb
43
62
  - spec/pms/proxy_spec.rb
63
+ - spec/pms_spec.rb
44
64
  - spec/spec.opts
45
- - spec/fox.txt
46
65
  - spec/spec_helper.rb
47
- - spec/pms_spec.rb
48
- homepage: http://pms.rubyforge.org/
49
- licenses: []
66
+ homepage: http://github.com/blackwinter/pms
67
+ licenses:
68
+ - AGPL-3.0
69
+ metadata: {}
70
+ post_install_message: |2+
50
71
 
51
- post_install_message:
52
- rdoc_options:
53
- - --line-numbers
54
- - --main
55
- - README
56
- - --charset
72
+ pms-0.0.6 [2013-12-19]:
73
+
74
+ * Added LSI support.
75
+ * Housekeeping and fixes.
76
+
77
+ rdoc_options:
78
+ - "--title"
79
+ - pms Application documentation (v0.0.6)
80
+ - "--charset"
57
81
  - UTF-8
58
- - --all
59
- - --title
60
- - pms Application documentation (v0.0.5)
61
- require_paths:
82
+ - "--line-numbers"
83
+ - "--all"
84
+ - "--main"
85
+ - README
86
+ require_paths:
62
87
  - lib
63
- required_ruby_version: !ruby/object:Gem::Requirement
64
- none: false
65
- requirements:
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
66
90
  - - ">="
67
- - !ruby/object:Gem::Version
68
- hash: 3
69
- segments:
70
- - 0
71
- version: "0"
72
- required_rubygems_version: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
75
95
  - - ">="
76
- - !ruby/object:Gem::Version
77
- hash: 3
78
- segments:
79
- - 0
80
- version: "0"
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
81
98
  requirements: []
82
-
83
- rubyforge_project: pms
84
- rubygems_version: 1.7.2
99
+ rubyforge_project:
100
+ rubygems_version: 2.1.11
85
101
  signing_key:
86
- specification_version: 3
102
+ specification_version: 4
87
103
  summary: Poor Man's Search
88
104
  test_files: []
89
-