cql-ruby 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,40 @@
1
+ # What
2
+
3
+ cql-ruby provides a common querly language (CQL) parser. CQL is a format frequently used in the library world. This parser was translated from the CQL-Java parser written by Mike Taylor available here http://zing.z3950.org/cql/java/
4
+
5
+ The parser builds a CQL parse tree suitable to serializing to various forms, built in are to_cql, to_xcql and to_solr (build a solr-lucene search query from cql)
6
+
7
+ # Installing
8
+
9
+ sudo gem install cql_ruby
10
+
11
+ # The basics
12
+
13
+ You have been asked to provide SRU access to your website, so that the dynamic and exciting library community can find and promote access to and awareness of your rich content. You discover that in order to support SRU, dang! you need a CQL parser. Well now you have one.
14
+
15
+ # Demonstration of usage
16
+
17
+ require 'cql_ruby'
18
+ parser = CqlRuby::CqlParser.new
19
+ puts parser.parse( 'dog and cat' ).to_solr
20
+
21
+ # Listserv
22
+
23
+ http://groups.google.com/group/cql_ruby
24
+
25
+ # Project
26
+
27
+ https://github.com/jrochkind/cql-ruby
28
+
29
+
30
+ # License
31
+
32
+ This code is free to use under the terms of the LGPL license.
33
+
34
+ # Contact
35
+
36
+ Comments are welcome. Best way to send them is to via the listserv
37
+
38
+ Chick Markley, from 9th April 2008
39
+ Jonathan Rochkind, from 14 June 2010
40
+
@@ -39,9 +39,9 @@ class CqlGenerator
39
39
  # TODO: generate proximity nodes
40
40
  else
41
41
  case rand( 3 )
42
- when 0: return CqlAndNode.new( node1, node2, ModifierSet.new( "and" ) )
43
- when 1: return CqlOrNode.new( node1, node2, ModifierSet.new( "or" ) )
44
- when 2: return CqlNotNode.new( node1, node2, ModifierSet.new( "or" ) )
42
+ when 0 then return CqlAndNode.new( node1, node2, ModifierSet.new( "and" ) )
43
+ when 1 then return CqlOrNode.new( node1, node2, ModifierSet.new( "or" ) )
44
+ when 2 then return CqlNotNode.new( node1, node2, ModifierSet.new( "or" ) )
45
45
  end
46
46
  end
47
47
 
@@ -61,16 +61,16 @@ class CqlGenerator
61
61
  def generate_index
62
62
  if rand(2) == 0
63
63
  case rand(3)
64
- when 0: index = "dc.author"
65
- when 1: index = "dc.title"
66
- when 2: index = "dc.subject"
64
+ when 0 then index = "dc.author"
65
+ when 1 then index = "dc.title"
66
+ when 2 then index = "dc.subject"
67
67
  end
68
68
  else
69
69
  case rand(4)
70
- when 0: index = "bath.author"
71
- when 1: index = "bath.title"
72
- when 2: index = "bath.subject"
73
- when 3: index = "foo>bar"
70
+ when 0 then index = "bath.author"
71
+ when 1 then index = "bath.title"
72
+ when 2 then index = "bath.subject"
73
+ when 3 then index = "foo>bar"
74
74
  end
75
75
  end
76
76
  index
@@ -85,36 +85,36 @@ class CqlGenerator
85
85
  return "=" if maybe( :equals_relation )
86
86
  return generate_numeric_relation if maybe( :numeric_relation )
87
87
  case rand(3)
88
- when 0: index = "exact"
89
- when 1: index = "all"
90
- when 2: index = "any"
88
+ when 0 then index = "exact"
89
+ when 1 then index = "all"
90
+ when 2 then index = "any"
91
91
  end
92
92
  index
93
93
  end
94
94
 
95
95
  def generate_term
96
96
  case rand(10)
97
- when 0: return "cat"
98
- when 1: return "\"cat\""
99
- when 2: return "comp.os.linux"
100
- when 3: return "xml:element"
101
- when 4: return "<xml.element>"
102
- when 5: return "prox/word/>=/5"
103
- when 6: return ""
104
- when 7: return "frog fish"
105
- when 8: return "the complete dinosaur"
106
- when 9: return "foo*bar"
97
+ when 0 then return "cat"
98
+ when 1 then return "\"cat\""
99
+ when 2 then return "comp.os.linux"
100
+ when 3 then return "xml:element"
101
+ when 4 then return "<xml.element>"
102
+ when 5 then return "prox/word/>=/5"
103
+ when 6 then return ""
104
+ when 7 then return "frog fish"
105
+ when 8 then return "the complete dinosaur"
106
+ when 9 then return "foo*bar"
107
107
  end
108
108
  end
109
109
 
110
110
  def generate_numeric_relation
111
111
  case rand(6)
112
- when 0: return "<"
113
- when 1: return ">"
114
- when 2: return "<="
115
- when 3: return ">="
116
- when 4: return "<>"
117
- when 5: return "="
112
+ when 0 then return "<"
113
+ when 1 then return ">"
114
+ when 2 then return "<="
115
+ when 3 then return ">="
116
+ when 4 then return "<>"
117
+ when 5 then return "="
118
118
  end
119
119
  end
120
120
 
@@ -156,15 +156,15 @@ class CqlLexer
156
156
  def render( token=nil, quote_chars=true )
157
157
  token = @token_type unless token
158
158
  case token
159
- when CqlLexer::TT_EOF: "EOF"
160
- when CqlLexer::TT_NUMBER: @value
161
- when CqlLexer::TT_WORD: "word:#{@value}"
162
- when "'": "string:\"#{@value}\""
163
- when CqlLexer::TT_LE: "<="
164
- when CqlLexer::TT_GE: ">="
165
- when CqlLexer::TT_NE: "<>"
166
- when CqlLexer::TT_EQEQ: "=="
167
- when CqlLexer::TT_EOF: "EOF"
159
+ when CqlLexer::TT_EOF then "EOF"
160
+ when CqlLexer::TT_NUMBER then @value
161
+ when CqlLexer::TT_WORD then "word:#{@value}"
162
+ when "'" then "string:\"#{@value}\""
163
+ when CqlLexer::TT_LE then "<="
164
+ when CqlLexer::TT_GE then ">="
165
+ when CqlLexer::TT_NE then "<>"
166
+ when CqlLexer::TT_EQEQ then "=="
167
+ when CqlLexer::TT_EOF then "EOF"
168
168
  else
169
169
  if @@keywords.has_value?( @value )
170
170
  @value
@@ -68,10 +68,10 @@ class CqlParser
68
68
  ms = gather_modifiers( value )
69
69
  term2 = parse_term( index, relation )
70
70
  term = case token_type
71
- when CqlLexer::TT_AND: CqlAndNode.new( term, term2, ms )
72
- when CqlLexer::TT_OR: CqlOrNode.new( term, term2, ms )
73
- when CqlLexer::TT_NOT: CqlNotNode.new( term, term2, ms )
74
- when CqlLexer::TT_PROX: CqlProxNode.new( term, term2, ms )
71
+ when CqlLexer::TT_AND then CqlAndNode.new( term, term2, ms )
72
+ when CqlLexer::TT_OR then CqlOrNode.new( term, term2, ms )
73
+ when CqlLexer::TT_NOT then CqlNotNode.new( term, term2, ms )
74
+ when CqlLexer::TT_PROX then CqlProxNode.new( term, term2, ms )
75
75
  end
76
76
 
77
77
  else
@@ -117,13 +117,13 @@ class CqlTermNode
117
117
  when "<>"
118
118
  negate = true
119
119
  maybe_quote(@term)
120
- when "cql.adj", "==": maybe_quote(@term)
121
- when "cql.all": '(' + @term.split(/\s/).collect{|a| '+'+a}.join(" ") + ')'
122
- when "cql.any": '(' + @term.split(/\s/).join(" OR ") + ')'
123
- when ">=": "[" + maybe_quote(@term) + " TO *]"
124
- when ">": "{" + maybe_quote(@term) + " TO *}"
125
- when "<=": "[* TO " + maybe_quote(@term) + "]"
126
- when "<": "{* TO " + maybe_quote(@term) + "}"
120
+ when "cql.adj", "==" then maybe_quote(@term)
121
+ when "cql.all" then '(' + @term.split(/\s/).collect{|a| '+'+a}.join(" ") + ')'
122
+ when "cql.any" then '(' + @term.split(/\s/).join(" OR ") + ')'
123
+ when ">=" then "[" + maybe_quote(@term) + " TO *]"
124
+ when ">" then "{" + maybe_quote(@term) + " TO *}"
125
+ when "<=" then "[* TO " + maybe_quote(@term) + "]"
126
+ when "<" then "{* TO " + maybe_quote(@term) + "}"
127
127
  when "cql.within"
128
128
  bounds = @term.gsub('"', "").split(/\s/)
129
129
  raise CqlException.new("can not extract two bounding values from within relation term: #{@term}") unless bounds.length == 2
@@ -7,6 +7,7 @@ class TestCqlParser < Test::Unit::TestCase
7
7
  lines = IO.readlines( File.dirname(__FILE__) + '/fixtures/sample_queries.txt' )
8
8
  lines.each do |line|
9
9
  next if /^\s*#/ =~ line
10
+ next if /^(\s|\n)*$/ =~ line
10
11
  begin
11
12
  tree = parser.parse( line )
12
13
  puts "in=#{line} out=#{tree.to_cql}" if tree
metadata CHANGED
@@ -1,34 +1,25 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cql-ruby
3
- version: !ruby/object:Gem::Version
4
- hash: 59
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 8
9
- - 2
10
- version: 0.8.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Jonathan Rochkind
14
9
  - Chick Markley
15
10
  autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2010-07-07 00:00:00 -04:00
20
- default_executable:
13
+ date: 2012-02-29 00:00:00.000000000 Z
21
14
  dependencies: []
22
-
23
- description: " CQL Parser, with serialization from cql node tree to cql, xcql, and solr query"
15
+ description: ! ' CQL Parser, with serialization from cql node tree to cql, xcql, and
16
+ solr query'
24
17
  email: cql_ruby@googlegroups.com
25
18
  executables: []
26
-
27
19
  extensions: []
28
-
29
- extra_rdoc_files:
30
- - README.txt
31
- files:
20
+ extra_rdoc_files:
21
+ - README.md
22
+ files:
32
23
  - lib/cql_ruby.rb
33
24
  - lib/cql_ruby/cql_generator.rb
34
25
  - lib/cql_ruby/cql_lexer.rb
@@ -36,7 +27,7 @@ files:
36
27
  - lib/cql_ruby/cql_parser.rb
37
28
  - lib/cql_ruby/cql_to_solr.rb
38
29
  - lib/cql_ruby/version.rb
39
- - README.txt
30
+ - README.md
40
31
  - test/test_cql_parser.rb
41
32
  - test/test_cql_nodes.rb
42
33
  - test/test_cql_generator.rb
@@ -45,41 +36,32 @@ files:
45
36
  - test/test_helper.rb
46
37
  - test/helper.rb
47
38
  - test/test_cql_to_solr.rb
48
- has_rdoc: true
49
- homepage: http://cql-ruby.rubyforge.org/
39
+ homepage: https://github.com/jrochkind/cql-ruby
50
40
  licenses: []
51
-
52
41
  post_install_message:
53
- rdoc_options:
42
+ rdoc_options:
54
43
  - --charset=UTF-8
55
- require_paths:
44
+ require_paths:
56
45
  - lib
57
- required_ruby_version: !ruby/object:Gem::Requirement
46
+ required_ruby_version: !ruby/object:Gem::Requirement
58
47
  none: false
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- hash: 3
63
- segments:
64
- - 0
65
- version: "0"
66
- required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
53
  none: false
68
- requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- hash: 3
72
- segments:
73
- - 0
74
- version: "0"
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
75
58
  requirements: []
76
-
77
59
  rubyforge_project: cql-ruby
78
- rubygems_version: 1.3.7
60
+ rubygems_version: 1.8.15
79
61
  signing_key:
80
62
  specification_version: 3
81
63
  summary: CQL Parser
82
- test_files:
64
+ test_files:
83
65
  - test/test_cql_parser.rb
84
66
  - test/test_cql_nodes.rb
85
67
  - test/test_cql_generator.rb
data/README.txt DELETED
@@ -1,191 +0,0 @@
1
- = cql_ruby
2
-
3
- * FIX (url)
4
-
5
- == DESCRIPTION:
6
-
7
- FIX (describe your package)
8
-
9
- == FEATURES/PROBLEMS:
10
-
11
- * FIX (list of features or problems)
12
-
13
- == SYNOPSIS:
14
-
15
- FIX (code sample of usage)
16
-
17
- == REQUIREMENTS:
18
-
19
- builder
20
-
21
- == INSTALL:
22
-
23
- sudo gem install cql-ruby
24
-
25
- == LICENSE:
26
-
27
- GNU LESSER GENERAL PUBLIC LICENSE
28
- Version 3, 29 June 2007
29
-
30
- Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
31
- Everyone is permitted to copy and distribute verbatim copies
32
- of this license document, but changing it is not allowed.
33
-
34
-
35
- This version of the GNU Lesser General Public License incorporates
36
- the terms and conditions of version 3 of the GNU General Public
37
- License, supplemented by the additional permissions listed below.
38
-
39
- 0. Additional Definitions.
40
-
41
- As used herein, "this License" refers to version 3 of the GNU Lesser
42
- General Public License, and the "GNU GPL" refers to version 3 of the GNU
43
- General Public License.
44
-
45
- "The Library" refers to a covered work governed by this License,
46
- other than an Application or a Combined Work as defined below.
47
-
48
- An "Application" is any work that makes use of an interface provided
49
- by the Library, but which is not otherwise based on the Library.
50
- Defining a subclass of a class defined by the Library is deemed a mode
51
- of using an interface provided by the Library.
52
-
53
- A "Combined Work" is a work produced by combining or linking an
54
- Application with the Library. The particular version of the Library
55
- with which the Combined Work was made is also called the "Linked
56
- Version".
57
-
58
- The "Minimal Corresponding Source" for a Combined Work means the
59
- Corresponding Source for the Combined Work, excluding any source code
60
- for portions of the Combined Work that, considered in isolation, are
61
- based on the Application, and not on the Linked Version.
62
-
63
- The "Corresponding Application Code" for a Combined Work means the
64
- object code and/or source code for the Application, including any data
65
- and utility programs needed for reproducing the Combined Work from the
66
- Application, but excluding the System Libraries of the Combined Work.
67
-
68
- 1. Exception to Section 3 of the GNU GPL.
69
-
70
- You may convey a covered work under sections 3 and 4 of this License
71
- without being bound by section 3 of the GNU GPL.
72
-
73
- 2. Conveying Modified Versions.
74
-
75
- If you modify a copy of the Library, and, in your modifications, a
76
- facility refers to a function or data to be supplied by an Application
77
- that uses the facility (other than as an argument passed when the
78
- facility is invoked), then you may convey a copy of the modified
79
- version:
80
-
81
- a) under this License, provided that you make a good faith effort to
82
- ensure that, in the event an Application does not supply the
83
- function or data, the facility still operates, and performs
84
- whatever part of its purpose remains meaningful, or
85
-
86
- b) under the GNU GPL, with none of the additional permissions of
87
- this License applicable to that copy.
88
-
89
- 3. Object Code Incorporating Material from Library Header Files.
90
-
91
- The object code form of an Application may incorporate material from
92
- a header file that is part of the Library. You may convey such object
93
- code under terms of your choice, provided that, if the incorporated
94
- material is not limited to numerical parameters, data structure
95
- layouts and accessors, or small macros, inline functions and templates
96
- (ten or fewer lines in length), you do both of the following:
97
-
98
- a) Give prominent notice with each copy of the object code that the
99
- Library is used in it and that the Library and its use are
100
- covered by this License.
101
-
102
- b) Accompany the object code with a copy of the GNU GPL and this license
103
- document.
104
-
105
- 4. Combined Works.
106
-
107
- You may convey a Combined Work under terms of your choice that,
108
- taken together, effectively do not restrict modification of the
109
- portions of the Library contained in the Combined Work and reverse
110
- engineering for debugging such modifications, if you also do each of
111
- the following:
112
-
113
- a) Give prominent notice with each copy of the Combined Work that
114
- the Library is used in it and that the Library and its use are
115
- covered by this License.
116
-
117
- b) Accompany the Combined Work with a copy of the GNU GPL and this license
118
- document.
119
-
120
- c) For a Combined Work that displays copyright notices during
121
- execution, include the copyright notice for the Library among
122
- these notices, as well as a reference directing the user to the
123
- copies of the GNU GPL and this license document.
124
-
125
- d) Do one of the following:
126
-
127
- 0) Convey the Minimal Corresponding Source under the terms of this
128
- License, and the Corresponding Application Code in a form
129
- suitable for, and under terms that permit, the user to
130
- recombine or relink the Application with a modified version of
131
- the Linked Version to produce a modified Combined Work, in the
132
- manner specified by section 6 of the GNU GPL for conveying
133
- Corresponding Source.
134
-
135
- 1) Use a suitable shared library mechanism for linking with the
136
- Library. A suitable mechanism is one that (a) uses at run time
137
- a copy of the Library already present on the user's computer
138
- system, and (b) will operate properly with a modified version
139
- of the Library that is interface-compatible with the Linked
140
- Version.
141
-
142
- e) Provide Installation Information, but only if you would otherwise
143
- be required to provide such information under section 6 of the
144
- GNU GPL, and only to the extent that such information is
145
- necessary to install and execute a modified version of the
146
- Combined Work produced by recombining or relinking the
147
- Application with a modified version of the Linked Version. (If
148
- you use option 4d0, the Installation Information must accompany
149
- the Minimal Corresponding Source and Corresponding Application
150
- Code. If you use option 4d1, you must provide the Installation
151
- Information in the manner specified by section 6 of the GNU GPL
152
- for conveying Corresponding Source.)
153
-
154
- 5. Combined Libraries.
155
-
156
- You may place library facilities that are a work based on the
157
- Library side by side in a single library together with other library
158
- facilities that are not Applications and are not covered by this
159
- License, and convey such a combined library under terms of your
160
- choice, if you do both of the following:
161
-
162
- a) Accompany the combined library with a copy of the same work based
163
- on the Library, uncombined with any other library facilities,
164
- conveyed under the terms of this License.
165
-
166
- b) Give prominent notice with the combined library that part of it
167
- is a work based on the Library, and explaining where to find the
168
- accompanying uncombined form of the same work.
169
-
170
- 6. Revised Versions of the GNU Lesser General Public License.
171
-
172
- The Free Software Foundation may publish revised and/or new versions
173
- of the GNU Lesser General Public License from time to time. Such new
174
- versions will be similar in spirit to the present version, but may
175
- differ in detail to address new problems or concerns.
176
-
177
- Each version is given a distinguishing version number. If the
178
- Library as you received it specifies that a certain numbered version
179
- of the GNU Lesser General Public License "or any later version"
180
- applies to it, you have the option of following the terms and
181
- conditions either of that published version or of any later version
182
- published by the Free Software Foundation. If the Library as you
183
- received it does not specify a version number of the GNU Lesser
184
- General Public License, you may choose any version of the GNU Lesser
185
- General Public License ever published by the Free Software Foundation.
186
-
187
- If the Library as you received it specifies that a proxy can decide
188
- whether future versions of the GNU Lesser General Public License shall
189
- apply, that proxy's public statement of acceptance of any version is
190
- permanent authorization for you to choose that version for the
191
- Library.