activerdf_sparql 1.3.2 → 1.3.3
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 +4 -0
- data/lib/activerdf_sparql/sparql.rb +5 -1
- data/test/test_sparql_adapter.rb +22 -10
- metadata +51 -85
- data/doc/rdoc/classes/SparqlAdapter.html +0 -225
- data/doc/rdoc/classes/SparqlAdapter.src/M000001.html +0 -31
- data/doc/rdoc/classes/SparqlAdapter.src/M000002.html +0 -18
- data/doc/rdoc/classes/SparqlAdapter.src/M000003.html +0 -20
- data/doc/rdoc/classes/SparqlAdapter.src/M000004.html +0 -55
- data/doc/rdoc/classes/SparqlResultParser.html +0 -236
- data/doc/rdoc/classes/SparqlResultParser.src/M000005.html +0 -20
- data/doc/rdoc/classes/SparqlResultParser.src/M000006.html +0 -27
- data/doc/rdoc/classes/SparqlResultParser.src/M000007.html +0 -23
- data/doc/rdoc/classes/SparqlResultParser.src/M000008.html +0 -20
- data/doc/rdoc/classes/SparqlResultParser.src/M000009.html +0 -25
- data/doc/rdoc/classes/SparqlResultParser.src/M000010.html +0 -17
- data/doc/rdoc/created.rid +0 -1
- data/doc/rdoc/files/LICENSE.html +0 -756
- data/doc/rdoc/files/README.html +0 -123
- data/doc/rdoc/files/lib/activerdf_sparql/init_rb.html +0 -114
- data/doc/rdoc/files/lib/activerdf_sparql/sparql_rb.html +0 -113
- data/doc/rdoc/files/lib/activerdf_sparql/sparql_result_parser_rb.html +0 -107
- data/doc/rdoc/fr_class_index.html +0 -28
- data/doc/rdoc/fr_file_index.html +0 -31
- data/doc/rdoc/fr_method_index.html +0 -36
- data/doc/rdoc/index.html +0 -24
- data/doc/rdoc/rdoc-style.css +0 -208
data/CHANGELOG
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
== activerdf_sparql (1.3.3)
|
2
|
+
* change Rakefile: require json_pure when running on JRuby
|
3
|
+
* added very simple close method to sparql adapter
|
4
|
+
|
1
5
|
== activerdf_sparql (1.3.2) Thu, 09 Aug 2007 15:10:16 +0100
|
2
6
|
* support for LANG filters and engine-specific keyword search
|
3
7
|
|
@@ -53,7 +53,7 @@ class SparqlAdapter < ActiveRdfAdapter
|
|
53
53
|
url = "#@url?query=#{CGI.escape(qs)}"
|
54
54
|
#url += "&content-type=#{CGI.escape('application/sparql-results+xml')}" if @yars2
|
55
55
|
url = url.gsub("DISTINCT", "") if @yars2
|
56
|
-
$activerdflog.debug "
|
56
|
+
$activerdflog.debug "querying #{url}"
|
57
57
|
|
58
58
|
# querying sparql endpoint
|
59
59
|
response = ''
|
@@ -87,6 +87,10 @@ class SparqlAdapter < ActiveRdfAdapter
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
+
def close
|
91
|
+
ConnectionPool.remove_data_source(self)
|
92
|
+
end
|
93
|
+
|
90
94
|
private
|
91
95
|
# constructs correct HTTP header for selected query-result format
|
92
96
|
def header(query)
|
data/test/test_sparql_adapter.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
# Copyright:: (c) 2005-2006
|
3
3
|
# License:: LGPL
|
4
4
|
|
5
|
+
require "rubygems"
|
5
6
|
require 'active_rdf'
|
6
7
|
require 'test/unit'
|
7
8
|
require 'federation/federation_manager'
|
@@ -11,7 +12,7 @@ require 'queryengine/query'
|
|
11
12
|
class TestSparqlAdapter < Test::Unit::TestCase
|
12
13
|
def setup
|
13
14
|
ConnectionPool.clear
|
14
|
-
@adapter = ConnectionPool.add(:type => :sparql, :url => 'http://dbpedia.org/sparql')
|
15
|
+
@adapter = ConnectionPool.add(:type => :sparql, :url => 'http://dbpedia.org/sparql', :engine => :virtuoso)
|
15
16
|
end
|
16
17
|
|
17
18
|
def teardown
|
@@ -22,7 +23,14 @@ class TestSparqlAdapter < Test::Unit::TestCase
|
|
22
23
|
end
|
23
24
|
|
24
25
|
def test_language
|
25
|
-
|
26
|
+
sunset = RDFS::Resource.new("http://dbpedia.org/resource/77_Sunset_Strip")
|
27
|
+
abstract = RDFS::Resource.new("http://dbpedia.org/property/abstract")
|
28
|
+
|
29
|
+
german = Query.new.distinct(:o).where(sunset,abstract,:o).limit(1).lang(:o,'de').execute.first
|
30
|
+
english = Query.new.distinct(:o).where(sunset,abstract,:o).limit(1).lang(:o,'en').execute.first
|
31
|
+
|
32
|
+
assert english =~ /^77 Sunset Strip was one of the most popular of the detective series in early television/
|
33
|
+
assert german =~ /^77 Sunset Strip ist ein Serienklassiker aus den USA um das gleichnamige, in Los Angeles am Sunset Boulevard angesiedelte Detektivbüro/
|
26
34
|
end
|
27
35
|
|
28
36
|
def test_limit_offset
|
@@ -45,15 +53,19 @@ class TestSparqlAdapter < Test::Unit::TestCase
|
|
45
53
|
Namespace.register :yago, 'http://dbpedia.org/class/yago/'
|
46
54
|
Namespace.register :dbpedia, 'http://dbpedia.org/property/'
|
47
55
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
56
|
+
begin
|
57
|
+
movies = Query.new.
|
58
|
+
select(:title).
|
59
|
+
where(:film, RDF.type, RDFS::Resource.new('http://dbpedia.org/class/yago/film')).
|
60
|
+
where(:film, RDFS.label, :title).
|
61
|
+
where(:title, RDFS::Resource.new('bif:contains'), 'kill').
|
62
|
+
filter_regex(:title, /Kill$/).execute
|
63
|
+
rescue TimeOut::Error => e
|
64
|
+
puts "WARNING: SPARQL endpoint timed out"
|
65
|
+
end
|
54
66
|
|
55
|
-
assert !movies.empty
|
56
|
-
assert movies.all? {|m| m =~ /Kill$/ }
|
67
|
+
assert !movies.empty?, "regex query returns empty results"
|
68
|
+
assert movies.all? {|m| m =~ /Kill$/ }, "regex query returns wrong results"
|
57
69
|
end
|
58
70
|
|
59
71
|
def test_query_with_block
|
metadata
CHANGED
@@ -1,108 +1,74 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
|
-
name: activerdf_sparql
|
5
|
-
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.3.2
|
7
|
-
date: 2007-08-09 00:00:00 +01:00
|
8
|
-
summary: ActiveRDF adapter to SPARQL endpoint
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email:
|
1
|
+
--- !ruby/object:Gem::Specification
|
12
2
|
homepage:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
25
|
-
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
3
|
+
extensions: []
|
4
|
+
executables: []
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 1.3.3
|
28
7
|
post_install_message:
|
29
|
-
|
30
|
-
- Eyal Oren <eyal.oren@deri.org
|
8
|
+
date: 2007-09-01 22:00:00 +00:00
|
31
9
|
files:
|
32
10
|
- LICENSE
|
33
11
|
- README
|
34
12
|
- 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
|
44
|
-
- doc/rdoc/classes
|
45
|
-
- doc/rdoc/classes/SparqlAdapter.src
|
46
|
-
- doc/rdoc/classes/SparqlAdapter.src/M000001.html
|
47
|
-
- doc/rdoc/classes/SparqlAdapter.src/M000002.html
|
48
|
-
- doc/rdoc/classes/SparqlAdapter.src/M000003.html
|
49
|
-
- doc/rdoc/classes/SparqlAdapter.src/M000004.html
|
50
|
-
- doc/rdoc/classes/SparqlResultParser.src
|
51
|
-
- doc/rdoc/classes/SparqlResultParser.src/M000005.html
|
52
|
-
- doc/rdoc/classes/SparqlResultParser.src/M000006.html
|
53
|
-
- doc/rdoc/classes/SparqlResultParser.src/M000007.html
|
54
|
-
- doc/rdoc/classes/SparqlResultParser.src/M000008.html
|
55
|
-
- doc/rdoc/classes/SparqlResultParser.src/M000009.html
|
56
|
-
- doc/rdoc/classes/SparqlResultParser.src/M000010.html
|
57
|
-
- doc/rdoc/classes/SparqlAdapter.html
|
58
|
-
- doc/rdoc/classes/SparqlResultParser.html
|
59
|
-
- doc/rdoc/fr_file_index.html
|
60
|
-
- doc/rdoc/fr_class_index.html
|
61
|
-
- doc/rdoc/fr_method_index.html
|
62
|
-
- doc/rdoc/index.html
|
63
|
-
- doc/rdoc/created.rid
|
64
13
|
- test/test_sparql_adapter.rb
|
65
14
|
- lib/activerdf_sparql
|
66
|
-
- lib/activerdf_sparql/sparql.rb
|
67
15
|
- lib/activerdf_sparql/init.rb
|
16
|
+
- lib/activerdf_sparql/sparql.rb
|
68
17
|
- lib/activerdf_sparql/sparql_result_parser.rb
|
69
|
-
|
70
|
-
|
18
|
+
rubygems_version: 0.9.4
|
71
19
|
rdoc_options: []
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
20
|
+
signing_key:
|
21
|
+
cert_chain:
|
22
|
+
name: activerdf_sparql
|
23
|
+
has_rdoc: true
|
24
|
+
platform: ruby
|
25
|
+
summary: ActiveRDF adapter to SPARQL endpoint
|
26
|
+
default_executable:
|
27
|
+
bindir: bin
|
28
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
29
|
+
version:
|
30
|
+
requirements:
|
31
|
+
- - '>'
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.0
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
specification_version: 1
|
37
|
+
test_files: []
|
81
38
|
dependencies:
|
82
|
-
- !ruby/object:Gem::Dependency
|
39
|
+
- !ruby/object:Gem::Dependency
|
83
40
|
name: gem_plugin
|
84
41
|
version_requirement:
|
85
|
-
version_requirements: !ruby/object:Gem::Version::Requirement
|
42
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
43
|
+
version:
|
86
44
|
requirements:
|
87
|
-
- -
|
88
|
-
- !ruby/object:Gem::Version
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
89
47
|
version: 0.2.1
|
90
|
-
|
91
|
-
- !ruby/object:Gem::Dependency
|
48
|
+
- !ruby/object:Gem::Dependency
|
92
49
|
name: activerdf
|
93
50
|
version_requirement:
|
94
|
-
version_requirements: !ruby/object:Gem::Version::Requirement
|
95
|
-
requirements:
|
96
|
-
- - ">="
|
97
|
-
- !ruby/object:Gem::Version
|
98
|
-
version: 0.9.2
|
51
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
99
52
|
version:
|
100
|
-
|
53
|
+
requirements:
|
54
|
+
- - '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.6.4
|
57
|
+
- !ruby/object:Gem::Dependency
|
101
58
|
name: json_pure
|
102
59
|
version_requirement:
|
103
|
-
version_requirements: !ruby/object:Gem::Version::Requirement
|
60
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
61
|
+
version:
|
104
62
|
requirements:
|
105
|
-
- -
|
106
|
-
- !ruby/object:Gem::Version
|
63
|
+
- - '>='
|
64
|
+
- !ruby/object:Gem::Version
|
107
65
|
version: 1.1.1
|
108
|
-
|
66
|
+
description: ActiveRDF adapter to SPARQL endpoint
|
67
|
+
authors:
|
68
|
+
- Eyal Oren <eyal.oren@deri.org
|
69
|
+
email:
|
70
|
+
extra_rdoc_files:
|
71
|
+
- README
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
autorequire:
|
@@ -1,225 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
-
<!DOCTYPE html
|
3
|
-
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
-
|
6
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
-
<head>
|
8
|
-
<title>Class: SparqlAdapter</title>
|
9
|
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
-
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
-
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
12
|
-
<script type="text/javascript">
|
13
|
-
// <![CDATA[
|
14
|
-
|
15
|
-
function popupCode( url ) {
|
16
|
-
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
-
}
|
18
|
-
|
19
|
-
function toggleCode( id ) {
|
20
|
-
if ( document.getElementById )
|
21
|
-
elem = document.getElementById( id );
|
22
|
-
else if ( document.all )
|
23
|
-
elem = eval( "document.all." + id );
|
24
|
-
else
|
25
|
-
return false;
|
26
|
-
|
27
|
-
elemStyle = elem.style;
|
28
|
-
|
29
|
-
if ( elemStyle.display != "block" ) {
|
30
|
-
elemStyle.display = "block"
|
31
|
-
} else {
|
32
|
-
elemStyle.display = "none"
|
33
|
-
}
|
34
|
-
|
35
|
-
return true;
|
36
|
-
}
|
37
|
-
|
38
|
-
// Make codeblocks hidden by default
|
39
|
-
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
-
|
41
|
-
// ]]>
|
42
|
-
</script>
|
43
|
-
|
44
|
-
</head>
|
45
|
-
<body>
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
<div id="classHeader">
|
50
|
-
<table class="header-table">
|
51
|
-
<tr class="top-aligned-row">
|
52
|
-
<td><strong>Class</strong></td>
|
53
|
-
<td class="class-name-in-header">SparqlAdapter</td>
|
54
|
-
</tr>
|
55
|
-
<tr class="top-aligned-row">
|
56
|
-
<td><strong>In:</strong></td>
|
57
|
-
<td>
|
58
|
-
<a href="../files/lib/activerdf_sparql/sparql_rb.html">
|
59
|
-
lib/activerdf_sparql/sparql.rb
|
60
|
-
</a>
|
61
|
-
<br />
|
62
|
-
</td>
|
63
|
-
</tr>
|
64
|
-
|
65
|
-
<tr class="top-aligned-row">
|
66
|
-
<td><strong>Parent:</strong></td>
|
67
|
-
<td>
|
68
|
-
ActiveRdfAdapter
|
69
|
-
</td>
|
70
|
-
</tr>
|
71
|
-
</table>
|
72
|
-
</div>
|
73
|
-
<!-- banner header -->
|
74
|
-
|
75
|
-
<div id="bodyContent">
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
<div id="contextContent">
|
80
|
-
|
81
|
-
<div id="description">
|
82
|
-
<p>
|
83
|
-
SPARQL adapter
|
84
|
-
</p>
|
85
|
-
|
86
|
-
</div>
|
87
|
-
|
88
|
-
|
89
|
-
</div>
|
90
|
-
|
91
|
-
<div id="method-list">
|
92
|
-
<h3 class="section-bar">Methods</h3>
|
93
|
-
|
94
|
-
<div class="name-list">
|
95
|
-
<a href="#M000004">execute_sparql_query</a>
|
96
|
-
<a href="#M000001">new</a>
|
97
|
-
<a href="#M000003">query</a>
|
98
|
-
<a href="#M000002">size</a>
|
99
|
-
</div>
|
100
|
-
</div>
|
101
|
-
|
102
|
-
</div>
|
103
|
-
|
104
|
-
|
105
|
-
<!-- if includes -->
|
106
|
-
|
107
|
-
<div id="section">
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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>
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
<!-- if method_list -->
|
142
|
-
<div id="methods">
|
143
|
-
<h3 class="section-bar">Public Class methods</h3>
|
144
|
-
|
145
|
-
<div id="method-M000001" class="method-detail">
|
146
|
-
<a name="M000001"></a>
|
147
|
-
|
148
|
-
<div class="method-heading">
|
149
|
-
<a href="SparqlAdapter.src/M000001.html" target="Code" class="method-signature"
|
150
|
-
onclick="popupCode('SparqlAdapter.src/M000001.html');return false;">
|
151
|
-
<span class="method-name">new</span><span class="method-args">(params = {})</span>
|
152
|
-
</a>
|
153
|
-
</div>
|
154
|
-
|
155
|
-
<div class="method-description">
|
156
|
-
</div>
|
157
|
-
</div>
|
158
|
-
|
159
|
-
<h3 class="section-bar">Public Instance methods</h3>
|
160
|
-
|
161
|
-
<div id="method-M000004" class="method-detail">
|
162
|
-
<a name="M000004"></a>
|
163
|
-
|
164
|
-
<div class="method-heading">
|
165
|
-
<a href="SparqlAdapter.src/M000004.html" target="Code" class="method-signature"
|
166
|
-
onclick="popupCode('SparqlAdapter.src/M000004.html');return false;">
|
167
|
-
<span class="method-name">execute_sparql_query</span><span class="method-args">(qs, header=nil) {|*clauses| ...}</span>
|
168
|
-
</a>
|
169
|
-
</div>
|
170
|
-
|
171
|
-
<div class="method-description">
|
172
|
-
<p>
|
173
|
-
do the real work of executing the sparql <a
|
174
|
-
href="SparqlAdapter.html#M000003">query</a>
|
175
|
-
</p>
|
176
|
-
</div>
|
177
|
-
</div>
|
178
|
-
|
179
|
-
<div id="method-M000003" class="method-detail">
|
180
|
-
<a name="M000003"></a>
|
181
|
-
|
182
|
-
<div class="method-heading">
|
183
|
-
<a href="SparqlAdapter.src/M000003.html" target="Code" class="method-signature"
|
184
|
-
onclick="popupCode('SparqlAdapter.src/M000003.html');return false;">
|
185
|
-
<span class="method-name">query</span><span class="method-args">(query, &block)</span>
|
186
|
-
</a>
|
187
|
-
</div>
|
188
|
-
|
189
|
-
<div class="method-description">
|
190
|
-
<p>
|
191
|
-
<a href="SparqlAdapter.html#M000003">query</a> datastore with <a
|
192
|
-
href="SparqlAdapter.html#M000003">query</a> string (SPARQL), returns array
|
193
|
-
with <a href="SparqlAdapter.html#M000003">query</a> results may be called
|
194
|
-
with a block
|
195
|
-
</p>
|
196
|
-
</div>
|
197
|
-
</div>
|
198
|
-
|
199
|
-
<div id="method-M000002" class="method-detail">
|
200
|
-
<a name="M000002"></a>
|
201
|
-
|
202
|
-
<div class="method-heading">
|
203
|
-
<a href="SparqlAdapter.src/M000002.html" target="Code" class="method-signature"
|
204
|
-
onclick="popupCode('SparqlAdapter.src/M000002.html');return false;">
|
205
|
-
<span class="method-name">size</span><span class="method-args">()</span>
|
206
|
-
</a>
|
207
|
-
</div>
|
208
|
-
|
209
|
-
<div class="method-description">
|
210
|
-
</div>
|
211
|
-
</div>
|
212
|
-
|
213
|
-
|
214
|
-
</div>
|
215
|
-
|
216
|
-
|
217
|
-
</div>
|
218
|
-
|
219
|
-
|
220
|
-
<div id="validator-badges">
|
221
|
-
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
222
|
-
</div>
|
223
|
-
|
224
|
-
</body>
|
225
|
-
</html>
|
@@ -1,31 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
-
<!DOCTYPE html
|
3
|
-
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
-
|
6
|
-
<html>
|
7
|
-
<head>
|
8
|
-
<title>new (SparqlAdapter)</title>
|
9
|
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
-
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
-
</head>
|
12
|
-
<body class="standalone-code">
|
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>
|
30
|
-
</body>
|
31
|
-
</html>
|
@@ -1,18 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
-
<!DOCTYPE html
|
3
|
-
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
-
|
6
|
-
<html>
|
7
|
-
<head>
|
8
|
-
<title>size (SparqlAdapter)</title>
|
9
|
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
-
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
-
</head>
|
12
|
-
<body class="standalone-code">
|
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
|
-
</body>
|
18
|
-
</html>
|
@@ -1,20 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
-
<!DOCTYPE html
|
3
|
-
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
-
|
6
|
-
<html>
|
7
|
-
<head>
|
8
|
-
<title>query (SparqlAdapter)</title>
|
9
|
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
-
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
-
</head>
|
12
|
-
<body class="standalone-code">
|
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>
|
19
|
-
</body>
|
20
|
-
</html>
|
@@ -1,55 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
-
<!DOCTYPE html
|
3
|
-
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
-
|
6
|
-
<html>
|
7
|
-
<head>
|
8
|
-
<title>execute_sparql_query (SparqlAdapter)</title>
|
9
|
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
-
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
-
</head>
|
12
|
-
<body class="standalone-code">
|
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>
|
54
|
-
</body>
|
55
|
-
</html>
|