activerdf_sparql 1.3.1 → 1.3.2
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.
- data/CHANGELOG +3 -0
- data/doc/rdoc/classes/SparqlAdapter.html +25 -12
- data/doc/rdoc/classes/SparqlAdapter.src/M000001.html +17 -14
- data/doc/rdoc/classes/SparqlAdapter.src/M000002.html +4 -4
- data/doc/rdoc/classes/SparqlAdapter.src/M000003.html +6 -8
- data/doc/rdoc/classes/SparqlAdapter.src/M000004.html +41 -38
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/lib/activerdf_sparql/sparql_rb.html +1 -1
- data/lib/activerdf_sparql/sparql.rb +14 -6
- data/test/test_sparql_adapter.rb +70 -87
- metadata +16 -16
data/CHANGELOG
CHANGED
@@ -110,6 +110,31 @@ SPARQL adapter
|
|
110
110
|
|
111
111
|
|
112
112
|
|
113
|
+
<div id="attribute-list">
|
114
|
+
<h3 class="section-bar">Attributes</h3>
|
115
|
+
|
116
|
+
<div class="name-list">
|
117
|
+
<table>
|
118
|
+
<tr class="top-aligned-row context-row">
|
119
|
+
<td class="context-item-name">engine</td>
|
120
|
+
<td class="context-item-value"> [R] </td>
|
121
|
+
<td class="context-item-desc">
|
122
|
+
Instantiate the connection with the SPARQL Endpoint. available parameters:
|
123
|
+
|
124
|
+
<ul>
|
125
|
+
<li>:url => url: endpoint location e.g. "<a
|
126
|
+
href="http://m3pe.org:8080/repositories/test-people">m3pe.org:8080/repositories/test-people</a>"
|
127
|
+
|
128
|
+
</li>
|
129
|
+
<li>:results => one of :xml, :json, :sparql_xml
|
130
|
+
|
131
|
+
</li>
|
132
|
+
</ul>
|
133
|
+
</td>
|
134
|
+
</tr>
|
135
|
+
</table>
|
136
|
+
</div>
|
137
|
+
</div>
|
113
138
|
|
114
139
|
|
115
140
|
|
@@ -128,18 +153,6 @@ SPARQL adapter
|
|
128
153
|
</div>
|
129
154
|
|
130
155
|
<div class="method-description">
|
131
|
-
<p>
|
132
|
-
Instantiate the connection with the SPARQL Endpoint. available parameters:
|
133
|
-
</p>
|
134
|
-
<ul>
|
135
|
-
<li>:url => url: endpoint location e.g. "<a
|
136
|
-
href="http://m3pe.org:8080/repositories/test-people">m3pe.org:8080/repositories/test-people</a>"
|
137
|
-
|
138
|
-
</li>
|
139
|
-
<li>:results => one of :xml, :json, :sparql_xml
|
140
|
-
|
141
|
-
</li>
|
142
|
-
</ul>
|
143
156
|
</div>
|
144
157
|
</div>
|
145
158
|
|
@@ -10,19 +10,22 @@
|
|
10
10
|
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
11
|
</head>
|
12
12
|
<body class="standalone-code">
|
13
|
-
<pre> <span class="ruby-comment cmt"># File lib/activerdf_sparql/sparql.rb, line
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
13
|
+
<pre> <span class="ruby-comment cmt"># File lib/activerdf_sparql/sparql.rb, line 19</span>
|
14
|
+
19: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">params</span> = {})
|
15
|
+
20: <span class="ruby-ivar">@reads</span> = <span class="ruby-keyword kw">true</span>
|
16
|
+
21: <span class="ruby-ivar">@writes</span> = <span class="ruby-keyword kw">false</span>
|
17
|
+
22:
|
18
|
+
23: <span class="ruby-ivar">@url</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:url</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">''</span>
|
19
|
+
24: <span class="ruby-ivar">@result_format</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:results</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">:json</span>
|
20
|
+
25: <span class="ruby-ivar">@engine</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:engine</span>]
|
21
|
+
26:
|
22
|
+
27: <span class="ruby-identifier">supported_engines</span> = [<span class="ruby-identifier">:yars2</span>, <span class="ruby-identifier">:sesame2</span>, <span class="ruby-identifier">:joseki</span>, <span class="ruby-identifier">:virtuoso</span>]
|
23
|
+
28: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ActiveRdfError</span>, <span class="ruby-value str">"SPARQL engine unsupported"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">supported_engines</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-ivar">@engine</span>)
|
24
|
+
29:
|
25
|
+
30: <span class="ruby-identifier">known_formats</span> = [<span class="ruby-identifier">:xml</span>, <span class="ruby-identifier">:json</span>, <span class="ruby-identifier">:sparql_xml</span>]
|
26
|
+
31: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ActiveRdfError</span>, <span class="ruby-value str">"Result format unsupported"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">known_formats</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-ivar">@result_format</span>)
|
27
|
+
32:
|
28
|
+
33: <span class="ruby-identifier">$activerdflog</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">"SPARQL adapter initialised #{inspect}"</span>
|
29
|
+
34: <span class="ruby-keyword kw">end</span></pre>
|
27
30
|
</body>
|
28
31
|
</html>
|
@@ -10,9 +10,9 @@
|
|
10
10
|
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
11
|
</head>
|
12
12
|
<body class="standalone-code">
|
13
|
-
<pre> <span class="ruby-comment cmt"># File lib/activerdf_sparql/sparql.rb, line
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
<pre> <span class="ruby-comment cmt"># File lib/activerdf_sparql/sparql.rb, line 36</span>
|
14
|
+
36: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">size</span>
|
15
|
+
37: <span class="ruby-identifier">query</span>(<span class="ruby-constant">Query</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">select</span>(<span class="ruby-identifier">:s</span>,<span class="ruby-identifier">:p</span>,<span class="ruby-identifier">:o</span>).<span class="ruby-identifier">where</span>(<span class="ruby-identifier">:s</span>,<span class="ruby-identifier">:p</span>,<span class="ruby-identifier">:o</span>)).<span class="ruby-identifier">size</span>
|
16
|
+
38: <span class="ruby-keyword kw">end</span></pre>
|
17
17
|
</body>
|
18
18
|
</html>
|
@@ -10,13 +10,11 @@
|
|
10
10
|
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
11
|
</head>
|
12
12
|
<body class="standalone-code">
|
13
|
-
<pre> <span class="ruby-comment cmt"># File lib/activerdf_sparql/sparql.rb, line
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
42: <span class="ruby-identifier">execute_sparql_query</span>(<span class="ruby-identifier">qs</span>, <span class="ruby-identifier">header</span>(<span class="ruby-identifier">query</span>), <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
20
|
-
43: <span class="ruby-keyword kw">end</span></pre>
|
13
|
+
<pre> <span class="ruby-comment cmt"># File lib/activerdf_sparql/sparql.rb, line 42</span>
|
14
|
+
42: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">query</span>(<span class="ruby-identifier">query</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
15
|
+
43: <span class="ruby-identifier">time</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>
|
16
|
+
44: <span class="ruby-identifier">qs</span> = <span class="ruby-constant">Query2SPARQL</span>.<span class="ruby-identifier">translate</span>(<span class="ruby-identifier">query</span>)
|
17
|
+
45: <span class="ruby-identifier">execute_sparql_query</span>(<span class="ruby-identifier">qs</span>, <span class="ruby-identifier">header</span>(<span class="ruby-identifier">query</span>), <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
18
|
+
46: <span class="ruby-keyword kw">end</span></pre>
|
21
19
|
</body>
|
22
20
|
</html>
|
@@ -10,43 +10,46 @@
|
|
10
10
|
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
11
|
</head>
|
12
12
|
<body class="standalone-code">
|
13
|
-
<pre> <span class="ruby-comment cmt"># File lib/activerdf_sparql/sparql.rb, line
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
13
|
+
<pre> <span class="ruby-comment cmt"># File lib/activerdf_sparql/sparql.rb, line 49</span>
|
14
|
+
49: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">execute_sparql_query</span>(<span class="ruby-identifier">qs</span>, <span class="ruby-identifier">header</span>=<span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
15
|
+
50: <span class="ruby-identifier">header</span> = <span class="ruby-identifier">header</span>(<span class="ruby-keyword kw">nil</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">header</span>.<span class="ruby-identifier">nil?</span>
|
16
|
+
51:
|
17
|
+
52: <span class="ruby-comment cmt"># encoding query string in URL</span>
|
18
|
+
53: <span class="ruby-identifier">url</span> = <span class="ruby-node">"#@url?query=#{CGI.escape(qs)}"</span>
|
19
|
+
54: <span class="ruby-comment cmt">#url += "&content-type=#{CGI.escape('application/sparql-results+xml')}" if @yars2</span>
|
20
|
+
55: <span class="ruby-identifier">url</span> = <span class="ruby-identifier">url</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">"DISTINCT"</span>, <span class="ruby-value str">""</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@yars2</span>
|
21
|
+
56: <span class="ruby-identifier">$activerdflog</span>.<span class="ruby-identifier">debug</span> <span class="ruby-node">"executing: requesting #{url}"</span>
|
22
|
+
57:
|
23
|
+
58: <span class="ruby-comment cmt"># querying sparql endpoint</span>
|
24
|
+
59: <span class="ruby-identifier">response</span> = <span class="ruby-value str">''</span>
|
25
|
+
60: <span class="ruby-keyword kw">begin</span>
|
26
|
+
61: <span class="ruby-identifier">open</span>(<span class="ruby-identifier">url</span>, <span class="ruby-identifier">header</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
|
27
|
+
62: <span class="ruby-identifier">response</span> = <span class="ruby-identifier">f</span>.<span class="ruby-identifier">read</span>
|
28
|
+
63: <span class="ruby-keyword kw">end</span>
|
29
|
+
64: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">OpenURI</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPError</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
30
|
+
65: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ActiveRdfError</span>, <span class="ruby-node">"could not query SPARQL endpoint, server said: #{e}"</span>
|
31
|
+
66: <span class="ruby-keyword kw">return</span> []
|
32
|
+
67: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ECONNREFUSED</span>
|
33
|
+
68: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ActiveRdfError</span>, <span class="ruby-value str">"connection refused on SPARQL endpoint #@url"</span>
|
34
|
+
69: <span class="ruby-keyword kw">return</span> []
|
35
|
+
70: <span class="ruby-keyword kw">end</span>
|
36
|
+
71: <span class="ruby-identifier">$activerdflog</span>.<span class="ruby-identifier">debug</span> <span class="ruby-node">"response:\n#{response}"</span>
|
37
|
+
72:
|
38
|
+
73: <span class="ruby-comment cmt"># we parse content depending on the result format</span>
|
39
|
+
74: <span class="ruby-identifier">results</span> = <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@result_format</span>
|
40
|
+
75: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:json</span>
|
41
|
+
76: <span class="ruby-identifier">parse_json</span>(<span class="ruby-identifier">response</span>)
|
42
|
+
77: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:xml</span>, <span class="ruby-identifier">:sparql_xml</span>
|
43
|
+
78: <span class="ruby-identifier">parse_xml</span>(<span class="ruby-identifier">response</span>)
|
44
|
+
79: <span class="ruby-keyword kw">end</span>
|
45
|
+
80:
|
46
|
+
81: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
47
|
+
82: <span class="ruby-identifier">results</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-operator">*</span><span class="ruby-identifier">clauses</span><span class="ruby-operator">|</span>
|
48
|
+
83: <span class="ruby-keyword kw">yield</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">clauses</span>)
|
49
|
+
84: <span class="ruby-keyword kw">end</span>
|
50
|
+
85: <span class="ruby-keyword kw">else</span>
|
51
|
+
86: <span class="ruby-identifier">results</span>
|
52
|
+
87: <span class="ruby-keyword kw">end</span>
|
53
|
+
88: <span class="ruby-keyword kw">end</span></pre>
|
51
54
|
</body>
|
52
55
|
</html>
|
data/doc/rdoc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Thu, 09 Aug 2007 15:13:42 +0100
|
@@ -4,7 +4,7 @@ require 'open-uri'
|
|
4
4
|
require 'cgi'
|
5
5
|
require 'rexml/document'
|
6
6
|
require "#{File.dirname(__FILE__)}/sparql_result_parser"
|
7
|
-
|
7
|
+
|
8
8
|
# SPARQL adapter
|
9
9
|
class SparqlAdapter < ActiveRdfAdapter
|
10
10
|
$activerdflog.info "loading SPARQL adapter"
|
@@ -14,18 +14,23 @@ class SparqlAdapter < ActiveRdfAdapter
|
|
14
14
|
# available parameters:
|
15
15
|
# * :url => url: endpoint location e.g. "http://m3pe.org:8080/repositories/test-people"
|
16
16
|
# * :results => one of :xml, :json, :sparql_xml
|
17
|
+
attr_reader :engine
|
18
|
+
|
17
19
|
def initialize(params = {})
|
18
20
|
@reads = true
|
19
21
|
@writes = false
|
20
22
|
|
21
23
|
@url = params[:url] || ''
|
22
24
|
@result_format = params[:results] || :json
|
25
|
+
@engine = params[:engine]
|
26
|
+
|
27
|
+
supported_engines = [:yars2, :sesame2, :joseki, :virtuoso]
|
28
|
+
raise ActiveRdfError, "SPARQL engine unsupported" unless supported_engines.include?(@engine)
|
23
29
|
|
24
30
|
known_formats = [:xml, :json, :sparql_xml]
|
25
|
-
raise ActiveRdfError, "Result format unsupported" unless
|
26
|
-
known_formats.include?(@result_format)
|
31
|
+
raise ActiveRdfError, "Result format unsupported" unless known_formats.include?(@result_format)
|
27
32
|
|
28
|
-
$activerdflog.info "
|
33
|
+
$activerdflog.info "SPARQL adapter initialised #{inspect}"
|
29
34
|
end
|
30
35
|
|
31
36
|
def size
|
@@ -37,8 +42,6 @@ class SparqlAdapter < ActiveRdfAdapter
|
|
37
42
|
def query(query, &block)
|
38
43
|
time = Time.now
|
39
44
|
qs = Query2SPARQL.translate(query)
|
40
|
-
$activerdflog.debug "executing sparql query #{query}"
|
41
|
-
|
42
45
|
execute_sparql_query(qs, header(query), &block)
|
43
46
|
end
|
44
47
|
|
@@ -48,6 +51,8 @@ class SparqlAdapter < ActiveRdfAdapter
|
|
48
51
|
|
49
52
|
# encoding query string in URL
|
50
53
|
url = "#@url?query=#{CGI.escape(qs)}"
|
54
|
+
#url += "&content-type=#{CGI.escape('application/sparql-results+xml')}" if @yars2
|
55
|
+
url = url.gsub("DISTINCT", "") if @yars2
|
51
56
|
$activerdflog.debug "executing: requesting #{url}"
|
52
57
|
|
53
58
|
# querying sparql endpoint
|
@@ -63,6 +68,7 @@ class SparqlAdapter < ActiveRdfAdapter
|
|
63
68
|
raise ActiveRdfError, "connection refused on SPARQL endpoint #@url"
|
64
69
|
return []
|
65
70
|
end
|
71
|
+
$activerdflog.debug "response:\n#{response}"
|
66
72
|
|
67
73
|
# we parse content depending on the result format
|
68
74
|
results = case @result_format
|
@@ -96,6 +102,8 @@ class SparqlAdapter < ActiveRdfAdapter
|
|
96
102
|
|
97
103
|
# parse json query results into array
|
98
104
|
def parse_json(s)
|
105
|
+
# this will try to first load json with the native c extensions,
|
106
|
+
# and if this fails json_pure will be loaded
|
99
107
|
require 'json'
|
100
108
|
|
101
109
|
parsed_object = JSON.parse(s)
|
data/test/test_sparql_adapter.rb
CHANGED
@@ -7,12 +7,11 @@ require 'test/unit'
|
|
7
7
|
require 'federation/federation_manager'
|
8
8
|
require 'queryengine/query'
|
9
9
|
|
10
|
+
|
10
11
|
class TestSparqlAdapter < Test::Unit::TestCase
|
11
12
|
def setup
|
12
13
|
ConnectionPool.clear
|
13
|
-
|
14
|
-
:url => "http://m3pe.org:8080/repositories/test-people/",
|
15
|
-
:results => :sparql_xml)
|
14
|
+
@adapter = ConnectionPool.add(:type => :sparql, :url => 'http://dbpedia.org/sparql')
|
16
15
|
end
|
17
16
|
|
18
17
|
def teardown
|
@@ -22,97 +21,81 @@ class TestSparqlAdapter < Test::Unit::TestCase
|
|
22
21
|
assert_instance_of SparqlAdapter, @adapter
|
23
22
|
end
|
24
23
|
|
25
|
-
def
|
26
|
-
|
27
|
-
result = Query.new.select(:s).where(:s, Namespace.lookup(:rdf,:type), :t).execute.first
|
28
|
-
rescue
|
29
|
-
# don't fail if SPARQL server doesn't respond
|
30
|
-
else
|
31
|
-
assert_instance_of RDFS::Resource, result
|
32
|
-
|
33
|
-
second_result = Query.new.select(:s, :p).where(:s, :p, 27).execute.flatten
|
34
|
-
assert_equal 2, second_result.size
|
35
|
-
assert_instance_of RDFS::Resource, second_result[0]
|
36
|
-
assert_instance_of RDFS::Resource, second_result[1]
|
37
|
-
end
|
24
|
+
def test_language
|
25
|
+
Query.new.distinct(:o).where(:s,:p,:o).limit(2).lang('en').execute
|
38
26
|
end
|
39
27
|
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
28
|
+
def test_limit_offset
|
29
|
+
one = Query.new.select(:s).where(:s,:p,:o).limit(10).execute
|
30
|
+
assert_equal 10, one.size
|
31
|
+
|
32
|
+
one.all? do |r|
|
33
|
+
assert_instance_of RDFS::Resource, r
|
34
|
+
end
|
35
|
+
|
36
|
+
two = Query.new.select(:s).where(:s,:p,:o).limit(10).offset(1).execute
|
37
|
+
assert_equal 10, two.size
|
38
|
+
assert_equal one[1], two[0]
|
39
|
+
|
40
|
+
three = Query.new.select(:s).where(:s,:p,:o).limit(10).offset(0).execute
|
41
|
+
assert_equal one, three
|
51
42
|
end
|
52
43
|
|
53
|
-
def
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
44
|
+
def test_regex_filter
|
45
|
+
Namespace.register :yago, 'http://dbpedia.org/class/yago/'
|
46
|
+
Namespace.register :dbpedia, 'http://dbpedia.org/property/'
|
47
|
+
|
48
|
+
movies = Query.new.
|
49
|
+
select(:title).
|
50
|
+
where(:film, RDF.type, RDFS::Resource.new('http://dbpedia.org/class/yago/film')).
|
51
|
+
where(:film, RDFS.label, :title).
|
52
|
+
where(:title, RDFS::Resource.new('bif:contains'), 'kill').
|
53
|
+
filter_regex(:title, /Kill$/).execute
|
54
|
+
|
55
|
+
assert !movies.empty?
|
56
|
+
assert movies.all? {|m| m =~ /Kill$/ }
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_query_with_block
|
60
|
+
reached_block = false
|
61
|
+
Query.new.select(:s, :p).where(:s,:p,:o).limit(1).execute do |s, p|
|
62
|
+
reached_block = true
|
63
|
+
assert_equal RDFS::Resource, s.class
|
64
|
+
assert_equal RDFS::Resource, p.class
|
65
|
+
end
|
66
|
+
assert reached_block, "querying with a block does not work"
|
67
|
+
|
68
|
+
reached_block = false
|
69
|
+
Query.new.select(:s, :p).where(:s,:p,:o).limit(3).execute do |s, p|
|
70
|
+
reached_block = true
|
71
|
+
assert_equal RDFS::Resource, s.class
|
72
|
+
assert_equal RDFS::Resource, p.class
|
73
|
+
end
|
74
|
+
assert reached_block, "querying with a block does not work"
|
75
|
+
|
76
|
+
reached_block = false
|
77
|
+
Query.new.select(:s).where(:s,:p,:o).limit(3).execute do |s|
|
78
|
+
reached_block = true
|
79
|
+
assert_equal RDFS::Resource, s.class
|
80
|
+
end
|
81
|
+
|
82
|
+
assert reached_block, "querying with a block does not work"
|
65
83
|
end
|
66
84
|
|
67
|
-
def
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
:results => :sparql_xml)
|
77
|
-
|
78
|
-
second_size = Query.new.select(:o).where(:s, :p, :o).execute.size
|
79
|
-
|
80
|
-
ConnectionPool.clear
|
81
|
-
|
82
|
-
# now we ask both
|
83
|
-
ConnectionPool.add_data_source(:type => :sparql,
|
84
|
-
:url => "http://www.m3pe.org:8080/repositories/test-people/",
|
85
|
-
:results => :sparql_xml)
|
86
|
-
ConnectionPool.add_data_source(:type => :sparql,
|
87
|
-
:url => "http://www.m3pe.org:8080/repositories/mindpeople",
|
88
|
-
:results => :sparql_xml)
|
89
|
-
|
90
|
-
union_size = Query.new.select(:o).where(:s, :p, :o).execute.size
|
91
|
-
assert_equal union_size, first_size + second_size
|
92
|
-
rescue
|
93
|
-
end
|
85
|
+
def test_refuse_to_write
|
86
|
+
eyal = RDFS::Resource.new 'http://activerdf.org/test/eyal'
|
87
|
+
age = RDFS::Resource.new 'foaf:age'
|
88
|
+
test = RDFS::Resource.new 'test'
|
89
|
+
|
90
|
+
# NameError gets thown if the method is unknown
|
91
|
+
assert_raises NoMethodError do
|
92
|
+
@adapter.add(eyal, age, test)
|
93
|
+
end
|
94
94
|
end
|
95
95
|
|
96
|
-
def
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
type = RDFS::Resource.new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")
|
101
|
-
age = RDFS::Resource.new("http://activerdf.org/test/age")
|
102
|
-
person = RDFS::Resource.new("http://www.w3.org/2000/01/rdf-schema#Resource")
|
103
|
-
resource = RDFS::Resource.new("http://activerdf.org/test/Person")
|
104
|
-
|
105
|
-
color = Query.new.select(:o).where(eyal, eye,:o).execute.first
|
106
|
-
assert_equal 'blue', color
|
107
|
-
assert_instance_of String, color
|
108
|
-
|
109
|
-
age_result = Query.new.select(:o).where(eyal, age, :o).execute.first.to_i
|
110
|
-
assert_equal 27, age_result
|
111
|
-
|
112
|
-
types_result = Query.new.select(:o).where(eyal, type, :o).execute
|
113
|
-
assert types_result.include?(person)
|
114
|
-
assert types_result.include?(resource)
|
115
|
-
rescue
|
116
|
-
end
|
96
|
+
def test_literal_conversion
|
97
|
+
# test literal conversion
|
98
|
+
label = Query.new.distinct(:label).where(:s, RDFS::label, :label).limit(1).execute(:flatten)
|
99
|
+
assert_instance_of String, label
|
117
100
|
end
|
118
101
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: activerdf_sparql
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.3.
|
7
|
-
date: 2007-08-
|
6
|
+
version: 1.3.2
|
7
|
+
date: 2007-08-09 00:00:00 +01:00
|
8
8
|
summary: ActiveRDF adapter to SPARQL endpoint
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -32,6 +32,15 @@ files:
|
|
32
32
|
- LICENSE
|
33
33
|
- README
|
34
34
|
- CHANGELOG
|
35
|
+
- doc/rdoc/rdoc-style.css
|
36
|
+
- doc/rdoc/files
|
37
|
+
- doc/rdoc/files/README.html
|
38
|
+
- doc/rdoc/files/LICENSE.html
|
39
|
+
- doc/rdoc/files/lib
|
40
|
+
- doc/rdoc/files/lib/activerdf_sparql
|
41
|
+
- doc/rdoc/files/lib/activerdf_sparql/sparql_rb.html
|
42
|
+
- doc/rdoc/files/lib/activerdf_sparql/init_rb.html
|
43
|
+
- doc/rdoc/files/lib/activerdf_sparql/sparql_result_parser_rb.html
|
35
44
|
- doc/rdoc/classes
|
36
45
|
- doc/rdoc/classes/SparqlAdapter.src
|
37
46
|
- doc/rdoc/classes/SparqlAdapter.src/M000001.html
|
@@ -47,20 +56,11 @@ files:
|
|
47
56
|
- doc/rdoc/classes/SparqlResultParser.src/M000010.html
|
48
57
|
- doc/rdoc/classes/SparqlAdapter.html
|
49
58
|
- doc/rdoc/classes/SparqlResultParser.html
|
50
|
-
- doc/rdoc/files
|
51
|
-
- doc/rdoc/files/lib
|
52
|
-
- doc/rdoc/files/lib/activerdf_sparql
|
53
|
-
- doc/rdoc/files/lib/activerdf_sparql/init_rb.html
|
54
|
-
- doc/rdoc/files/lib/activerdf_sparql/sparql_rb.html
|
55
|
-
- doc/rdoc/files/lib/activerdf_sparql/sparql_result_parser_rb.html
|
56
|
-
- doc/rdoc/files/LICENSE.html
|
57
|
-
- doc/rdoc/files/README.html
|
58
|
-
- doc/rdoc/created.rid
|
59
|
-
- doc/rdoc/fr_class_index.html
|
60
59
|
- doc/rdoc/fr_file_index.html
|
60
|
+
- doc/rdoc/fr_class_index.html
|
61
61
|
- doc/rdoc/fr_method_index.html
|
62
62
|
- doc/rdoc/index.html
|
63
|
-
- doc/rdoc/
|
63
|
+
- doc/rdoc/created.rid
|
64
64
|
- test/test_sparql_adapter.rb
|
65
65
|
- lib/activerdf_sparql
|
66
66
|
- lib/activerdf_sparql/sparql.rb
|
@@ -98,11 +98,11 @@ dependencies:
|
|
98
98
|
version: 0.9.2
|
99
99
|
version:
|
100
100
|
- !ruby/object:Gem::Dependency
|
101
|
-
name:
|
101
|
+
name: json_pure
|
102
102
|
version_requirement:
|
103
103
|
version_requirements: !ruby/object:Gem::Version::Requirement
|
104
104
|
requirements:
|
105
|
-
- - "
|
105
|
+
- - ">="
|
106
106
|
- !ruby/object:Gem::Version
|
107
|
-
version:
|
107
|
+
version: 1.1.1
|
108
108
|
version:
|