activerdf_redland 1.0 → 1.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.
- data/Rakefile +1 -1
- data/lib/activerdf_redland/redland.rb +13 -19
- metadata +2 -2
data/Rakefile
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
# Adapter to Redland database
|
2
|
-
# uses SPARQL for querying
|
3
|
-
#
|
4
1
|
# Author:: Eyal Oren
|
5
2
|
# Copyright:: (c) 2005-2006 Eyal Oren
|
6
3
|
# License:: LGPL
|
@@ -9,10 +6,10 @@ require 'federation/connection_pool'
|
|
9
6
|
require 'queryengine/query2sparql'
|
10
7
|
require 'rdf/redland'
|
11
8
|
|
12
|
-
#
|
13
|
-
|
9
|
+
# Adapter to Redland database
|
10
|
+
# uses SPARQL for querying
|
14
11
|
class RedlandAdapter < ActiveRdfAdapter
|
15
|
-
$
|
12
|
+
$activerdflog.info "loading Redland adapter"
|
16
13
|
ConnectionPool.register_adapter(:redland,self)
|
17
14
|
|
18
15
|
# instantiate connection to Redland database
|
@@ -28,7 +25,7 @@ class RedlandAdapter < ActiveRdfAdapter
|
|
28
25
|
type = 'memory'; path = ''; file = '.'
|
29
26
|
end
|
30
27
|
|
31
|
-
$
|
28
|
+
$activerdflog.info "RedlandAdapter: initializing with type: #{type} file: #{file} path: #{path}"
|
32
29
|
|
33
30
|
@store = Redland::HashStore.new(type, file, path, false)
|
34
31
|
@model = Redland::Model.new @store
|
@@ -40,7 +37,7 @@ class RedlandAdapter < ActiveRdfAdapter
|
|
40
37
|
# load a file from the given location with the given syntax into the model.
|
41
38
|
# use Redland syntax strings, e.g. "ntriples" or "rdfxml", defaults to "ntriples"
|
42
39
|
def load(location, syntax="ntriples")
|
43
|
-
$
|
40
|
+
$activerdflog.debug "Redland: loading file with syntax: #{syntax} and location: #{location}" if $activerdflog.level == Logger::DEBUG
|
44
41
|
parser = Redland::Parser.new(syntax, "", nil)
|
45
42
|
parser.parse_into_model(@model, "file:#{location}")
|
46
43
|
end
|
@@ -48,30 +45,27 @@ class RedlandAdapter < ActiveRdfAdapter
|
|
48
45
|
# yields query results (as many as requested in select clauses) executed on data source
|
49
46
|
def query(query)
|
50
47
|
qs = Query2SPARQL.translate(query)
|
51
|
-
$
|
48
|
+
$activerdflog.debug "RedlandAdapter: executing SPARQL query #{qs}" if $activerdflog.level == Logger::DEBUG
|
52
49
|
|
53
|
-
time = Time.now
|
54
50
|
clauses = query.select_clauses.size
|
55
51
|
redland_query = Redland::Query.new(qs, 'sparql')
|
56
52
|
query_results = @model.query_execute(redland_query)
|
57
|
-
$log.debug "RedlandAdapter: query response from Redland took: #{Time.now - time}s"
|
58
53
|
|
59
|
-
$
|
54
|
+
$activerdflog.debug "RedlandAdapter: found #{query_results.size} query results" if $activerdflog.level == Logger::DEBUG
|
60
55
|
|
61
56
|
# verify if the query has failed
|
62
57
|
if query_results.nil?
|
63
|
-
$
|
58
|
+
$activerdflog.debug "RedlandAdapter: query has failed with nil result" if $activerdflog.level == Logger::DEBUG
|
64
59
|
return false
|
65
60
|
end
|
66
61
|
if not query_results.is_bindings?
|
67
|
-
$
|
62
|
+
$activerdflog.debug "RedlandAdapter: query has failed without bindings" if $activerdflog.level == Logger::DEBUG
|
68
63
|
return false
|
69
64
|
end
|
70
65
|
|
71
66
|
# convert the result to array
|
72
67
|
#TODO: if block is given we should not parse all results into array first
|
73
68
|
results = query_result_to_array(query_results)
|
74
|
-
$log.debug "RedlandAdapter: result of query is #{results.join(', ')}"
|
75
69
|
|
76
70
|
if block_given?
|
77
71
|
results.each do |clauses|
|
@@ -115,16 +109,16 @@ class RedlandAdapter < ActiveRdfAdapter
|
|
115
109
|
|
116
110
|
# add triple to datamodel
|
117
111
|
def add(s, p, o)
|
118
|
-
$
|
112
|
+
$activerdflog.debug "adding triple #{s} #{p} #{o}" if $activerdflog.level == Logger::DEBUG
|
119
113
|
|
120
114
|
# verify input
|
121
115
|
if s.nil? || p.nil? || o.nil?
|
122
|
-
$
|
116
|
+
$activerdflog.debug "cannot add triple with empty subject, exiting" if $activerdflog.level == Logger::DEBUG
|
123
117
|
return false
|
124
118
|
end
|
125
119
|
|
126
120
|
unless s.respond_to?(:uri) && p.respond_to?(:uri)
|
127
|
-
$
|
121
|
+
$activerdflog.debug "cannot add triple where s/p are not resources, exiting" if $activerdflog.level == Logger::DEBUG
|
128
122
|
return false
|
129
123
|
end
|
130
124
|
|
@@ -132,7 +126,7 @@ class RedlandAdapter < ActiveRdfAdapter
|
|
132
126
|
@model.add(wrap(s), wrap(p), wrap(o))
|
133
127
|
save if ConnectionPool.auto_flush?
|
134
128
|
rescue Redland::RedlandError => e
|
135
|
-
$
|
129
|
+
$activerdflog.warn "RedlandAdapter: adding triple failed in Redland library: #{e}"
|
136
130
|
return false
|
137
131
|
end
|
138
132
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: activerdf_redland
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: "1.
|
7
|
-
date: 2006-
|
6
|
+
version: "1.1"
|
7
|
+
date: 2006-12-08 00:00:00 +00:00
|
8
8
|
summary: ActiveRDF adapter to Redland RDF store
|
9
9
|
require_paths:
|
10
10
|
- lib
|