activerdf 1.6.10 → 1.6.11

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ == activerdf (1.6.11) Thu, 27 Nov 2008 11:27:24 +0100
2
+ * added support for enabling/disabling adapters (Samur Saraujo)
3
+ * RDFS::Resource accepts block (Aleksander Pohl)
4
+
1
5
  == activerdf (1.6.10) Wed, 23 Apr 2008 10:43:44 +0200
2
6
  * convert float <-> xsd:double (Richard Dale)
3
7
  * fix #202979: superclass mismatch in literal.rb (Slava Kravchenko)
@@ -5,7 +5,11 @@ require 'queryengine/query2sparql'
5
5
 
6
6
  class ActiveRdfAdapter
7
7
  # indicate if adapter can read and write
8
- bool_accessor :reads, :writes
8
+ bool_accessor :reads, :writes, :enabled
9
+
10
+ def initialize
11
+ @enabled = true
12
+ end
9
13
 
10
14
  # translate a query to its string representation
11
15
  def translate(query)
@@ -54,11 +54,11 @@ class ConnectionPool
54
54
 
55
55
  # returns the set of currently registered read-access datasources
56
56
  def ConnectionPool.read_adapters
57
- @@adapter_pool.select {|adapter| adapter.reads? }
57
+ @@adapter_pool.select {|adapter| adapter.reads? && adapter.enabled?}
58
58
  end
59
59
 
60
60
  def ConnectionPool.write_adapters
61
- @@adapter_pool.select {|adapter| adapter.writes? }
61
+ @@adapter_pool.select {|adapter| adapter.writes? && adapter.enabled?}
62
62
  end
63
63
 
64
64
  # returns adapter-instance for given parameters (either existing or new)
@@ -10,7 +10,7 @@ class Namespace
10
10
  # e.g. :rdf and 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
11
11
  def self.register(prefix, fullURI)
12
12
  raise ActiveRdfError, 'prefix nor uri can be empty' if (prefix.to_s.empty? or fullURI.to_s.empty?)
13
- raise ActiveRdfError, "namespace uri should end with # or /" unless /\/|#/ =~ fullURI.to_s[-1..-1]
13
+ #raise ActiveRdfError, "namespace uri should end with # or /" unless /\/|#/ =~ fullURI.to_s[-1..-1]
14
14
  $activerdflog.info "Namespace: registering #{fullURI} to #{prefix}"
15
15
  @@namespaces[prefix.to_sym] = fullURI.to_s
16
16
  @@inverted_namespaces[fullURI.to_s] = prefix.to_sym
@@ -194,7 +194,7 @@ module RDFS
194
194
  end
195
195
 
196
196
  # manages invocations such as eyal.age
197
- def method_missing(method, *args)
197
+ def method_missing(method, *args,&block)
198
198
  # possibilities:
199
199
  # 1. eyal.age is a property of eyal (triple exists <eyal> <age> "30")
200
200
  # evidence: eyal age ?a, ?a is not nil (only if value exists)
@@ -250,7 +250,7 @@ module RDFS
250
250
  if update
251
251
  return set_predicate(@predicates[methodname], args)
252
252
  else
253
- return get_predicate(@predicates[methodname])
253
+ return get_predicate(@predicates[methodname],false,&block)
254
254
  end
255
255
  end
256
256
 
@@ -263,7 +263,7 @@ module RDFS
263
263
 
264
264
  # catch the invocation on the namespace
265
265
  class <<namespace
266
- def method_missing(localname, *values)
266
+ def method_missing(localname, *values,&block)
267
267
  update = localname.to_s[-1..-1] == '='
268
268
  predicate = if update
269
269
  Namespace.lookup(@@uri, localname.to_s[0..-2])
@@ -274,7 +274,7 @@ module RDFS
274
274
  if update
275
275
  @@subject.set_predicate(predicate, values)
276
276
  else
277
- @@subject.get_predicate(predicate, @@flatten)
277
+ @@subject.get_predicate(predicate, @@flatten,&block)
278
278
  end
279
279
  end
280
280
  private(:type)
@@ -294,7 +294,7 @@ module RDFS
294
294
  if update
295
295
  return set_predicate(pred, args)
296
296
  else
297
- return get_predicate(pred, flatten)
297
+ return get_predicate(pred, flatten,&block)
298
298
  end
299
299
  end
300
300
  end
@@ -422,8 +422,12 @@ module RDFS
422
422
  values
423
423
  end
424
424
 
425
- def get_predicate(predicate, flatten=false)
426
- values = Query.new.distinct(:o).where(self, predicate, :o).execute(:flatten => flatten)
425
+ def get_predicate(predicate, flatten=false,&block)
426
+ query = Query.new.distinct(:o).where(self, predicate, :o)
427
+ if block_given?
428
+ yield query, :o
429
+ end
430
+ values = query.execute(:flatten => flatten)
427
431
 
428
432
  # TODO: fix '<<' for Fixnum values etc (we cannot use values.instance_eval
429
433
  # because Fixnum cannot do instace_eval, they're not normal classes)
@@ -140,6 +140,6 @@ class TestFederationManager < Test::Unit::TestCase
140
140
  # in parallel for distinct data, actually gives same results as querying
141
141
  # only the one set
142
142
  uniq = Query.new.distinct(:s,:p,:o).where(:s,:p,:o).execute
143
- assert_equal first, uniq
143
+ assert_equal first.sort, uniq.sort
144
144
  end
145
145
  end
@@ -82,13 +82,14 @@ class TestObjectManager < Test::Unit::TestCase
82
82
  </rdf:Description>
83
83
  </rdf:RDF>'
84
84
  assert eyal.to_xml.include?(snippet)
85
-
86
-
87
- url = 'http://gollem.swi.psy.uva.nl/cgi-bin/rdf-parser'
85
+
86
+ require 'net/http'
87
+ url = 'http://librdf.org/parse'
88
88
  uri = URI.parse(url)
89
89
  req = Net::HTTP::Post.new(url)
90
- req.set_form_data('rdf' => eyal.to_xml)
91
- res = Net::HTTP.new(uri.host, uri.port).start { |http| http.request(req) }
92
- assert_match /RDF statement parsed successfully/, res.body, "SWI-Prolog failed to parse XML output"
90
+ req.set_form_data('content'=>eyal.to_xml, 'language'=>'rdfxml')
91
+ res = Net::HTTP.new(uri.host,uri.port).start {|http| http.request(req) }
92
+ result = res.body.match(/Found.*triples/)[0]
93
+ assert_equal "Found 4 triples", result, 'invalid XML generated (according to online parser at librdf.org'
93
94
  end
94
95
  end
@@ -134,4 +134,12 @@ class TestResourceReading < Test::Unit::TestCase
134
134
  assert_equal 1, RDFS::Resource.find_by_rdf::type(RDFS::Resource, :context => one).size
135
135
  assert_equal 1, RDFS::Resource.find_by_eye_and_rdf::type('blue', RDFS::Resource, :context => one).size
136
136
  end
137
+
138
+ def test_reading_with_block
139
+ qs=<<EOF
140
+ SELECT DISTINCT ?o WHERE { <http://activerdf.org/test/eyal>
141
+ <http://activerdf.org/test/age> ?o . FILTER (regex(lang(?o), '^nl$'))}
142
+ EOF
143
+ @eyal.age {|query, obj| query.lang(obj, "nl"); assert_equal qs.gsub("\n",'').strip, query.to_sp.strip}
144
+ end
137
145
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.10
4
+ version: 1.6.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eyal Oren
@@ -9,7 +9,7 @@ autorequire: active_rdf
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-04-23 00:00:00 +02:00
12
+ date: 2008-11-27 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  requirements: []
94
94
 
95
95
  rubyforge_project:
96
- rubygems_version: 1.0.1
96
+ rubygems_version: 1.1.1
97
97
  signing_key:
98
98
  specification_version: 2
99
99
  summary: Offers object-oriented access to RDF (with adapters to several datastores).