cql-ruby 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ desc 'Release the website and new gem version'
2
+ task :deploy => [:check_version, :website, :release] do
3
+ puts "Remember to create SVN tag:"
4
+ puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
5
+ "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
6
+ puts "Suggested comment:"
7
+ puts "Tagging release #{CHANGES}"
8
+ end
9
+
10
+ desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
11
+ task :local_deploy => [:website_generate, :install_gem]
12
+
13
+ task :check_version do
14
+ unless ENV['VERSION']
15
+ puts 'Must pass a VERSION=x.y.z release version'
16
+ exit
17
+ end
18
+ unless ENV['VERSION'] == VERS
19
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
20
+ exit
21
+ end
22
+ end
23
+
24
+ desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
25
+ task :install_gem_no_doc => [:clean, :package] do
26
+ sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
27
+ end
28
+
29
+ namespace :manifest do
30
+ desc 'Recreate Manifest.txt to include ALL files'
31
+ task :refresh do
32
+ `rake check_manifest | patch -p0 > Manifest.txt`
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ task :ruby_env do
2
+ RUBY_APP = if RUBY_PLATFORM =~ /java/
3
+ "jruby"
4
+ else
5
+ "ruby"
6
+ end unless defined? RUBY_APP
7
+ end
@@ -0,0 +1,17 @@
1
+ desc 'Generate website files'
2
+ task :website_generate => :ruby_env do
3
+ (Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
4
+ sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
5
+ end
6
+ end
7
+
8
+ desc 'Upload website files to rubyforge'
9
+ task :website_upload do
10
+ host = "#{rubyforge_username}@rubyforge.org"
11
+ remote_dir = "/var/www/gforge-projects/#{PATH}/"
12
+ local_dir = 'website'
13
+ sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
14
+ end
15
+
16
+ desc 'Generate and upload website files'
17
+ task :website => [:website_generate, :website_upload, :publish_docs]
@@ -0,0 +1,112 @@
1
+ # These are from the java distribution
2
+ # Simple
3
+
4
+ cat
5
+ "cat"
6
+ comp.os.linux
7
+ xml:element
8
+ "<xml:element>"
9
+ "="
10
+ "prox/distance<3/unit=word"
11
+ ("cat")
12
+ ((dog))
13
+ all
14
+ prox
15
+
16
+ # Index Relation Term
17
+
18
+ title = "fish"
19
+ title exact fish
20
+ title any fish
21
+ title all fish
22
+ title > 9
23
+ title >= 23
24
+ dc.title any "fish chips"
25
+ dc.title any/stem fish
26
+ dc.fish all/stem/fuzzy "fish chips"
27
+ (title any frog)
28
+ ((dc.title any/stem "frog pond"))
29
+ dc.title scr "fish frog chicken"
30
+ dc.title =/rel.algorithm=CORI squid
31
+ author any/f.foo/b.bar>1 "sanderson taylor"
32
+ numberOfLegs <= 4
33
+ numberOfLegs <> 4
34
+ title == jaws
35
+
36
+ # Simple Boolean
37
+
38
+ cat or dog
39
+ cat and fish
40
+ cat not frog
41
+ (cat not frog)
42
+ "cat" not "fish food"
43
+ xml and "prox///"
44
+ fred and any
45
+ ((fred or all))
46
+ a or b and c not d
47
+
48
+ # I/R/T plus Boolean
49
+
50
+ bath.author any fish and dc.title all "cat dog"
51
+ (title any/stem "fish dog" or and)
52
+
53
+ # Prox
54
+
55
+ cat prox hat
56
+ cat prox/distance=3/unit=word/ordered hat
57
+ cat prox/distance<3 hat
58
+ "fish food" prox/unit=sentence and
59
+ title all "chips frog" prox/distance<=5 exact
60
+ (dc.author exact "jones" prox/distance>5/unit=element title >= "smith")
61
+ ((cat prox hat))
62
+ a and/rel.SumOfScores b
63
+ a and/rel.algorithm=CORI b
64
+
65
+ # Special Characters
66
+
67
+ (cat^)
68
+ "cat"
69
+ "^cat says \"fish\""
70
+ "cat*fish"
71
+ cat?dog
72
+ (("^cat*fishdog\"horse?"))
73
+
74
+ # Nesting Parentheses
75
+
76
+ (((cat or dog) or horse) and frog)
77
+ (cat and dog) or (horse and frog)
78
+ (cat and (horse or frog)) and chips
79
+
80
+ # Prefix Maps
81
+
82
+ > foo="http://www.loc.gov/zing/cql/dc-indexes/" dc.title="fish"
83
+ > "http://www.loc.gov/zing/cql/dc-indexes/" title="fish"
84
+ > foo="http://www.loc.gov/zing/cql/dc-indexes" > ccg = "http://srw.o-r-g.org/cql/indexSets/ccg/" foo.title="fish" and ccg.force=3
85
+
86
+ # Lame Searches
87
+
88
+ any or all:stem and all exact any prox prox=fuzzy
89
+ (((((((((any)))))))))
90
+ ""
91
+ > any > any = exact any > any
92
+ sortby sortby sortby
93
+ sortby sortby sortby sortby sortby
94
+
95
+ # Sorting
96
+
97
+ kernighan sortby title
98
+ kernighan and ritchie sortby title
99
+ dc.creator=kernighan sortby dc.title
100
+ dc.creator=kernighan sortby numberOfLegs/cql.number
101
+ dc.creator=kernighan sortby dc.title/sort.respectCase
102
+ dc.creator=kernighan sortby dc.title/sort.respectCase/sort.descending
103
+ dc.creator=kernighan sortby dc.date dc.title
104
+ dc.creator=kernighan sortby dc.date/sort.missingOmit
105
+ dc.creator=kernighan sortby dc.date/sort.missingValue=1970
106
+ >dc="http://deepcustard.org/1.0" blah sortby dc.custardDepth
107
+ >ns1="http://uri1" >ns2="http://uri2" whatever sortby ns1.key/a/b/c=1 ns2.key2
108
+ (>dc=x b=c) sortby d
109
+ b=(>dc=x c) sortby d
110
+ (>dc=x c1 and c2) sortby d
111
+ >dc="http://deepcustard.org" (>dc="http://dublincore.org" dc.title=jaws) sortby dc.custardDepth
112
+ >dc="http://deepcustard.org" (fish or >dc="http://dublincore.org" dc.title=jaws) sortby dc.custardDepth
@@ -0,0 +1,23 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/cql_ruby'
3
+ require File.dirname(__FILE__) + '/../lib/cql_ruby/cql_generator'
4
+
5
+ class TestCqlGenerator < Test::Unit::TestCase
6
+ def test_generator
7
+ params = {:seed => 1, :debug => false }
8
+
9
+ parser = CqlRuby::CqlParser.new
10
+ generator = CqlRuby::CqlGenerator.new( params )
11
+ 100.times do
12
+ tree = generator.generate_cql_query
13
+ puts "tree built"
14
+ puts tree.to_cql
15
+ new_tree = parser.parse( tree.to_cql )
16
+ assert( new_tree )
17
+ assert( new_tree.to_solr )
18
+ puts new_tree.to_solr
19
+ # puts tree.to_xcql
20
+ end
21
+ puts "done"
22
+ end
23
+ end
@@ -0,0 +1,54 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/cql_ruby'
3
+
4
+ class TestCqlLexer < Test::Unit::TestCase
5
+ def test_lexer
6
+ cl = CqlRuby::CqlLexer.new
7
+ cl.tokenize( "<a" )
8
+ assert_equal cl.tokenize( 'one' ), ["one"]
9
+ assert_equal cl.tokenize( 'one two'), ["one","two"]
10
+ assert_equal cl.tokenize( '"a b c"'), ['"a b c"']
11
+ assert_equal cl.tokenize( '"a ( b ) c"'), ['"a ( b ) c"']
12
+ assert_raises( CqlRuby::CqlException ) { cl.tokenize( '"a ( b ) c') }
13
+
14
+ c0 = CqlRuby::CqlLexer.new( '<a' )
15
+ assert_equal( '<', c0.next_token )
16
+ assert_equal( 'a', c0.next_token )
17
+
18
+ c2 = CqlRuby::CqlLexer.new( 'abc 123 "a b c" x < <a and OR Not prox sortby >= <> <= ==' )
19
+ c2.next_token
20
+ assert_equal( CqlRuby::CqlLexer::TT_WORD, c2.token_type )
21
+ assert( c2.word? )
22
+ c2.next_token
23
+ assert_equal( CqlRuby::CqlLexer::TT_NUMBER, c2.token_type )
24
+ assert( c2.number? )
25
+ assert_equal( '"', c2.next_token )
26
+ assert_equal( 'a b c', c2.value )
27
+ assert_equal( 'x', c2.next_token )
28
+ assert_equal( '<',c2.next_token )
29
+ assert_equal( '<', c2.next_token )
30
+ assert_equal( 'a', c2.next_token )
31
+ assert_equal( CqlRuby::CqlLexer::TT_AND , c2.next_token )
32
+ assert( c2.and? )
33
+ assert_equal( CqlRuby::CqlLexer::TT_OR, c2.next_token )
34
+ assert( c2.or? )
35
+ assert_equal( CqlRuby::CqlLexer::TT_NOT, c2.next_token )
36
+ assert( c2.not? )
37
+ assert_equal( CqlRuby::CqlLexer::TT_PROX, c2.next_token )
38
+ assert( c2.prox? )
39
+ assert_equal( CqlRuby::CqlLexer::TT_SORTBY, c2.next_token )
40
+ assert( c2.sortby? )
41
+ assert_equal( CqlRuby::CqlLexer::TT_GE, c2.next_token )
42
+ assert( c2.greater_than_or_equal? )
43
+ assert_equal( CqlRuby::CqlLexer::TT_NE, c2.next_token )
44
+ assert( c2.not_equal? )
45
+ assert_equal( CqlRuby::CqlLexer::TT_LE, c2.next_token )
46
+ assert( c2.less_than_or_equal? )
47
+ assert_equal( CqlRuby::CqlLexer::TT_EQEQ, c2.next_token )
48
+ assert( c2.double_equal? )
49
+ assert_equal( CqlRuby::CqlLexer::TT_EOF, c2.next_token )
50
+ assert( c2.eof? )
51
+
52
+ end
53
+ end
54
+
@@ -0,0 +1,105 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require File.dirname(__FILE__) + '/../lib/cql_ruby'
4
+
5
+ class TestCqlNodes < Test::Unit::TestCase
6
+ require 'builder'
7
+
8
+ def test_node
9
+ cn = CqlRuby::CqlNode.new
10
+
11
+ cp = CqlRuby::CqlPrefix.new( 'bob', 'jones')
12
+
13
+ es = <<-end_of_xml
14
+ <prefixes>
15
+ <prefix>
16
+ <name>bob</name>
17
+ <identifier>jones</identifier>
18
+ </prefix>
19
+ </prefixes>
20
+ end_of_xml
21
+
22
+ xml = Builder::XmlMarkup.new(:indent => 1)
23
+ assert_equal( es, cn.render_prefixes( xml, [cp] ) )
24
+
25
+
26
+ end
27
+
28
+ def test_modifier_set
29
+
30
+ end
31
+
32
+ def test_cql_relation_node
33
+ xml = Builder::XmlMarkup.new(:indent => 1)
34
+ relation = CqlRuby::CqlRelation.new( "=" )
35
+
36
+ assert_equal( "<relation>\n <value>=</value>\n</relation>\n", relation.to_xcql(xml) )
37
+ assert_equal( "=", relation.to_cql )
38
+ relation = CqlRuby::CqlRelation.new( "=" )
39
+
40
+ xml = Builder::XmlMarkup.new(:indent => 1)
41
+ assert_equal( "<relation>\n <value>=</value>\n</relation>\n", relation.to_xcql(xml) )
42
+ assert_equal( "=", relation.to_cql )
43
+ end
44
+
45
+ def test_modifier
46
+ modifier = CqlRuby::Modifier.new( "dog" )
47
+ assert_equal( "dog", modifier.to_cql )
48
+ modifier = CqlRuby::Modifier.new( "dog", "=", "cat" )
49
+ assert_equal( "dog = cat", modifier.to_cql )
50
+ end
51
+
52
+ def test_modifier_set
53
+ me = <<-end_of_modifier
54
+ <modifier>
55
+ <type>a</type>
56
+ <test>b</test>
57
+ <value>c</value>
58
+ </modifier>
59
+ end_of_modifier
60
+
61
+ m1 = CqlRuby::Modifier.new( 'a', 'b', 'c' )
62
+ assert_equal( "a b c", m1.to_cql() )
63
+ xml = Builder::XmlMarkup.new(:indent => 1)
64
+ assert_equal( me, m1.to_xcql( xml, "test") )
65
+ m1 = CqlRuby::Modifier.new( 'a' )
66
+ xml = Builder::XmlMarkup.new(:indent => 1)
67
+ assert_not_equal( me, m1.to_xcql( xml, "test") )
68
+
69
+ ms = CqlRuby::ModifierSet.new( "base" )
70
+ ms.add_modifier( "dog" )
71
+ assert_equal( "base/dog", ms.to_cql )
72
+ ms.add_modifier( "cat", "wont", "eat" )
73
+ assert_equal("base/dog/cat wont eat", ms.to_cql )
74
+ end
75
+
76
+ def test_cql_boolean_node
77
+ n1 = CqlRuby::CqlNode.new
78
+ n2 = CqlRuby::CqlNode.new
79
+ ms = CqlRuby::ModifierSet.new( "=" )
80
+
81
+ bn = CqlRuby::CqlBooleanNode.new( n1, n2, ms )
82
+ assert_equal( "() = ()", bn.to_cql )
83
+ # assert_equal( "() = ()", bn.to_xcql(0) )
84
+ end
85
+
86
+ def test_cql_term_node
87
+ rel = CqlRuby::CqlRelation.new( "likes" )
88
+ tn = CqlRuby::CqlTermNode.new( "dog", rel, "cat" )
89
+ assert_equal( "dog likes cat", tn.to_cql )
90
+ xml = Builder::XmlMarkup.new(:indent => 1)
91
+
92
+ expected = <<end_of_expected
93
+ <searchClause>
94
+ <index>dog</index>
95
+ <relation>
96
+ <value>likes</value>
97
+ </relation>
98
+ <term>cat</term>
99
+ </searchClause>
100
+ end_of_expected
101
+
102
+ xml = Builder::XmlMarkup.new(:indent => 1)
103
+ assert_equal( expected, tn.to_xcql(xml) )
104
+ end
105
+ end
@@ -0,0 +1,113 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/cql_ruby'
3
+
4
+ class TestCqlParser < Test::Unit::TestCase
5
+ def test_coverage
6
+ parser = CqlRuby::CqlParser.new
7
+ lines = IO.readlines( File.dirname(__FILE__) + '/fixtures/sample_queries.txt' )
8
+ lines.each do |line|
9
+ next if /^\s*#/ =~ line
10
+ begin
11
+ tree = parser.parse( line )
12
+ puts "in=#{line} out=#{tree.to_cql}" if tree
13
+ rescue Exception
14
+ puts "exception: line=#{line} error=#{$!}"
15
+ end
16
+ end
17
+ end
18
+
19
+ def test_parser
20
+ parser = CqlRuby::CqlParser.new
21
+ parser.debug = false
22
+
23
+
24
+ tree = parser.parse( ">fox=lynx dog = cat" )
25
+ assert_equal( '>fox="lynx" (dog = cat)', tree.to_cql )
26
+
27
+ assert_raises( CqlRuby::CqlException ) { parser.parse( "dog sortby" ) }
28
+
29
+ tree = parser.parse( "> dog cat" )
30
+ assert_equal( '>"dog" (cat)', tree.to_cql )
31
+
32
+ tree = parser.parse( "dc.title < cat" )
33
+ assert_equal( 'dc.title < cat', tree.to_cql )
34
+
35
+ tree = parser.parse( "dog ** fish" )
36
+ assert_equal( 'dog ** fish', tree.to_cql )
37
+
38
+ tree = parser.parse( "dog prox fish" )
39
+ assert_equal( '(dog) prox (fish)', tree.to_cql )
40
+
41
+ tree = parser.parse( "dog not fish" )
42
+ assert_equal( '(dog) not (fish)', tree.to_cql )
43
+
44
+ assert_raises( CqlRuby::CqlException ) { parser.parse( 'abc = "def' ) }
45
+
46
+ tree = parser.parse( "au=(Kerninghan or Ritchie) and ti=Unix" )
47
+ assert_equal( '((au = Kerninghan) or (au = Ritchie)) and (ti = Unix)', tree.to_cql )
48
+
49
+ query = 'cql.resultSetId = "resultA" and cql.resultSetId = "resultB"'
50
+ result = '(cql.resultSetId = resulta) and (cql.resultSetId = resultb)'
51
+ tree = parser.parse( query )
52
+ assert_equal( result.downcase, tree.to_cql.downcase )
53
+
54
+ query = 'dc.title any/relevant/rel.CORI "cat fish"'
55
+ tree = parser.parse( query )
56
+ assert_equal( query.downcase, tree.to_cql )
57
+
58
+ query = 'cql.resultSetId = "resultA" or cql.resultSetId = "resultB"'
59
+ tree = parser.parse( query )
60
+ result = '(cql.resultSetId = resultA) or (cql.resultSetId = resultB)'
61
+ assert_equal( result, tree.to_cql )
62
+
63
+ query = 'dc.title any/relevant/rel.CORI "cat fish" sortBy dc.date/sort.ascending'
64
+ tree = parser.parse( query )
65
+ puts "tree=#{tree.to_cql}="
66
+ assert_equal( 'dc.title any/relevant/rel.cori "cat fish" sortby dc.date/sort.ascending', tree.to_cql )
67
+
68
+ query = 'cql.resultSetId = "resultA" or cql.resultSetId = "resultB"'
69
+ result = '(cql.resultSetId = resulta) or (cql.resultSetId = resultb)'
70
+ tree = parser.parse( query )
71
+ assert_equal( result.downcase, tree.to_cql.downcase )
72
+
73
+ query = 'author = "smith"'
74
+ result = 'author = smith'
75
+ tree = parser.parse( query )
76
+ result1 = tree.to_cql
77
+ assert_equal( result, result1 )
78
+ tree = parser.parse( result1 )
79
+ result2 = tree.to_cql
80
+ assert_equal( result1, result2 )
81
+
82
+ result = <<end_of_result
83
+ <searchClause>
84
+ <index>
85
+ dc.title
86
+ </index>
87
+ <relation>
88
+ <value>
89
+ any
90
+ </value>
91
+ <modifiers>
92
+ <modifier>
93
+ <type>relevant</type>
94
+ </modifier>
95
+ <modifier>
96
+ <type>rel.cori</type>
97
+ </modifier>
98
+ </modifiers>
99
+ </relation>
100
+ <term>
101
+ cat fish
102
+ </term>
103
+ </searchClause>
104
+ end_of_result
105
+
106
+ tree = parser.parse( 'dc.title any/relevant/rel.CORI "cat fish"')
107
+ result.gsub!( /\s+/, '' )
108
+ tree_string = tree.to_xcql
109
+ tree_string.gsub!( /\s+/, '' )
110
+ assert_equal( result, tree_string )
111
+
112
+ end
113
+ end