sparql 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +3 -0
- data/CREDITS +0 -0
- data/README.markdown +103 -53
- data/UNLICENSE +24 -0
- data/VERSION +1 -0
- data/bin/sparql +87 -0
- data/lib/sparql.rb +105 -22
- data/lib/sparql/algebra.rb +369 -0
- data/lib/sparql/algebra/evaluatable.rb +37 -0
- data/lib/sparql/algebra/expression.rb +284 -0
- data/lib/sparql/algebra/extensions.rb +159 -0
- data/lib/sparql/algebra/operator.rb +492 -0
- data/lib/sparql/algebra/operator/add.rb +34 -0
- data/lib/sparql/algebra/operator/and.rb +65 -0
- data/lib/sparql/algebra/operator/asc.rb +29 -0
- data/lib/sparql/algebra/operator/ask.rb +46 -0
- data/lib/sparql/algebra/operator/base.rb +46 -0
- data/lib/sparql/algebra/operator/bgp.rb +26 -0
- data/lib/sparql/algebra/operator/bound.rb +48 -0
- data/lib/sparql/algebra/operator/compare.rb +84 -0
- data/lib/sparql/algebra/operator/construct.rb +85 -0
- data/lib/sparql/algebra/operator/dataset.rb +77 -0
- data/lib/sparql/algebra/operator/datatype.rb +42 -0
- data/lib/sparql/algebra/operator/desc.rb +17 -0
- data/lib/sparql/algebra/operator/describe.rb +71 -0
- data/lib/sparql/algebra/operator/distinct.rb +50 -0
- data/lib/sparql/algebra/operator/divide.rb +43 -0
- data/lib/sparql/algebra/operator/equal.rb +32 -0
- data/lib/sparql/algebra/operator/exprlist.rb +52 -0
- data/lib/sparql/algebra/operator/filter.rb +71 -0
- data/lib/sparql/algebra/operator/graph.rb +28 -0
- data/lib/sparql/algebra/operator/greater_than.rb +32 -0
- data/lib/sparql/algebra/operator/greater_than_or_equal.rb +33 -0
- data/lib/sparql/algebra/operator/is_blank.rb +35 -0
- data/lib/sparql/algebra/operator/is_iri.rb +37 -0
- data/lib/sparql/algebra/operator/is_literal.rb +36 -0
- data/lib/sparql/algebra/operator/join.rb +67 -0
- data/lib/sparql/algebra/operator/lang.rb +29 -0
- data/lib/sparql/algebra/operator/lang_matches.rb +53 -0
- data/lib/sparql/algebra/operator/left_join.rb +95 -0
- data/lib/sparql/algebra/operator/less_than.rb +32 -0
- data/lib/sparql/algebra/operator/less_than_or_equal.rb +32 -0
- data/lib/sparql/algebra/operator/minus.rb +31 -0
- data/lib/sparql/algebra/operator/multiply.rb +34 -0
- data/lib/sparql/algebra/operator/not.rb +35 -0
- data/lib/sparql/algebra/operator/not_equal.rb +26 -0
- data/lib/sparql/algebra/operator/or.rb +65 -0
- data/lib/sparql/algebra/operator/order.rb +69 -0
- data/lib/sparql/algebra/operator/plus.rb +31 -0
- data/lib/sparql/algebra/operator/prefix.rb +45 -0
- data/lib/sparql/algebra/operator/project.rb +46 -0
- data/lib/sparql/algebra/operator/reduced.rb +47 -0
- data/lib/sparql/algebra/operator/regex.rb +70 -0
- data/lib/sparql/algebra/operator/same_term.rb +46 -0
- data/lib/sparql/algebra/operator/slice.rb +60 -0
- data/lib/sparql/algebra/operator/str.rb +35 -0
- data/lib/sparql/algebra/operator/subtract.rb +32 -0
- data/lib/sparql/algebra/operator/union.rb +55 -0
- data/lib/sparql/algebra/query.rb +99 -0
- data/lib/sparql/algebra/sxp_extensions.rb +35 -0
- data/lib/sparql/algebra/version.rb +20 -0
- data/lib/sparql/extensions.rb +102 -0
- data/lib/sparql/grammar.rb +298 -0
- data/lib/sparql/grammar/lexer.rb +609 -0
- data/lib/sparql/grammar/parser.rb +1383 -0
- data/lib/sparql/grammar/parser/meta.rb +1801 -0
- data/lib/sparql/results.rb +220 -0
- data/lib/sparql/version.rb +20 -0
- metadata +232 -62
- data/Rakefile +0 -22
- data/coverage/index.html +0 -252
- data/coverage/lib-sparql-execute_sparql_rb.html +0 -621
- data/coverage/lib-sparql_rb.html +0 -622
- data/lib/sparql/execute_sparql.rb +0 -27
- data/lib/sparql/sparql.treetop +0 -159
- data/sparql.gemspec +0 -16
- data/spec/spec.opts +0 -2
- data/spec/spec_helper.rb +0 -24
- data/spec/unit/graph_parsing_spec.rb +0 -76
- data/spec/unit/iri_parsing_spec.rb +0 -46
- data/spec/unit/prefixed_names_parsing_spec.rb +0 -40
- data/spec/unit/primitives_parsing_spec.rb +0 -26
- data/spec/unit/sparql_parsing_spec.rb +0 -72
- data/spec/unit/variables_parsing_spec.rb +0 -36
@@ -1,27 +0,0 @@
|
|
1
|
-
# This file is part of Sparql.rb.
|
2
|
-
#
|
3
|
-
# Sparql.rb is free software: you can redistribute it and/or modify
|
4
|
-
# it under the terms of the GNU Lesser General Public License as published by
|
5
|
-
# the Free Software Foundation, either version 3 of the License, or
|
6
|
-
# (at your option) any later version.
|
7
|
-
#
|
8
|
-
# Sparql.rb is distributed in the hope that it will be useful,
|
9
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
-
# GNU Lesser General Public License for more details.
|
12
|
-
#
|
13
|
-
# You should have received a copy of the GNU Lesser General Public License
|
14
|
-
# along with Sparql.rb. If not, see <http://www.gnu.org/licenses/>.
|
15
|
-
|
16
|
-
|
17
|
-
require 'rubygems'
|
18
|
-
require 'treetop'
|
19
|
-
|
20
|
-
Treetop.load "lib/sparql/primitives"
|
21
|
-
Treetop.load "lib/sparql/prefixed_names"
|
22
|
-
Treetop.load "lib/sparql/variables"
|
23
|
-
Treetop.load "lib/sparql/iri"
|
24
|
-
Treetop.load "lib/sparql/logical_expressions"
|
25
|
-
Treetop.load "lib/sparql/graph"
|
26
|
-
Treetop.load "lib/sparql/series"
|
27
|
-
Treetop.load "lib/sparql/sparql"
|
data/lib/sparql/sparql.treetop
DELETED
@@ -1,159 +0,0 @@
|
|
1
|
-
#!/usr/bin/env tt
|
2
|
-
# Author:: Pius Uzamere, The Uyiosa Corporation (http://uyiosa.com/)
|
3
|
-
# Copyright:: 2008 Pius Uzamere
|
4
|
-
|
5
|
-
# This file is part of Sparql.rb.
|
6
|
-
#
|
7
|
-
# Sparql.rb is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU Lesser General Public License as published by
|
9
|
-
# the Free Software Foundation, either version 3 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# Sparql.rb is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU Lesser General Public License for more details.
|
16
|
-
#
|
17
|
-
# You should have received a copy of the GNU Lesser General Public License
|
18
|
-
# along with Sparql.rb. If not, see <http://www.gnu.org/licenses/>.
|
19
|
-
|
20
|
-
grammar Sparql
|
21
|
-
include Primitives
|
22
|
-
include Variables
|
23
|
-
include LogicalExpressions
|
24
|
-
include Graph
|
25
|
-
include Series
|
26
|
-
|
27
|
-
# 'SELECT ?v WHERE { ?v ?p "cat"@en }'
|
28
|
-
|
29
|
-
rule query
|
30
|
-
prologue space query_part:( select_query / construct_query / describe_query / ask_query ) {
|
31
|
-
def well_formed?
|
32
|
-
true #=> if a node has been identified as a query, it's well-formed by definition.
|
33
|
-
end
|
34
|
-
}
|
35
|
-
end
|
36
|
-
|
37
|
-
rule prologue
|
38
|
-
base_decl? prefix_decl*
|
39
|
-
end
|
40
|
-
|
41
|
-
rule base_decl
|
42
|
-
'BASE' space iri_ref
|
43
|
-
end
|
44
|
-
|
45
|
-
rule prefix_decl
|
46
|
-
'PREFIX' space pname_ns space iri_ref
|
47
|
-
end
|
48
|
-
|
49
|
-
rule select_query
|
50
|
-
'SELECT' space (( 'DISTINCT' / 'REDUCED' ) space)? ( series_of_variables / '*' ) space (series_of_dataset_clauses space)? where space solution_modifier
|
51
|
-
{
|
52
|
-
def query_type
|
53
|
-
"SELECT"
|
54
|
-
end
|
55
|
-
}
|
56
|
-
end
|
57
|
-
|
58
|
-
rule ask_query
|
59
|
-
'ASK' space (series_of_dataset_clauses space)? where {
|
60
|
-
def query_type
|
61
|
-
"ASK"
|
62
|
-
end
|
63
|
-
}
|
64
|
-
end
|
65
|
-
|
66
|
-
rule describe_query
|
67
|
-
'DESCRIBE' space ( series_of_var_or_irirefs / '*' ) space (series_of_dataset_clauses space)? (where space)? solution_modifier {
|
68
|
-
def query_type
|
69
|
-
"DESCRIBE"
|
70
|
-
end
|
71
|
-
}
|
72
|
-
end
|
73
|
-
|
74
|
-
rule construct_query
|
75
|
-
'CONSTRUCT' space construct_template space (dataset_clause space)* (where space) solution_modifier {
|
76
|
-
def query_type
|
77
|
-
"CONSTRUCT"
|
78
|
-
end
|
79
|
-
}
|
80
|
-
end
|
81
|
-
|
82
|
-
rule where
|
83
|
-
('WHERE' space)? group_graph_pattern
|
84
|
-
end
|
85
|
-
|
86
|
-
rule construct_template
|
87
|
-
'{' space construct_triples? space '}'
|
88
|
-
end
|
89
|
-
|
90
|
-
rule construct_triples
|
91
|
-
triples_same_subject space ( '.' construct_triples? )?
|
92
|
-
end
|
93
|
-
|
94
|
-
rule solution_modifier
|
95
|
-
(order_clause space limit_offset_clauses)? / order_clause? / limit_offset_clauses?
|
96
|
-
end
|
97
|
-
|
98
|
-
rule order_clause
|
99
|
-
'ORDER BY' space series_of_order_conditions
|
100
|
-
end
|
101
|
-
|
102
|
-
rule offset_clause
|
103
|
-
'OFFSET' space integer
|
104
|
-
end
|
105
|
-
|
106
|
-
rule limit_clause
|
107
|
-
'LIMIT' space integer
|
108
|
-
end
|
109
|
-
|
110
|
-
rule limit_offset_clauses
|
111
|
-
( limit_clause space (offset_clause? / offset_clause space limit_clause?) )
|
112
|
-
end
|
113
|
-
|
114
|
-
rule order_condition
|
115
|
-
( ( 'ASC' / 'DESC' ) space bracketted_expression ) / ( constraint / var )
|
116
|
-
end
|
117
|
-
|
118
|
-
rule constraint
|
119
|
-
bracketted_expression / built_in_call / function_call
|
120
|
-
end
|
121
|
-
|
122
|
-
rule built_in_call
|
123
|
-
'STR' space '(' expression ')'
|
124
|
-
/ 'LANG' space '(' expression ')'
|
125
|
-
/ 'LANGMATCHES' space '(' expression ',' expression ')'
|
126
|
-
/ 'DATATYPE' space '(' expression ')' / 'BOUND' space '(' var ')'
|
127
|
-
/ 'sameTerm' '(' expression ',' expression ')'
|
128
|
-
/ 'isIRI' space '(' expression ')'
|
129
|
-
/ 'isURI' space '(' expression ')'
|
130
|
-
/ 'isBLANK' space '(' expression ')'
|
131
|
-
/ 'isLITERAL' space '(' expression ')'
|
132
|
-
/ regex_expression
|
133
|
-
end
|
134
|
-
|
135
|
-
rule regex_expression
|
136
|
-
'REGEX' space '(' expression ',' expression ( ',' expression )? ')'
|
137
|
-
end
|
138
|
-
|
139
|
-
rule function_call
|
140
|
-
iriref arg_list
|
141
|
-
end
|
142
|
-
|
143
|
-
rule dataset_clause
|
144
|
-
'FROM' space ( default_graph_clause / named_graph_clause )
|
145
|
-
end
|
146
|
-
|
147
|
-
rule default_graph_clause
|
148
|
-
source_selector
|
149
|
-
end
|
150
|
-
|
151
|
-
rule source_selector
|
152
|
-
iriref
|
153
|
-
end
|
154
|
-
|
155
|
-
rule named_graph_clause
|
156
|
-
'NAMED' space SourceSelector
|
157
|
-
end
|
158
|
-
|
159
|
-
end
|
data/sparql.gemspec
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
Gem::Specification.new do |s|
|
2
|
-
s.name = "sparql"
|
3
|
-
s.version = "0.0.1"
|
4
|
-
s.date = "2008-07-15"
|
5
|
-
s.summary = "SPARQL library for Ruby."
|
6
|
-
s.email = "pius+github@uyiosa.com"
|
7
|
-
s.homepage = "http://github.com/pius/sparql"
|
8
|
-
s.description = "sparql is a Ruby library for parsing SPARQL queries. Implements the formal grammar of SPARQL as a parsing expression grammar."
|
9
|
-
s.has_rdoc = true
|
10
|
-
s.authors = ['Pius Uzamere']
|
11
|
-
s.files = ["README.markdown", "Rakefile", "sparql.gemspec", "lib/sparql.rb", "lib/sparql/execute_sparql.rb", "lib/sparql/sparql.treetop", "coverage/index.html", "coverage/lib-sparql-execute_sparql_rb.html", "coverage/lib-sparql_rb.html"]
|
12
|
-
s.test_files = ["spec/spec.opts", "spec/spec_helper.rb", "spec/unit/graph_parsing_spec.rb", "spec/unit/graph_parsing_spec.rb", "spec/unit/iri_parsing_spec.rb", "spec/unit/sparql_parsing_spec.rb", "spec/unit/variables_parsing_spec.rb", "spec/unit/primitives_parsing_spec.rb", "spec/unit/prefixed_names_parsing_spec.rb"]
|
13
|
-
#s.rdoc_options = ["--main", "README.txt"]
|
14
|
-
#s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
|
15
|
-
s.add_dependency("treetop", [">= 1.2.4"])
|
16
|
-
end
|
data/spec/spec.opts
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'pathname'
|
3
|
-
require 'treetop'
|
4
|
-
|
5
|
-
# rule triples_same_subject
|
6
|
-
# var_or_term space property_list_not_empty / triples_node space property_list
|
7
|
-
# end
|
8
|
-
|
9
|
-
|
10
|
-
class Pathname
|
11
|
-
def /(path)
|
12
|
-
(self + path).expand_path
|
13
|
-
end
|
14
|
-
end # class Pathname
|
15
|
-
|
16
|
-
spec_dir_path = Pathname(__FILE__).dirname.expand_path
|
17
|
-
require spec_dir_path.parent + 'lib/sparql'
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
# require fixture resources
|
22
|
-
Dir[spec_dir_path + "fixtures/*.rb"].each do |fixture_file|
|
23
|
-
require fixture_file
|
24
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
# This file is part of Sparql.rb.
|
2
|
-
#
|
3
|
-
# Sparql.rb is free software: you can redistribute it and/or modify
|
4
|
-
# it under the terms of the GNU Lesser General Public License as published by
|
5
|
-
# the Free Software Foundation, either version 3 of the License, or
|
6
|
-
# (at your option) any later version.
|
7
|
-
#
|
8
|
-
# Sparql.rb is distributed in the hope that it will be useful,
|
9
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
-
# GNU Lesser General Public License for more details.
|
12
|
-
#
|
13
|
-
# You should have received a copy of the GNU Lesser General Public License
|
14
|
-
# along with Sparql.rb. If not, see <http://www.gnu.org/licenses/>.
|
15
|
-
|
16
|
-
require 'pathname'
|
17
|
-
|
18
|
-
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
19
|
-
|
20
|
-
describe "GraphParser", '#parse' do
|
21
|
-
|
22
|
-
before(:all) do
|
23
|
-
@parser = GraphParser.new
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should recognize a triple block where the predicate is a prefixed name" do
|
27
|
-
some_triple_block = '?x foaf:knows ?y'
|
28
|
-
@parser.parse(some_triple_block).should_not == nil
|
29
|
-
@parser.parse(some_triple_block).triples_same_subject.text_value.should == '?x foaf:knows ?y'
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should recognize a triple block where the predicate is a variable" do
|
33
|
-
some_triple_block = '?x ?theta ?y'
|
34
|
-
@parser.parse(some_triple_block).should_not == nil
|
35
|
-
@parser.parse(some_triple_block).triples_same_subject.text_value.should == '?x ?theta ?y'
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should recognize 'triples_same_subject'" do
|
39
|
-
some_triple_block = '?x foaf:knows ?y'
|
40
|
-
triples_same_subject = @parser.parse(some_triple_block).triples_same_subject
|
41
|
-
triples_same_subject.property_list_not_empty.text_value.should == "foaf:knows ?y"
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should recognize 'triples_same_subject' when the predicate is a variable" do
|
45
|
-
some_triple_block = '?x ?theta ?y'
|
46
|
-
triples_same_subject = @parser.parse(some_triple_block).triples_same_subject
|
47
|
-
triples_same_subject.property_list_not_empty.text_value.should == '?theta ?y'
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should recognize 'triples_same_subject' when the object is a literal" # do
|
51
|
-
# some_triple_block = '?x ?theta "foo"'
|
52
|
-
# triples_same_subject = @parser.parse(some_triple_block).triples_same_subject
|
53
|
-
# triples_same_subject.property_list_not_empty.text_value.should == '?theta ?y "foo"'
|
54
|
-
# end
|
55
|
-
|
56
|
-
it "should recognize a 'group_graph_pattern'" # do
|
57
|
-
# some_group_graph_pattern = '?v ?p "cat"'
|
58
|
-
# parsed = @parser.parse(some_group_graph_pattern)
|
59
|
-
# parsed.should_not == nil
|
60
|
-
# end
|
61
|
-
|
62
|
-
it "should recognize a 'graph_pattern_not_triples'" # do
|
63
|
-
# some_graph_pattern_not_triples = '{ ?v ?p "cat" }'
|
64
|
-
# parsed = @parser.parse(some_graph_pattern_not_triples)
|
65
|
-
# parsed.should_not == nil
|
66
|
-
# end
|
67
|
-
|
68
|
-
# it "should recognize a basic SELECT query with one variable and one triple pattern" do
|
69
|
-
# basic_valid_select_query = 'SELECT ?foo WHERE { ?x foaf:knows ?y . }'
|
70
|
-
# parser = SparqlParser.new
|
71
|
-
# parser.parse(basic_valid_select_query).well_formed?.should == true
|
72
|
-
# parser.parse(basic_valid_select_query).prologue.text_value.should == ""
|
73
|
-
# parser.parse(basic_valid_select_query).query_part.text_value.should == "SELECT ?foo WHERE { ?x foaf:knows ?y . }"
|
74
|
-
# parser.parse('SELECT ?foo ?bar WHERE { ?x foaf:knows ?y . ?z foaf:name ?y . }').should_not == nil
|
75
|
-
# end
|
76
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# This file is part of Sparql.rb.
|
2
|
-
#
|
3
|
-
# Sparql.rb is free software: you can redistribute it and/or modify
|
4
|
-
# it under the terms of the GNU Lesser General Public License as published by
|
5
|
-
# the Free Software Foundation, either version 3 of the License, or
|
6
|
-
# (at your option) any later version.
|
7
|
-
#
|
8
|
-
# Sparql.rb is distributed in the hope that it will be useful,
|
9
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
-
# GNU Lesser General Public License for more details.
|
12
|
-
#
|
13
|
-
# You should have received a copy of the GNU Lesser General Public License
|
14
|
-
# along with Sparql.rb. If not, see <http://www.gnu.org/licenses/>.
|
15
|
-
|
16
|
-
require 'pathname'
|
17
|
-
|
18
|
-
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
19
|
-
|
20
|
-
describe "IriParser", '#parse' do
|
21
|
-
|
22
|
-
before(:all) do
|
23
|
-
@parser = IriParser.new
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should be able to recognize an iriref in brackets" do
|
27
|
-
the_iriref = "<http://purl.org/dc/elements/1.1/title>"
|
28
|
-
@parser.parse(the_iriref).should_not == nil
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should be able to recognize an 'iri_ref'" do
|
32
|
-
the_iri_ref = "<http://xmlns.com/foaf/0.1/>"
|
33
|
-
@parser.parse(the_iri_ref).should_not == nil
|
34
|
-
end
|
35
|
-
|
36
|
-
# it "should be able to recognize an 'irirefchars'" do
|
37
|
-
# the_iriref = "<http://xmlns.com/foaf/0.1/>"
|
38
|
-
# @parser.parse(the_iriref).should_not == nil
|
39
|
-
# end
|
40
|
-
#
|
41
|
-
# it "should be able to recognize a 'prefixed_name'" do
|
42
|
-
# the_iriref = "<http://xmlns.com/foaf/0.1/>"
|
43
|
-
# @parser.parse(the_iriref).should_not == nil
|
44
|
-
# end
|
45
|
-
|
46
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# This file is part of Sparql.rb.
|
2
|
-
#
|
3
|
-
# Sparql.rb is free software: you can redistribute it and/or modify
|
4
|
-
# it under the terms of the GNU Lesser General Public License as published by
|
5
|
-
# the Free Software Foundation, either version 3 of the License, or
|
6
|
-
# (at your option) any later version.
|
7
|
-
#
|
8
|
-
# Sparql.rb is distributed in the hope that it will be useful,
|
9
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
-
# GNU Lesser General Public License for more details.
|
12
|
-
#
|
13
|
-
# You should have received a copy of the GNU Lesser General Public License
|
14
|
-
# along with Sparql.rb. If not, see <http://www.gnu.org/licenses/>.
|
15
|
-
|
16
|
-
require 'pathname'
|
17
|
-
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
18
|
-
|
19
|
-
describe "PrefixedNamesParser", '#parse' do
|
20
|
-
|
21
|
-
before(:all) do
|
22
|
-
@parser = PrefixedNamesParser.new
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should be able to recognize a common prefixed_name" do
|
26
|
-
the_pn = "foaf:knows"
|
27
|
-
tree = @parser.parse(the_pn)
|
28
|
-
tree.should_not == nil
|
29
|
-
tree.pname_ns.text_value.should == "foaf:"
|
30
|
-
tree.pn_local.text_value.should == "knows"
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should be able to recognize a prefixed_name whose local name has a leading digit (SPARQL idiosyncrasy)" do
|
34
|
-
the_pn = "foaf:1knows"
|
35
|
-
tree = @parser.parse(the_pn)
|
36
|
-
tree.should_not == nil
|
37
|
-
tree.pname_ns.text_value.should == "foaf:"
|
38
|
-
tree.pn_local.text_value.should == "1knows"
|
39
|
-
end
|
40
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# This file is part of Sparql.rb.
|
2
|
-
#
|
3
|
-
# Sparql.rb is free software: you can redistribute it and/or modify
|
4
|
-
# it under the terms of the GNU Lesser General Public License as published by
|
5
|
-
# the Free Software Foundation, either version 3 of the License, or
|
6
|
-
# (at your option) any later version.
|
7
|
-
#
|
8
|
-
# Sparql.rb is distributed in the hope that it will be useful,
|
9
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
-
# GNU Lesser General Public License for more details.
|
12
|
-
#
|
13
|
-
# You should have received a copy of the GNU Lesser General Public License
|
14
|
-
# along with Sparql.rb. If not, see <http://www.gnu.org/licenses/>.
|
15
|
-
|
16
|
-
require 'pathname'
|
17
|
-
|
18
|
-
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
19
|
-
|
20
|
-
describe "PrimitivesParser", '#parse' do
|
21
|
-
|
22
|
-
before(:all) do
|
23
|
-
@parser = PrimitivesParser.new
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
# This file is part of Sparql.rb.
|
2
|
-
#
|
3
|
-
# Sparql.rb is free software: you can redistribute it and/or modify
|
4
|
-
# it under the terms of the GNU Lesser General Public License as published by
|
5
|
-
# the Free Software Foundation, either version 3 of the License, or
|
6
|
-
# (at your option) any later version.
|
7
|
-
#
|
8
|
-
# Sparql.rb is distributed in the hope that it will be useful,
|
9
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
-
# GNU Lesser General Public License for more details.
|
12
|
-
#
|
13
|
-
# You should have received a copy of the GNU Lesser General Public License
|
14
|
-
# along with Sparql.rb. If not, see <http://www.gnu.org/licenses/>.
|
15
|
-
|
16
|
-
require 'pathname'
|
17
|
-
|
18
|
-
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
19
|
-
describe "SparqlParser", '#parse' do
|
20
|
-
|
21
|
-
before(:all) do
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should recognize a basic SELECT query with one variable and one triple pattern" do
|
25
|
-
basic_valid_select_query = 'SELECT ?foo WHERE { ?x foaf:knows ?y . }'
|
26
|
-
parser = SparqlParser.new
|
27
|
-
parser.parse(basic_valid_select_query).well_formed?.should == true
|
28
|
-
parser.parse(basic_valid_select_query).prologue.text_value.should == ""
|
29
|
-
parser.parse(basic_valid_select_query).query_part.text_value.should == "SELECT ?foo WHERE { ?x foaf:knows ?y . }"
|
30
|
-
parser.parse('SELECT ?foo ?bar WHERE { ?x foaf:knows ?y . ?z foaf:name ?y . }').should_not == nil
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should recognize a basic SELECT query with one variable, one triple pattern, and a PREFIX declaration" do
|
34
|
-
basic_valid_select_query_with_prologue = 'PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?foo WHERE { ?x foaf:knows ?y . }'
|
35
|
-
parser = SparqlParser.new
|
36
|
-
parser.parse(basic_valid_select_query_with_prologue).well_formed?.should == true
|
37
|
-
parser.parse(basic_valid_select_query_with_prologue).prologue.text_value.should == "PREFIX foaf: <http://xmlns.com/foaf/0.1/>"
|
38
|
-
parser.parse(basic_valid_select_query_with_prologue).query_part.text_value.should == "SELECT ?foo WHERE { ?x foaf:knows ?y . }"
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should recognize a basic SELECT query with one variable, two triple patterns, and a PREFIX declaration" do
|
42
|
-
query = 'PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?foo WHERE { ?x foaf:knows ?y . ?z foaf:knows ?x .}'
|
43
|
-
parser = SparqlParser.new
|
44
|
-
parser.parse(query).well_formed?.should == true
|
45
|
-
parser.parse(query).prologue.text_value.should == "PREFIX foaf: <http://xmlns.com/foaf/0.1/>"
|
46
|
-
parser.parse(query).query_part.text_value.should == "SELECT ?foo WHERE { ?x foaf:knows ?y . ?z foaf:knows ?x .}"
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should recognize a SELECT query with a literal" # do
|
50
|
-
# query = 'SELECT ?v WHERE { ?v ?p "cat" }'
|
51
|
-
# parser = SparqlParser.new
|
52
|
-
# parser.parse(query).well_formed?.should == true
|
53
|
-
# parser.parse(query).prologue.text_value.should == ""
|
54
|
-
# parser.parse(query).query_part.text_value.should == 'SELECT ?v WHERE { ?v ?p "cat"@en }'
|
55
|
-
# end
|
56
|
-
|
57
|
-
it "should recognize a SELECT query with a LANGTAG" # do
|
58
|
-
# query = 'SELECT ?v WHERE { ?v ?p "cat"@en }'
|
59
|
-
# parser = SparqlParser.new
|
60
|
-
# parser.parse(query).well_formed?.should == true
|
61
|
-
# parser.parse(query).prologue.text_value.should == ""
|
62
|
-
# parser.parse(query).query_part.text_value.should == 'SELECT ?v WHERE { ?v ?p "cat"@en }'
|
63
|
-
# end
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
it "should recognize a CONSTRUCT query"
|
69
|
-
it "should recognize an ASK query"
|
70
|
-
it "should recognize a DESCRIBE query"
|
71
|
-
|
72
|
-
end
|