pms 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,5 +1,17 @@
1
1
  = Revision history for pms
2
2
 
3
+ == 0.0.4 [2010-10-24]
4
+
5
+ * Some code cleanup.
6
+
7
+ == 0.0.3 [2010-02-18]
8
+
9
+ * Added some handy operator aliases.
10
+
11
+ == 0.0.2 [2008-12-09]
12
+
13
+ * Fixed handling of Proxy internals.
14
+
3
15
  == 0.0.1 [2008-12-06]
4
16
 
5
17
  * Birthday :-)
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to pms version 0.0.3
5
+ This documentation refers to pms version 0.0.4
6
6
 
7
7
 
8
8
  == DESCRIPTION
data/TODO ADDED
@@ -0,0 +1,3 @@
1
+ - positions w/ NEAR + ADJ
2
+ - specs (positions, i18n)
3
+ - docu
data/lib/pms.rb CHANGED
@@ -24,6 +24,7 @@
24
24
  ###############################################################################
25
25
  #++
26
26
 
27
+ require 'pms/version'
27
28
  require 'pms/index'
28
29
  require 'pms/proxy'
29
30
 
@@ -36,8 +37,8 @@ class PMS
36
37
  @index = Index.new(input)
37
38
  end
38
39
 
39
- def search(token = nil)
40
- token ? TokenProxy.new(self, token) : Proxy.new(self).and { |*a| yield(*a) }
40
+ def search(token = nil, &block)
41
+ token ? TokenProxy.new(self, token) : Proxy.new(self).and(&block)
41
42
  end
42
43
 
43
44
  alias_method :/, :search
data/lib/pms/ext.rb CHANGED
@@ -28,15 +28,13 @@ require 'pms'
28
28
 
29
29
  module PMS::Ext
30
30
 
31
- RECEIVERS = [String, IO, Array].freeze
32
-
33
- def search(*args)
34
- PMS.new(self).search(*args)
31
+ def search(*args, &block)
32
+ PMS.new(self).search(*args, &block)
35
33
  end
36
34
 
37
35
  alias_method :/, :search
38
36
 
39
- RECEIVERS.each { |klass|
37
+ [String, IO, Array].each { |klass|
40
38
  klass.send(:include, self)
41
39
  }
42
40
 
@@ -44,8 +42,9 @@ end
44
42
 
45
43
  class << File
46
44
 
47
- def search(file, *args)
48
- open(file.respond_to?(:path) ? file.path : file) { |f| f.search(*args) }
45
+ def search(file, *args, &block)
46
+ file = file.path if file.respond_to?(:path)
47
+ open(file) { |f| f.search(*args, &block) }
49
48
  end
50
49
 
51
50
  end
data/lib/pms/i18n.rb ADDED
@@ -0,0 +1,44 @@
1
+ #--
2
+ ###############################################################################
3
+ # #
4
+ # A component of pms, Poor Man's Search. #
5
+ # #
6
+ # Copyright (C) 2008-2010 Jens Wille #
7
+ # #
8
+ # Authors: #
9
+ # Jens Wille <jens.wille@uni-koeln.de> #
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/util/i18n'
28
+ require 'pms'
29
+
30
+ class PMS
31
+
32
+ class Index
33
+
34
+ alias_method :_pms_i18n_original_mangle_token, :mangle_token
35
+
36
+ def mangle_token(token)
37
+ token = _pms_i18n_original_mangle_token(token)
38
+ token.replace_diacritics!
39
+ token
40
+ end
41
+
42
+ end
43
+
44
+ end
data/lib/pms/index.rb CHANGED
@@ -28,7 +28,7 @@ class PMS
28
28
 
29
29
  class Index
30
30
 
31
- TOKEN_RE = %r{\w+}o
31
+ TOKEN_RE = %r{\w+}
32
32
 
33
33
  attr_reader :input, :index, :entries
34
34
 
@@ -36,8 +36,6 @@ class PMS
36
36
  raise ArgumentError, "input must implement #each" unless input.respond_to?(:each)
37
37
 
38
38
  @input = input
39
- @index = Hash.new { |h, k| h[k] = Hash.new { |i, j| i[j] = [] } }
40
-
41
39
  build_index
42
40
  end
43
41
 
@@ -82,8 +80,8 @@ class PMS
82
80
  private
83
81
 
84
82
  def build_index
85
- @documents, @entries = nil, []
86
- doc_num = -1
83
+ @documents, @entries, doc_num = nil, [], -1
84
+ index = Hash.new { |h, k| h[k] = Hash.new { |i, j| i[j] = [] } }
87
85
 
88
86
  input.each { |doc|
89
87
  @entries << doc_num += 1
@@ -93,6 +91,8 @@ class PMS
93
91
  index[mangle_token(token)][doc_num] << pos += 1
94
92
  }
95
93
  }
94
+
95
+ @index = index
96
96
  end
97
97
 
98
98
  def get_documents
data/lib/pms/proxy.rb CHANGED
@@ -36,31 +36,21 @@ class PMS
36
36
  @results = pms.results
37
37
  end
38
38
 
39
- def and(token = nil)
40
- token ? apply_operator_with_token('and', token) :
41
- apply_operator_with_block('and') { |*a| yield(*a) }
39
+ def matches
40
+ index.matches(results)
42
41
  end
43
42
 
44
- alias_method :&, :and
45
-
46
- def or(token = nil)
47
- token ? apply_operator_with_token('or', token) :
48
- apply_operator_with_block('or') { |*a| yield(*a) }
49
- end
43
+ %w[and or not].each { |op| class_eval %Q{
44
+ def #{op}(token = nil, &block)
45
+ token ? apply_operator_with_token(#{op.inspect}, token) :
46
+ apply_operator_with_block(#{op.inspect}, &block)
47
+ end
48
+ } }
50
49
 
50
+ alias_method :&, :and
51
51
  alias_method :|, :or
52
-
53
- def not(token = nil)
54
- token ? apply_operator_with_token('not', token) :
55
- apply_operator_with_block('not') { |*a| yield(*a) }
56
- end
57
-
58
52
  alias_method :-, :not
59
53
 
60
- def matches
61
- index.matches(results)
62
- end
63
-
64
54
  private
65
55
 
66
56
  def apply_operator_with_token(op, token)
@@ -69,10 +59,8 @@ class PMS
69
59
 
70
60
  def apply_operator_with_block(op)
71
61
  case sub = yield(pms)
72
- when Proxy
73
- apply_operator(op, sub.results)
74
- else
75
- raise "sub-query must return a PMS::Proxy object (got #{sub.class})"
62
+ when Proxy then apply_operator(op, sub.results)
63
+ else raise "sub-query must return a #{Proxy} object (got #{sub.class})"
76
64
  end
77
65
  end
78
66
 
@@ -80,14 +68,10 @@ class PMS
80
68
  results = self.results
81
69
 
82
70
  case op = op.to_s.downcase
83
- when 'and'
84
- results &= doc_nums
85
- when 'or'
86
- results |= doc_nums
87
- when 'not'
88
- results -= doc_nums
89
- else
90
- raise ArgumentError, "invalid operator '#{op}'"
71
+ when 'and' then results &= doc_nums
72
+ when 'or' then results |= doc_nums
73
+ when 'not' then results -= doc_nums
74
+ else raise ArgumentError, "invalid operator `#{op}'"
91
75
  end
92
76
 
93
77
  clone_with_results(results) # allow chaining!
data/lib/pms/version.rb CHANGED
@@ -4,7 +4,7 @@ class PMS
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 0
7
- TINY = 3
7
+ TINY = 4
8
8
 
9
9
  class << self
10
10
 
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'rubygems'
2
+
1
3
  unless Object.const_defined?(:BASE)
2
4
  BASE = File.join(File.dirname(__FILE__), '..')
3
5
 
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 4
9
+ version: 0.0.4
5
10
  platform: ruby
6
11
  authors:
7
12
  - Jens Wille
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-02-18 00:00:00 +01:00
17
+ date: 2010-10-24 00:00:00 +02:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -24,18 +29,20 @@ extra_rdoc_files:
24
29
  - ChangeLog
25
30
  - README
26
31
  files:
27
- - lib/pms.rb
28
- - lib/pms/index.rb
29
- - lib/pms/proxy.rb
30
- - lib/pms/ext.rb
32
+ - lib/pms/i18n.rb
31
33
  - lib/pms/version.rb
34
+ - lib/pms/ext.rb
35
+ - lib/pms/proxy.rb
36
+ - lib/pms/index.rb
37
+ - lib/pms.rb
38
+ - COPYING
39
+ - Rakefile
32
40
  - README
33
41
  - ChangeLog
34
- - Rakefile
35
- - COPYING
36
- - spec/pms/index_spec.rb
37
- - spec/pms/ext_spec.rb
42
+ - TODO
38
43
  - spec/pms/proxy_spec.rb
44
+ - spec/pms/ext_spec.rb
45
+ - spec/pms/index_spec.rb
39
46
  - spec/spec_helper.rb
40
47
  - spec/pms_spec.rb
41
48
  - test_data/fox.txt
@@ -45,33 +52,37 @@ licenses: []
45
52
 
46
53
  post_install_message:
47
54
  rdoc_options:
55
+ - --line-numbers
56
+ - --inline-source
48
57
  - --charset
49
58
  - UTF-8
50
- - --title
51
- - pms Application documentation
52
59
  - --main
53
60
  - README
54
- - --line-numbers
55
- - --inline-source
61
+ - --title
62
+ - pms Application documentation
56
63
  - --all
57
64
  require_paths:
58
65
  - lib
59
66
  required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
60
68
  requirements:
61
69
  - - ">="
62
70
  - !ruby/object:Gem::Version
71
+ segments:
72
+ - 0
63
73
  version: "0"
64
- version:
65
74
  required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
66
76
  requirements:
67
77
  - - ">="
68
78
  - !ruby/object:Gem::Version
79
+ segments:
80
+ - 0
69
81
  version: "0"
70
- version:
71
82
  requirements: []
72
83
 
73
84
  rubyforge_project: pms
74
- rubygems_version: 1.3.5
85
+ rubygems_version: 1.3.7
75
86
  signing_key:
76
87
  specification_version: 3
77
88
  summary: Poor Man's Search