keyword_search 1.0.6 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Rakefile +1 -1
- data/lib/keyword_search.rb +3 -2
- data/lib/keyword_search/evaluator.rb +9 -7
- data/lib/keyword_search/parser.rb +20 -28
- data/lib/keyword_search/tokenizer.rb +27 -15
- metadata +12 -3
data/History.txt
CHANGED
data/Rakefile
CHANGED
@@ -12,7 +12,7 @@ Hoe.new('keyword_search', KeywordSearch::VERSION) do |p|
|
|
12
12
|
p.author = 'Bruce Williams'
|
13
13
|
p.email = 'bruce@codefluency.com'
|
14
14
|
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
15
|
-
p.extra_deps = [['dhaka', '=
|
15
|
+
p.extra_deps = [['dhaka', '= 2.1.0']]
|
16
16
|
end
|
17
17
|
|
18
18
|
task :rebuild_parser do
|
data/lib/keyword_search.rb
CHANGED
@@ -7,15 +7,16 @@ end
|
|
7
7
|
|
8
8
|
module KeywordSearch
|
9
9
|
|
10
|
-
VERSION = '1.0
|
10
|
+
VERSION = '1.1.0'
|
11
11
|
|
12
12
|
class << self
|
13
13
|
def search(input_string, definition=nil, &block)
|
14
|
+
@evaluator ||= Evaluator.new
|
14
15
|
definition ||= Definition.new(&block)
|
15
16
|
tokens = Tokenizer.tokenize(input_string.downcase)
|
16
17
|
parse_result = Parser.parse(tokens)
|
17
18
|
unless parse_result.has_error?
|
18
|
-
results =
|
19
|
+
results = @evaluator.evaluate(parse_result.parse_tree)
|
19
20
|
results.each do |key, terms|
|
20
21
|
definition.handle(key, terms)
|
21
22
|
end
|
@@ -7,23 +7,25 @@ module KeywordSearch
|
|
7
7
|
define_evaluation_rules do
|
8
8
|
|
9
9
|
for_multiple_pairs do
|
10
|
-
child_nodes
|
11
|
-
|
12
|
-
|
10
|
+
child_nodes.inject({}) do |result,child_node|
|
11
|
+
evaluate(child_node).each do |key,value|
|
12
|
+
result[key] ||= []
|
13
|
+
result[key] += value
|
14
|
+
end
|
15
|
+
result
|
13
16
|
end
|
14
|
-
child_nodes[0]
|
15
17
|
end
|
16
18
|
|
17
19
|
for_one_pair do
|
18
|
-
child_nodes
|
20
|
+
evaluate(child_nodes.first)
|
19
21
|
end
|
20
22
|
|
21
23
|
for_keyword_and_term do
|
22
|
-
{child_nodes
|
24
|
+
{child_nodes.first.tokens.first.value => [child_nodes.last.tokens.first.value]}
|
23
25
|
end
|
24
26
|
|
25
27
|
for_default_keyword_term do
|
26
|
-
{:default => [child_nodes[0].
|
28
|
+
{:default => [child_nodes[0].tokens[0].value]}
|
27
29
|
end
|
28
30
|
|
29
31
|
end
|
@@ -4,46 +4,38 @@ class KeywordSearch::Parser < Dhaka::CompiledParser
|
|
4
4
|
|
5
5
|
start_with 0
|
6
6
|
|
7
|
-
at_state(
|
8
|
-
|
9
|
-
for_symbol('_End_') { reduce_with 'start' }
|
10
|
-
for_symbol('Pair') { shift_to 6 }
|
11
|
-
for_symbol('s') { shift_to 1 }
|
12
|
-
}
|
13
|
-
|
14
|
-
at_state(2) {
|
15
|
-
for_symbol('s') { shift_to 3 }
|
7
|
+
at_state(3) {
|
8
|
+
for_symbols("k", "_End_", "s") { reduce_with "one_pair" }
|
16
9
|
}
|
17
10
|
|
18
|
-
at_state(
|
19
|
-
|
20
|
-
for_symbol('_End_') { reduce_with 'keyword_and_term' }
|
21
|
-
for_symbol('s') { reduce_with 'keyword_and_term' }
|
11
|
+
at_state(1) {
|
12
|
+
for_symbols("s") { shift_to 2 }
|
22
13
|
}
|
23
14
|
|
24
15
|
at_state(6) {
|
25
|
-
|
26
|
-
for_symbol('_End_') { reduce_with 'multiple_pairs' }
|
27
|
-
for_symbol('s') { reduce_with 'multiple_pairs' }
|
16
|
+
for_symbols("k", "_End_", "s") { reduce_with "multiple_pairs" }
|
28
17
|
}
|
29
18
|
|
30
|
-
at_state(
|
31
|
-
|
32
|
-
|
33
|
-
|
19
|
+
at_state(5) {
|
20
|
+
for_symbols("s") { shift_to 4 }
|
21
|
+
for_symbols("_End_") { reduce_with "start" }
|
22
|
+
for_symbols("k") { shift_to 1 }
|
23
|
+
for_symbols("Pair") { shift_to 6 }
|
34
24
|
}
|
35
25
|
|
36
|
-
at_state(
|
37
|
-
|
38
|
-
for_symbol('_End_') { reduce_with 'default_keyword_term' }
|
39
|
-
for_symbol('s') { reduce_with 'default_keyword_term' }
|
26
|
+
at_state(2) {
|
27
|
+
for_symbols("k", "_End_", "s") { reduce_with "keyword_and_term" }
|
40
28
|
}
|
41
29
|
|
42
30
|
at_state(0) {
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
31
|
+
for_symbols("s") { shift_to 4 }
|
32
|
+
for_symbols("k") { shift_to 1 }
|
33
|
+
for_symbols("Pair") { shift_to 3 }
|
34
|
+
for_symbols("Pairs") { shift_to 5 }
|
35
|
+
}
|
36
|
+
|
37
|
+
at_state(4) {
|
38
|
+
for_symbols("k", "_End_", "s") { reduce_with "default_keyword_term" }
|
47
39
|
}
|
48
40
|
|
49
41
|
end
|
@@ -1,6 +1,18 @@
|
|
1
1
|
module KeywordSearch
|
2
2
|
|
3
3
|
class Tokenizer < Dhaka::Tokenizer
|
4
|
+
|
5
|
+
def accumulator
|
6
|
+
@accumulator ||= ''
|
7
|
+
end
|
8
|
+
|
9
|
+
def accumulate(string)
|
10
|
+
accumulator << string
|
11
|
+
end
|
12
|
+
|
13
|
+
def clear_accumulator
|
14
|
+
@accumulator = ''
|
15
|
+
end
|
4
16
|
|
5
17
|
|
6
18
|
# TODO: Add further character support; this is just for initial release
|
@@ -16,13 +28,13 @@ module KeywordSearch
|
|
16
28
|
for_state :idle_state do
|
17
29
|
|
18
30
|
for_characters(printables) do
|
19
|
-
|
31
|
+
clear_accumulator
|
20
32
|
switch_to :unquoted_literal_state
|
21
33
|
end
|
22
34
|
|
23
35
|
for_characters(quotes) do
|
24
|
-
|
25
|
-
|
36
|
+
advance unless accumulator.empty?
|
37
|
+
clear_accumulator
|
26
38
|
case curr_char
|
27
39
|
when %<">
|
28
40
|
advance
|
@@ -42,21 +54,21 @@ module KeywordSearch
|
|
42
54
|
for_state :unquoted_literal_state do
|
43
55
|
|
44
56
|
for_characters(printables) do
|
45
|
-
|
57
|
+
accumulate curr_char
|
46
58
|
advance
|
47
|
-
|
59
|
+
create_token('s', accumulator) unless curr_char
|
48
60
|
end
|
49
61
|
|
50
62
|
for_characters(keyword_separator) do
|
51
|
-
|
52
|
-
|
63
|
+
create_token 'k', accumulator
|
64
|
+
clear_accumulator
|
53
65
|
advance
|
54
66
|
switch_to :idle_state
|
55
67
|
end
|
56
68
|
|
57
69
|
for_characters(whitespace) do
|
58
|
-
|
59
|
-
|
70
|
+
create_token 's', accumulator
|
71
|
+
clear_accumulator
|
60
72
|
switch_to :idle_state
|
61
73
|
end
|
62
74
|
|
@@ -64,12 +76,12 @@ module KeywordSearch
|
|
64
76
|
|
65
77
|
for_state :double_quoted_literal_state do
|
66
78
|
for_characters(all_characters - %w<">) do
|
67
|
-
|
79
|
+
accumulate curr_char
|
68
80
|
advance
|
69
81
|
end
|
70
82
|
for_characters %w<"> do
|
71
|
-
|
72
|
-
|
83
|
+
create_token 's', accumulator
|
84
|
+
clear_accumulator = ''
|
73
85
|
advance
|
74
86
|
switch_to :idle_state
|
75
87
|
end
|
@@ -77,12 +89,12 @@ module KeywordSearch
|
|
77
89
|
|
78
90
|
for_state :single_quoted_literal_state do
|
79
91
|
for_characters(all_characters - %w<'>) do
|
80
|
-
|
92
|
+
accumulate curr_char
|
81
93
|
advance
|
82
94
|
end
|
83
95
|
for_characters %w<'> do
|
84
|
-
|
85
|
-
|
96
|
+
create_token 's', accumulator
|
97
|
+
clear_accumulator
|
86
98
|
advance
|
87
99
|
switch_to :idle_state
|
88
100
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: keyword_search
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.0
|
7
|
-
date: 2007-
|
6
|
+
version: 1.1.0
|
7
|
+
date: 2007-03-21 00:00:00 -06:00
|
8
8
|
summary: Generic support for extracting GMail-style search keywords/values from strings
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -60,5 +60,14 @@ dependencies:
|
|
60
60
|
requirements:
|
61
61
|
- - "="
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version:
|
63
|
+
version: 2.1.0
|
64
|
+
version:
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: hoe
|
67
|
+
version_requirement:
|
68
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 1.2.0
|
64
73
|
version:
|