cql-ruby 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +37 -0
- data/README.txt +191 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +70 -0
- data/config/requirements.rb +15 -0
- data/lib/cql_ruby.rb +9 -0
- data/lib/cql_ruby/cql_generator.rb +133 -0
- data/lib/cql_ruby/cql_lexer.rb +221 -0
- data/lib/cql_ruby/cql_nodes.rb +328 -0
- data/lib/cql_ruby/cql_parser.rb +183 -0
- data/lib/cql_ruby/cql_to_solr.rb +57 -0
- data/lib/cql_ruby/version.rb +9 -0
- data/log/debug.log +0 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- data/test/fixtures/sample_queries.txt +112 -0
- data/test/test_cql_generator.rb +23 -0
- data/test/test_cql_lexer.rb +54 -0
- data/test/test_cql_nodes.rb +105 -0
- data/test/test_cql_parser.rb +113 -0
- data/test/test_cql_ruby.rb +11 -0
- data/test/test_cql_to_solr.rb +21 -0
- data/test/test_helper.rb +2 -0
- data/website/index.html +111 -0
- data/website/index.txt +49 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.html.erb +48 -0
- metadata +102 -0
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 FIXME full name
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
config/hoe.rb
|
7
|
+
config/requirements.rb
|
8
|
+
lib/cql_ruby.rb
|
9
|
+
lib/cql_ruby/version.rb
|
10
|
+
lib/cql_ruby/cql_generator.rb
|
11
|
+
lib/cql_ruby/cql_lexer.rb
|
12
|
+
lib/cql_ruby/cql_nodes.rb
|
13
|
+
lib/cql_ruby/cql_parser.rb
|
14
|
+
lib/cql_ruby/cql_to_solr.rb
|
15
|
+
log/debug.log
|
16
|
+
script/console
|
17
|
+
script/destroy
|
18
|
+
script/generate
|
19
|
+
script/txt2html
|
20
|
+
setup.rb
|
21
|
+
tasks/deployment.rake
|
22
|
+
tasks/environment.rake
|
23
|
+
tasks/website.rake
|
24
|
+
test/fixtures
|
25
|
+
test/fixtures/sample_queries.txt
|
26
|
+
test/test_cql_generator.rb
|
27
|
+
test/test_cql_lexer.rb
|
28
|
+
test/test_cql_nodes.rb
|
29
|
+
test/test_cql_parser.rb
|
30
|
+
test/test_cql_ruby.rb
|
31
|
+
test/test_cql_to_solr.rb
|
32
|
+
test/test_helper.rb
|
33
|
+
website/index.html
|
34
|
+
website/index.txt
|
35
|
+
website/javascripts/rounded_corners_lite.inc.js
|
36
|
+
website/stylesheets/screen.css
|
37
|
+
website/template.html.erb
|
data/README.txt
ADDED
@@ -0,0 +1,191 @@
|
|
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.
|
data/Rakefile
ADDED
data/config/hoe.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'cql_ruby/version'
|
2
|
+
|
3
|
+
AUTHOR = 'Chick Markley'
|
4
|
+
EMAIL = "chick@qrhino.com"
|
5
|
+
DESCRIPTION = "CQL parser for Ruby"
|
6
|
+
GEM_NAME = 'cql-ruby' # what ppl will type to install your gem
|
7
|
+
RUBYFORGE_PROJECT = 'cql-ruby' # The unix name for your project
|
8
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
9
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
10
|
+
|
11
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
12
|
+
@config = nil
|
13
|
+
RUBYFORGE_USERNAME = "chickmarkley"
|
14
|
+
def rubyforge_username
|
15
|
+
unless @config
|
16
|
+
begin
|
17
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
18
|
+
rescue
|
19
|
+
puts <<-EOS
|
20
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
21
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
22
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
23
|
+
EOS
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
end
|
27
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
REV = nil
|
32
|
+
# UNCOMMENT IF REQUIRED:
|
33
|
+
# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
|
34
|
+
VERS = CqlRuby::VERSION::STRING + (REV ? ".#{REV}" : "")
|
35
|
+
RDOC_OPTS = ['--quiet', '--title', 'cql_ruby documentation',
|
36
|
+
"--opname", "index.html",
|
37
|
+
"--line-numbers",
|
38
|
+
"--main", "README",
|
39
|
+
"--inline-source"]
|
40
|
+
|
41
|
+
class Hoe
|
42
|
+
def extra_deps
|
43
|
+
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
44
|
+
@extra_deps
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Generate all the Rake tasks
|
49
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
50
|
+
$hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
51
|
+
p.developer(AUTHOR, EMAIL)
|
52
|
+
p.description = DESCRIPTION
|
53
|
+
p.summary = DESCRIPTION
|
54
|
+
p.url = HOMEPATH
|
55
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
56
|
+
p.test_globs = ["test/**/test_*.rb"]
|
57
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
58
|
+
|
59
|
+
# == Optional
|
60
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
61
|
+
#p.extra_deps = ['builder'] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
62
|
+
|
63
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
68
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
69
|
+
$hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
70
|
+
$hoe.rsync_args = '-av --delete --ignore-errors'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
include FileUtils
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
%w[rake hoe newgem rubigen].each do |req_gem|
|
6
|
+
begin
|
7
|
+
require req_gem
|
8
|
+
rescue LoadError
|
9
|
+
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
10
|
+
puts "Installation: gem install #{req_gem} -y"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
data/lib/cql_ruby.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
#$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
# $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
#
|
4
|
+
#Dir['map_by_method/**/*.rb'].sort.each { |lib| require lib }
|
5
|
+
|
6
|
+
require File.dirname(__FILE__) + '/cql_ruby/cql_nodes'
|
7
|
+
require File.dirname(__FILE__) + '/cql_ruby/cql_lexer'
|
8
|
+
require File.dirname(__FILE__) + '/cql_ruby/cql_parser'
|
9
|
+
require File.dirname(__FILE__) + '/cql_ruby/cql_to_solr'
|
@@ -0,0 +1,133 @@
|
|
1
|
+
module CqlRuby
|
2
|
+
|
3
|
+
# A generator that produces random CQL queries.
|
4
|
+
# <P>
|
5
|
+
# Why is that useful? Mainly to produce test-cases for CQL parsers
|
6
|
+
# (including the <TT>CQLParser</TT> class in this package): you can
|
7
|
+
# generate a random search tree, render it to XCQL and remember the
|
8
|
+
# result. Then decompile the tree to CQL, feed the generated CQL to
|
9
|
+
# the parser of your choice, and check that the XCQL it comes up with
|
10
|
+
# is the same what you got from your initial rendering.
|
11
|
+
# <P>
|
12
|
+
# This code is based on the same grammar as the <TT>CQLParser</TT> class in
|
13
|
+
# this distribution - there is a <TT>generate_<I>x</I>()</TT> method
|
14
|
+
# for each grammar element <I>X</I>.
|
15
|
+
#
|
16
|
+
# @version $Id: CQLGenerator.java,v 1.9 2007/07/03 15:41:35 mike Exp $
|
17
|
+
# @see <A href="http://zing.z3950.org/cql/index.html"
|
18
|
+
# >http://zing.z3950.org/cql/index.html</A>
|
19
|
+
class CqlGenerator
|
20
|
+
attr_accessor :params, :rnd, :debug_mode
|
21
|
+
|
22
|
+
def initialize( params )
|
23
|
+
@debug_mode = params[ :debug ] || false
|
24
|
+
@params = params
|
25
|
+
srand( params[ :seed ] ) if params and params[ :seed ]
|
26
|
+
end
|
27
|
+
|
28
|
+
def debug( s )
|
29
|
+
puts( "DEBUG: #{s}" ) if @debug_mode
|
30
|
+
end
|
31
|
+
|
32
|
+
def generate_cql_query
|
33
|
+
return generate_search_clause unless maybe( :complex_query )
|
34
|
+
|
35
|
+
node1 = generate_cql_query
|
36
|
+
node2 = generate_search_clause
|
37
|
+
|
38
|
+
if maybe( :proxOp )
|
39
|
+
# TODO: generate proximity nodes
|
40
|
+
else
|
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" ) )
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
generate_search_clause
|
49
|
+
end
|
50
|
+
|
51
|
+
def generate_search_clause
|
52
|
+
return generate_cql_query if maybe( :complex_clause )
|
53
|
+
|
54
|
+
index = generate_index
|
55
|
+
relation = generate_relation
|
56
|
+
term = generate_term
|
57
|
+
|
58
|
+
CqlTermNode.new( index, relation, term )
|
59
|
+
end
|
60
|
+
|
61
|
+
def generate_index
|
62
|
+
if rand(2) == 0
|
63
|
+
case rand(3)
|
64
|
+
when 0: index = "dc.author"
|
65
|
+
when 1: index = "dc.title"
|
66
|
+
when 2: index = "dc.subject"
|
67
|
+
end
|
68
|
+
else
|
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"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
index
|
77
|
+
end
|
78
|
+
|
79
|
+
def generate_relation
|
80
|
+
base = generate_base_relation
|
81
|
+
CqlRelation.new( base )
|
82
|
+
end
|
83
|
+
|
84
|
+
def generate_base_relation
|
85
|
+
return "=" if maybe( :equals_relation )
|
86
|
+
return generate_numeric_relation if maybe( :numeric_relation )
|
87
|
+
case rand(3)
|
88
|
+
when 0: index = "exact"
|
89
|
+
when 1: index = "all"
|
90
|
+
when 2: index = "any"
|
91
|
+
end
|
92
|
+
index
|
93
|
+
end
|
94
|
+
|
95
|
+
def generate_term
|
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"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def generate_numeric_relation
|
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 "="
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def maybe( key )
|
122
|
+
probability = @params[ key ] || ".1"
|
123
|
+
|
124
|
+
dice = rand
|
125
|
+
threshold = probability.to_f
|
126
|
+
res = dice < threshold
|
127
|
+
|
128
|
+
debug( "dice=#{dice} vs #{threshold} = #{res.to_s}" )
|
129
|
+
res
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
end
|