pms 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +5 -0
- data/README +6 -6
- data/Rakefile +12 -9
- data/lib/pms/i18n.rb +42 -0
- data/lib/pms/index.rb +12 -12
- data/lib/pms/proxy.rb +18 -16
- data/lib/pms/version.rb +1 -1
- data/spec/pms_spec.rb +2 -2
- data/spec/spec_helper.rb +4 -0
- metadata +73 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82f2df289b312da9511a90eac32ce0d4c0ab580f
|
4
|
+
data.tar.gz: 35aa658fa71100f68a9e857925bbbcc35804df10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e70a4beff1cc219ab22a7637b6dc14d9d3024bf7d4099fe96a36598170a8b48403c1d87efd97be25fb0d5e021a6ba5adc04cf1a56e27147ccc9ea0cb37b51132
|
7
|
+
data.tar.gz: b2fd4b90e1085da74da8fa61860350589d36fdad117cf78f546bdb57100f568b8139aa31b64e7144311de476ed5535f5af2e92a0257ebd96f208482b1588ee36
|
data/ChangeLog
CHANGED
data/README
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
== VERSION
|
4
4
|
|
5
|
-
This documentation refers to pms version 0.0.
|
5
|
+
This documentation refers to pms version 0.0.7
|
6
6
|
|
7
7
|
|
8
8
|
== DESCRIPTION
|
@@ -44,10 +44,10 @@ You can find more examples in the <tt>spec/</tt> directory.
|
|
44
44
|
|
45
45
|
== LINKS
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
Documentation:: https://blackwinter.github.com/pms
|
48
|
+
Source code:: https://github.com/blackwinter/pms
|
49
|
+
RubyGem:: https://rubygems.org/gems/pms
|
50
|
+
Travis CI:: https://travis-ci.org/blackwinter/pms
|
51
51
|
|
52
52
|
|
53
53
|
== AUTHORS
|
@@ -57,7 +57,7 @@ RubyGem:: http://rubygems.org/gems/pms
|
|
57
57
|
|
58
58
|
== LICENSE AND COPYRIGHT
|
59
59
|
|
60
|
-
Copyright (C) 2008-
|
60
|
+
Copyright (C) 2008-2014 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,18 @@ begin
|
|
4
4
|
require 'hen'
|
5
5
|
|
6
6
|
Hen.lay! {{
|
7
|
-
:
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
7
|
+
gem: {
|
8
|
+
name: %q{pms},
|
9
|
+
version: PMS::VERSION,
|
10
|
+
summary: %q{Poor Man's Search},
|
11
|
+
description: %q{A simple searching facility for (nearly) arbitrary input.},
|
12
|
+
author: %q{Jens Wille},
|
13
|
+
email: %q{jens.wille@gmail.com},
|
14
|
+
license: %q{AGPL-3.0},
|
15
|
+
homepage: :blackwinter,
|
16
|
+
dependencies: { lsi4r: ['~> 0.0', '>= 0.0.2'], unicode: '~> 0.4' },
|
17
|
+
|
18
|
+
required_ruby_version: '>= 2.0'
|
16
19
|
}
|
17
20
|
}}
|
18
21
|
rescue LoadError => err
|
data/lib/pms/i18n.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# A component of pms, Poor Man's Search. #
|
5
|
+
# #
|
6
|
+
# Copyright (C) 2008-2014 Jens Wille #
|
7
|
+
# #
|
8
|
+
# Authors: #
|
9
|
+
# Jens Wille <jens.wille@gmail.com> #
|
10
|
+
# #
|
11
|
+
# pms is free software; you can redistribute it and/or modify it under the #
|
12
|
+
# terms of the GNU General Public License as published by the Free Software #
|
13
|
+
# Foundation; either version 3 of the License, or (at your option) any later #
|
14
|
+
# version. #
|
15
|
+
# #
|
16
|
+
# pms is distributed in the hope that it will be useful, but WITHOUT ANY #
|
17
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
18
|
+
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more #
|
19
|
+
# details. #
|
20
|
+
# #
|
21
|
+
# You should have received a copy of the GNU General Public License along #
|
22
|
+
# with pms. If not, see <http://www.gnu.org/licenses/>. #
|
23
|
+
# #
|
24
|
+
###############################################################################
|
25
|
+
#++
|
26
|
+
|
27
|
+
require 'nuggets/i18n'
|
28
|
+
require 'pms'
|
29
|
+
|
30
|
+
class PMS
|
31
|
+
|
32
|
+
module I18n
|
33
|
+
|
34
|
+
def mangle_token(token)
|
35
|
+
super.tap(&:replace_diacritics!)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
Index.prepend(I18n)
|
41
|
+
|
42
|
+
end
|
data/lib/pms/index.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# #
|
4
4
|
# A component of pms, Poor Man's Search. #
|
5
5
|
# #
|
6
|
-
# Copyright (C) 2008-
|
6
|
+
# Copyright (C) 2008-2014 Jens Wille #
|
7
7
|
# #
|
8
8
|
# Authors: #
|
9
9
|
# Jens Wille <jens.wille@gmail.com> #
|
@@ -48,16 +48,12 @@ class PMS
|
|
48
48
|
when String
|
49
49
|
index[mangle_token(token)]
|
50
50
|
when Regexp
|
51
|
-
|
52
|
-
|
53
|
-
index.each { |key, value|
|
54
|
-
res.update(value) { |_, old, new| old | new } if key =~ token
|
51
|
+
index.each_with_object({}) { |(key, value), hash|
|
52
|
+
hash.update(value) { |_, old, new| old | new } if key =~ token
|
55
53
|
}
|
56
|
-
|
57
|
-
res
|
58
54
|
else
|
59
|
-
raise TypeError, "
|
60
|
-
end.
|
55
|
+
raise TypeError, "String or Regexp expected, got #{token.class}"
|
56
|
+
end.each_value(&:compact!)
|
61
57
|
end
|
62
58
|
|
63
59
|
alias_method :results_with_positions, :doc_nums_with_positions
|
@@ -85,7 +81,7 @@ class PMS
|
|
85
81
|
|
86
82
|
def build_index(options)
|
87
83
|
if lsi = options[:lsi]
|
88
|
-
require '
|
84
|
+
require 'lsi4r'
|
89
85
|
|
90
86
|
lsi = DEFAULT_LSI if lsi == true
|
91
87
|
map = Hash.new { |h, k| h[k] = [] }
|
@@ -98,13 +94,13 @@ class PMS
|
|
98
94
|
@entries << doc_num += 1
|
99
95
|
pos = -1
|
100
96
|
|
101
|
-
doc
|
97
|
+
each_token(doc) { |token|
|
102
98
|
index[term = mangle_token(token)][doc_num] << pos += 1
|
103
99
|
map[doc_num] << term if map
|
104
100
|
}
|
105
101
|
}
|
106
102
|
|
107
|
-
|
103
|
+
Lsi4R.each_norm(map, min: lsi, new: true) { |d, k, _|
|
108
104
|
index[mangle_token(k)][d.key] << nil
|
109
105
|
} if lsi
|
110
106
|
|
@@ -119,6 +115,10 @@ class PMS
|
|
119
115
|
docs
|
120
116
|
end
|
121
117
|
|
118
|
+
def each_token(doc, &block)
|
119
|
+
doc.scan(TOKEN_RE, &block)
|
120
|
+
end
|
121
|
+
|
122
122
|
def mangle_token(token)
|
123
123
|
Unicode.downcase(token)
|
124
124
|
end
|
data/lib/pms/proxy.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# #
|
4
4
|
# A component of pms, Poor Man's Search. #
|
5
5
|
# #
|
6
|
-
# Copyright (C) 2008-
|
6
|
+
# Copyright (C) 2008-2014 Jens Wille #
|
7
7
|
# #
|
8
8
|
# Authors: #
|
9
9
|
# Jens Wille <jens.wille@gmail.com> #
|
@@ -51,6 +51,17 @@ class PMS
|
|
51
51
|
alias_method :|, :or
|
52
52
|
alias_method :-, :not
|
53
53
|
|
54
|
+
{ and: :&, or: :|, not: :- }.each { |op, sym|
|
55
|
+
class_eval <<-EOT, __FILE__, __LINE__ + 1
|
56
|
+
def #{op}(token = nil, &block)
|
57
|
+
token ? apply_operator_with_token(#{op.inspect}, token) :
|
58
|
+
apply_operator_with_block(#{op.inspect}, &block)
|
59
|
+
end
|
60
|
+
EOT
|
61
|
+
|
62
|
+
alias_method sym, op
|
63
|
+
}
|
64
|
+
|
54
65
|
private
|
55
66
|
|
56
67
|
def apply_operator_with_token(op, token)
|
@@ -78,9 +89,7 @@ class PMS
|
|
78
89
|
end
|
79
90
|
|
80
91
|
def clone_with_results(results)
|
81
|
-
clone
|
82
|
-
clone.instance_variable_set(:@results, results)
|
83
|
-
clone
|
92
|
+
clone.tap { |clone| clone.instance_variable_set(:@results, results) }
|
84
93
|
end
|
85
94
|
|
86
95
|
end
|
@@ -92,10 +101,8 @@ class PMS
|
|
92
101
|
def initialize(pms, token)
|
93
102
|
super(pms)
|
94
103
|
|
95
|
-
@token = token
|
96
|
-
|
97
104
|
@results_with_positions = index.results_with_positions(token)
|
98
|
-
@results = @results_with_positions.keys
|
105
|
+
@token, @results = token, @results_with_positions.keys
|
99
106
|
end
|
100
107
|
|
101
108
|
def near(token, distance = 1, order = false)
|
@@ -111,15 +118,12 @@ class PMS
|
|
111
118
|
!results1[doc_num].any? { |pos1|
|
112
119
|
positions.find { |pos2|
|
113
120
|
diff = pos2 - pos1
|
114
|
-
|
115
|
-
break if order && diff < 0
|
116
|
-
|
117
|
-
diff.abs <= distance
|
121
|
+
order && diff < 0 ? break : diff.abs <= distance
|
118
122
|
}
|
119
123
|
}
|
120
124
|
}
|
121
125
|
|
122
|
-
apply_operator(
|
126
|
+
apply_operator(:and, doc_nums)
|
123
127
|
end
|
124
128
|
|
125
129
|
alias_method :%, :near
|
@@ -134,10 +138,8 @@ class PMS
|
|
134
138
|
private
|
135
139
|
|
136
140
|
def clone_with_results(results)
|
137
|
-
clone
|
138
|
-
|
139
|
-
@results_with_positions.dup.delete_if { |k, _| !results.include?(k) })
|
140
|
-
clone
|
141
|
+
super.tap { |clone| clone.instance_variable_set(:@results_with_positions,
|
142
|
+
@results_with_positions.dup.delete_if { |k, _| !results.include?(k) }) }
|
141
143
|
end
|
142
144
|
|
143
145
|
end
|
data/lib/pms/version.rb
CHANGED
data/spec/pms_spec.rb
CHANGED
@@ -112,12 +112,12 @@ describe PMS, 'with LSI' do
|
|
112
112
|
|
113
113
|
before :each do
|
114
114
|
@pms1 = PMS.new(File.read(FOX))
|
115
|
-
@pms2 = PMS.new(File.read(FOX), :
|
115
|
+
@pms2 = PMS.new(File.read(FOX), lsi: true)
|
116
116
|
end
|
117
117
|
|
118
118
|
it 'should find more ducks' do
|
119
119
|
@pms1.search('ducks').results.should == [1]
|
120
|
-
@pms2.search('ducks').results.should == [1, 4,
|
120
|
+
@pms2.search('ducks').results.should == [1, 4, 6]
|
121
121
|
end
|
122
122
|
|
123
123
|
it 'should not report positions for LSI terms' do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,23 +1,77 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Wille
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: lsi4r
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.0.2
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.0.2
|
13
33
|
- !ruby/object:Gem::Dependency
|
14
34
|
name: unicode
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0.4'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0.4'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: hen
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0.8'
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 0.8.1
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0.8'
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 0.8.1
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: rake
|
15
69
|
requirement: !ruby/object:Gem::Requirement
|
16
70
|
requirements:
|
17
71
|
- - ">="
|
18
72
|
- !ruby/object:Gem::Version
|
19
73
|
version: '0'
|
20
|
-
type: :
|
74
|
+
type: :development
|
21
75
|
prerelease: false
|
22
76
|
version_requirements: !ruby/object:Gem::Requirement
|
23
77
|
requirements:
|
@@ -25,20 +79,20 @@ dependencies:
|
|
25
79
|
- !ruby/object:Gem::Version
|
26
80
|
version: '0'
|
27
81
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
82
|
+
name: rspec
|
29
83
|
requirement: !ruby/object:Gem::Requirement
|
30
84
|
requirements:
|
31
85
|
- - ">="
|
32
86
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0
|
34
|
-
type: :
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
35
89
|
prerelease: false
|
36
90
|
version_requirements: !ruby/object:Gem::Requirement
|
37
91
|
requirements:
|
38
92
|
- - ">="
|
39
93
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0
|
41
|
-
description:
|
94
|
+
version: '0'
|
95
|
+
description: A simple searching facility for (nearly) arbitrary input.
|
42
96
|
email: jens.wille@gmail.com
|
43
97
|
executables: []
|
44
98
|
extensions: []
|
@@ -47,15 +101,16 @@ extra_rdoc_files:
|
|
47
101
|
- COPYING
|
48
102
|
- ChangeLog
|
49
103
|
files:
|
104
|
+
- COPYING
|
105
|
+
- ChangeLog
|
106
|
+
- README
|
107
|
+
- Rakefile
|
50
108
|
- lib/pms.rb
|
51
109
|
- lib/pms/ext.rb
|
110
|
+
- lib/pms/i18n.rb
|
52
111
|
- lib/pms/index.rb
|
53
112
|
- lib/pms/proxy.rb
|
54
113
|
- lib/pms/version.rb
|
55
|
-
- COPYING
|
56
|
-
- ChangeLog
|
57
|
-
- README
|
58
|
-
- Rakefile
|
59
114
|
- spec/fox.txt
|
60
115
|
- spec/pms/ext_spec.rb
|
61
116
|
- spec/pms/index_spec.rb
|
@@ -69,14 +124,14 @@ licenses:
|
|
69
124
|
metadata: {}
|
70
125
|
post_install_message: |2+
|
71
126
|
|
72
|
-
pms-0.0.
|
127
|
+
pms-0.0.7 [2014-12-19]:
|
73
128
|
|
74
|
-
*
|
75
|
-
*
|
129
|
+
* Requires at least Ruby 2.0.
|
130
|
+
* Slightly refactored.
|
76
131
|
|
77
132
|
rdoc_options:
|
78
133
|
- "--title"
|
79
|
-
- pms Application documentation (v0.0.
|
134
|
+
- pms Application documentation (v0.0.7)
|
80
135
|
- "--charset"
|
81
136
|
- UTF-8
|
82
137
|
- "--line-numbers"
|
@@ -89,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
144
|
requirements:
|
90
145
|
- - ">="
|
91
146
|
- !ruby/object:Gem::Version
|
92
|
-
version: '0'
|
147
|
+
version: '2.0'
|
93
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
149
|
requirements:
|
95
150
|
- - ">="
|
@@ -97,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
152
|
version: '0'
|
98
153
|
requirements: []
|
99
154
|
rubyforge_project:
|
100
|
-
rubygems_version: 2.
|
155
|
+
rubygems_version: 2.4.5
|
101
156
|
signing_key:
|
102
157
|
specification_version: 4
|
103
158
|
summary: Poor Man's Search
|