Class: PMS::Index
Constant Summary collapse
- TOKEN_RE =
%r{\w+}- DEFAULT_LSI =
0.05
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
Instance Method Summary collapse
- #doc(doc_num) ⇒ Object (also: #[])
- #doc_nums(token) ⇒ Object (also: #results)
- #doc_nums_with_positions(token) ⇒ Object (also: #results_with_positions)
- #documents(doc_nums = default = true) ⇒ Object (also: #matches)
-
#initialize(input, options = {}) ⇒ Index
constructor
A new instance of Index.
Constructor Details
#initialize(input, options = {}) ⇒ Index
Returns a new instance of Index.
39 40 41 42 43 44 |
# File 'lib/pms/index.rb', line 39 def initialize(input, = {}) @input = input.respond_to?(:each) ? input : input.is_a?(String) ? input.each_line : raise(ArgumentError, 'input must implement #each') build_index() end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
37 38 39 |
# File 'lib/pms/index.rb', line 37 def entries @entries end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
37 38 39 |
# File 'lib/pms/index.rb', line 37 def index @index end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
37 38 39 |
# File 'lib/pms/index.rb', line 37 def input @input end |
Instance Method Details
#doc(doc_num) ⇒ Object Also known as: []
74 75 76 |
# File 'lib/pms/index.rb', line 74 def doc(doc_num) documents([doc_num]).first end |
#doc_nums(token) ⇒ Object Also known as: results
61 62 63 |
# File 'lib/pms/index.rb', line 61 def doc_nums(token) doc_nums_with_positions(token).keys end |
#doc_nums_with_positions(token) ⇒ Object Also known as: results_with_positions
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/pms/index.rb', line 46 def doc_nums_with_positions(token) case token when String index[mangle_token(token)] when Regexp index.each_with_object({}) { |(key, value), hash| hash.update(value) { |_, old, new| old | new } if key =~ token } else raise TypeError, "String or Regexp expected, got #{token.class}" end.each_value(&:compact!) end |
#documents(doc_nums = default = true) ⇒ Object Also known as: matches
67 68 69 70 |
# File 'lib/pms/index.rb', line 67 def documents(doc_nums = default = true) @documents ||= get_documents default ? @documents : @documents.values_at(*doc_nums) end |