Permalink
Browse files

Updated requires to expect proper $LOAD_PATH, removed __FILE__ refere…

…nces

Removed rubygems, gem_plugin dependencies
Rename test/common.rb to test/test_helper.rb

ConnectionPool now loads adapters on demand.

Removed unused instance_exec
Removed external_resource, ResourceLike
  • Loading branch information...
1 parent 9456c0b commit 1bfdcfce1b41c4e2f83890b05c2d09f9e79f318c @michaeldiamond michaeldiamond committed Apr 11, 2010
Showing with 379 additions and 525 deletions.
  1. +17 −23 Rakefile
  2. +0 −5 activerdf-jena/test/test_jena_adapter.rb
  3. +0 −5 activerdf-jena/test/test_ng4j_adapter.rb
  4. +2 −3 activerdf-rdflite/lib/activerdf_rdflite/rdflite.rb
  5. +72 −70 activerdf-rdflite/lib/activerdf_rdflite/suggesting.rb
  6. +2 −3 activerdf-rdflite/test/test_fetching.rb
  7. +5 −7 activerdf-rdflite/test/test_rdflite.rb
  8. +3 −2 activerdf-redland/lib/activerdf_redland/redland.rb
  9. +3 −4 activerdf-redland/test/test_redland_adapter.rb
  10. +3 −3 activerdf-sparql/lib/activerdf_sparql/sparql.rb
  11. +1 −1 activerdf-yars/lib/activerdf_yars/jars2.rb
  12. +49 −79 lib/active_rdf.rb
  13. 0 lib/{ → active_rdf}/active_rdf_helpers.rb
  14. 0 lib/{ → active_rdf}/active_rdf_log.rb
  15. +2 −2 lib/active_rdf/federation/active_rdf_adapter.rb
  16. +64 −22 lib/active_rdf/federation/connection_pool.rb
  17. +1 −1 lib/active_rdf/federation/federation_manager.rb
  18. +0 −13 lib/active_rdf/instance_exec.rb
  19. +0 −2 lib/active_rdf/objectmanager/bnode.rb
  20. +2 −2 lib/active_rdf/objectmanager/ordered_set.rb
  21. +3 −5 lib/active_rdf/objectmanager/resource.rb
  22. +0 −28 lib/active_rdf/objectmanager/resource_like.rb
  23. +1 −0 lib/active_rdf/queryengine/ntriples_parser.rb
  24. +2 −19 lib/active_rdf/queryengine/query.rb
  25. +1 −1 lib/active_rdf/queryengine/query2sparql.rb
  26. +1 −1 test/adapters/test_activerdf_adapter.rb
  27. +1 −3 test/adapters/test_adapters.rb
  28. +0 −101 test/common.rb
  29. +4 −5 test/federation/test_connection_pool.rb
  30. +20 −20 test/federation/test_federation_manager.rb
  31. +1 −2 test/objectmanager/test_namespace.rb
  32. +4 −4 test/objectmanager/test_object_manager.rb
  33. +3 −3 test/objectmanager/test_ordered_set.rb
  34. +1 −1 test/objectmanager/test_property.rb
  35. +1 −1 test/objectmanager/test_resource_reading.rb
  36. +1 −1 test/objectmanager/test_resource_reasoning.rb
  37. +1 −2 test/objectmanager/test_resource_writing.rb
  38. +0 −28 test/queryengine/my_external_resource.rb
  39. +0 −42 test/queryengine/test_external_resource_class.rb
  40. +2 −2 test/queryengine/test_ntriples_parser.rb
  41. +1 −2 test/queryengine/test_query.rb
  42. +2 −2 test/queryengine/test_query2jars2.rb
  43. +2 −2 test/queryengine/test_query2sparql.rb
  44. +2 −3 test/queryengine/test_query_engine.rb
  45. +99 −0 test/test_helper.rb
View
@@ -1,19 +1,16 @@
-require 'rubygems'
-
require 'rake'
require 'rake/testtask'
require 'rake/clean'
require 'rake/rdoctask'
-require 'tools/rakehelp'
require 'fileutils'
include FileUtils
+require 'tools/rakehelp'
+
$version = IO.read('VERSION').strip
$name = 'activerdf'
$distdir = "#$name-#$version"
-# setup tests and rdoc files
-setup_tests
setup_clean ["pkg", "lib/*.bundle", "*.gem", ".config"]
Rake::RDocTask.new do |rdoc|
@@ -27,22 +24,19 @@ Rake::RDocTask.new do |rdoc|
rdoc.options << '--line-numbers' << '--inline-source'
end
-
begin
require 'jeweler'
- Jeweler::Tasks.new do |s|
- s.name = 'activerdf_net7'
- s.summary = 'Offers object-oriented access to RDF (with adapters to several datastores). Version of the Talia project.'
- s.description = s.summary + ' THIS IS NOT THE OFFICIAL VERSION.'
- s.authors = ['Eyal Oren', 'The Talia Team']
- s.email = 'hahn@netseven.it'
- s.homepage = 'http://www.activerdf.org'
- s.platform = Gem::Platform::RUBY
- s.autorequire = 'active_rdf'
- s.add_dependency('gem_plugin', '>= 0.2.1')
- s.files = FileList["{lib}/**/*", "{activerdf}*/**/*"]
- s.extra_rdoc_files = ["README.rdoc", "CHANGELOG", "LICENSE"]
- s.add_dependency('grit', '>= 1.1.1')
+ Jeweler::Tasks.new do |gemspec|
+ gemspec.name = 'activerdf'
+ gemspec.summary = 'Offers object-oriented access to RDF (with adapters to several datastores).'
+ gemspec.description = gemspec.summary
+ gemspec.authors = ['Michael Diamond', 'Eyal Oren', 'The Talia Team']
+ gemspec.email = 'michael@thinknasium.org'
+ gemspec.homepage = 'http://www.activerdf.org'
+ gemspec.platform = Gem::Platform::RUBY
+ gemspec.autorequire = 'active_rdf'
+ gemspec.files = FileList["lib/**/*", "activerdf-*/**/*"]
+ gemspec.extra_rdoc_files = ["README.rdoc", "CHANGELOG", "LICENSE"]
end
Jeweler::GemcutterTasks.new
rescue LoadError
@@ -73,8 +67,8 @@ end
# define test_all task
Rake::TestTask.new do |t|
- t.name = :test_all
- t.test_files = FileList.new("test/**/*.rb", "activerdf-*/test/**/*.rb") do |fl|
- fl.exclude(/jena|sesame|sparql/i)
- end
+ t.libs << "test"
+ t.libs.concat FileList.new("activerdf-*/lib")
+ t.test_files = FileList.new("test/**/*.rb", "activerdf-*/test/**/*.rb")
+# t.test_files.exclude(/jena|sesame|sparql/i)
end
@@ -3,14 +3,9 @@
# License:: LGPL
require 'test/unit'
-require 'rubygems'
-
require "java"
-
require 'active_rdf'
-
require "pp"
-
require "fileutils"
class TestJenaAdapter < Test::Unit::TestCase
@@ -3,14 +3,9 @@
# License:: LGPL
require 'test/unit'
-require 'rubygems'
-
require "java"
-
require 'active_rdf'
-
require "pp"
-
require "fileutils"
class TestNG4JAdapter < Test::Unit::TestCase
@@ -3,10 +3,9 @@
# License:: LGPL
require 'sqlite3'
-require 'active_rdf'
-require 'federation/connection_pool'
+require 'active_rdf/federation/connection_pool'
+require 'active_rdf/queryengine/ntriples_parser'
require 'uuidtools'
-require 'queryengine/ntriples_parser'
require 'open-uri'
require 'mime/types'
@@ -9,79 +9,81 @@
# foaf:birthday. You can use this adapter in any collaborative editing setting:
# it leads the community to converge on terminology (everybody will use the
# same foaf:birthday to define somebody's birthday).
-class SuggestingAdapter < FetchingAdapter
- ConnectionPool.register_adapter(:suggesting,self)
-
- alias _old_initialize initialize
-
- # initialises the adapter, see RDFLite for description of possible parameters.
- def initialize params
- _old_initialize(params)
- @db.execute('drop view if exists occurrence')
- @db.execute('create view occurrence as select p, count(distinct s) as count from triple group by p')
-
- @db.execute('drop view if exists cooccurrence')
- @db.execute('create view cooccurrence as select t0.p as p1,t1.p as p2, count(distinct t0.s) as count from triple as t0 join triple as t1 on t0.s=t1.s and t0.p!=t1.p group by t0.p, t1.p')
- end
-
- # suggests additional predicates that might be applicable for the given resource
- def suggest(resource)
- ActiveRdfLogger::log_debug(self) { "Starting suggestions for #{size} triples" }
- time = Time.now
-
- predicates = []
- own_predicates = resource.direct_predicates
-
- construct_occurrence_matrix
- construct_cooccurrence_matrix
-
- own_predicates.each do |p|
- predicates << p if occurrence(p) > 1
+module ActiveRDF
+ class SuggestingAdapter < FetchingAdapter
+ ConnectionPool.register_adapter(:suggesting,self)
+
+ alias _old_initialize initialize
+
+ # initialises the adapter, see RDFLite for description of possible parameters.
+ def initialize params
+ _old_initialize(params)
+ @db.execute('drop view if exists occurrence')
+ @db.execute('create view occurrence as select p, count(distinct s) as count from triple group by p')
+
+ @db.execute('drop view if exists cooccurrence')
+ @db.execute('create view cooccurrence as select t0.p as p1,t1.p as p2, count(distinct t0.s) as count from triple as t0 join triple as t1 on t0.s=t1.s and t0.p!=t1.p group by t0.p, t1.p')
end
-
- # fetch all predicates co-occurring with our predicates
- candidates = predicates.collect {|p| cooccurring(p) }
- return nil if candidates.empty?
-
- # perform set intersection
- candidates = candidates.inject {|intersect, n| intersect & n }.flatten
- candidates = candidates - own_predicates
-
- suggestions = candidates.collect do |candidate|
- score = predicates.inject(1.0) do |score, p|
- score * cooccurrence(candidate, p) / occurrence(p)
+
+ # suggests additional predicates that might be applicable for the given resource
+ def suggest(resource)
+ ActiveRdfLogger::log_debug(self) { "Starting suggestions for #{size} triples" }
+ time = Time.now
+
+ predicates = []
+ own_predicates = resource.direct_predicates
+
+ construct_occurrence_matrix
+ construct_cooccurrence_matrix
+
+ own_predicates.each do |p|
+ predicates << p if occurrence(p) > 1
end
- [candidate, score]
+
+ # fetch all predicates co-occurring with our predicates
+ candidates = predicates.collect {|p| cooccurring(p) }
+ return nil if candidates.empty?
+
+ # perform set intersection
+ candidates = candidates.inject {|intersect, n| intersect & n }.flatten
+ candidates = candidates - own_predicates
+
+ suggestions = candidates.collect do |candidate|
+ score = predicates.inject(1.0) do |score, p|
+ score * cooccurrence(candidate, p) / occurrence(p)
+ end
+ [candidate, score]
+ end
+ ActiveRdfLogger::log_debug(self) { "Suggestions for #{resource} took #{Time.now-time}s" }
+ suggestions
end
- ActiveRdfLogger::log_debug(self) { "Suggestions for #{resource} took #{Time.now-time}s" }
- suggestions
- end
-
- private
- def construct_occurrence_matrix
- @occurrence = {}
- @db.execute('select * from occurrence where count > 1') do |p,count|
- @occurrence[parse(p)] = count.to_i
+
+ private
+ def construct_occurrence_matrix
+ @occurrence = {}
+ @db.execute('select * from occurrence where count > 1') do |p,count|
+ @occurrence[parse(p)] = count.to_i
+ end
end
- end
-
- def construct_cooccurrence_matrix
- @cooccurrence = {}
- @db.execute('select * from cooccurrence') do |p1, p2, count|
- @cooccurrence[parse(p1)] ||= {}
- @cooccurrence[parse(p1)][parse(p2)] = count.to_i
+
+ def construct_cooccurrence_matrix
+ @cooccurrence = {}
+ @db.execute('select * from cooccurrence') do |p1, p2, count|
+ @cooccurrence[parse(p1)] ||= {}
+ @cooccurrence[parse(p1)][parse(p2)] = count.to_i
+ end
+ end
+
+ def occurrence(predicate)
+ @occurrence[predicate] || 0
+ end
+
+ def cooccurrence(p1, p2)
+ @cooccurrence[p1][p2] || 0
+ end
+
+ def cooccurring(predicate)
+ @cooccurrence[predicate].keys
end
end
-
- def occurrence(predicate)
- @occurrence[predicate] || 0
- end
-
- def cooccurrence(p1, p2)
- @cooccurrence[p1][p2] || 0
- end
-
- def cooccurring(predicate)
- @cooccurrence[predicate].keys
- end
-end
+end
@@ -4,9 +4,8 @@
require 'test/unit'
require 'active_rdf'
-common_test_dir = File.dirname(File.expand_path(__FILE__)) + '/../../test'
-require "#{common_test_dir}/common"
-require "#{common_test_dir}/adapters/test_network_aware_adapter"
+require 'test_helper'
+require 'adapters/test_network_aware_adapter'
class TestFetchingAdapter < Test::Unit::TestCase
include SetupAdapter
@@ -2,15 +2,13 @@
# Copyright:: (c) 2005-2006
# License:: LGPL
-# require 'active_rdf'
require 'test/unit'
require 'active_rdf'
-common_test_dir = File.dirname(File.expand_path(__FILE__)) + '/../../test'
-require "#{common_test_dir}/adapters/test_persistent_adapter"
-require "#{common_test_dir}/adapters/test_bnode_capable_adapter"
-require "#{common_test_dir}/adapters/test_context_aware_adapter"
-require "#{common_test_dir}/adapters/test_network_aware_adapter"
-require "#{common_test_dir}/adapters/test_reasoning_adapter"
+require 'adapters/test_persistent_adapter'
+require 'adapters/test_bnode_capable_adapter'
+require 'adapters/test_context_aware_adapter'
+require 'adapters/test_network_aware_adapter'
+require 'adapters/test_reasoning_adapter'
class TestRdfLiteAdapter < Test::Unit::TestCase
@@ -1,8 +1,9 @@
# Author:: Eyal Oren
# Copyright:: (c) 2005-2006 Eyal Oren
# License:: LGPL
-require 'federation/connection_pool'
-require 'queryengine/query2sparql'
+
+require 'active_rdf/federation/connection_pool'
+require 'active_rdf/queryengine/query2sparql'
require 'rdf/redland'
# Adapter to Redland database
@@ -5,10 +5,9 @@
require 'test/unit'
require 'tmpdir'
require 'fileutils'
-common_test_dir = File.dirname(File.expand_path(__FILE__)) + '/../../test'
-require "#{common_test_dir}/adapters/test_writable_adapter"
-require "#{common_test_dir}/adapters/test_persistent_adapter"
-require "#{common_test_dir}/adapters/test_network_aware_adapter"
+require 'adapters/test_writable_adapter'
+require 'adapters/test_persistent_adapter'
+require 'adapters/test_network_aware_adapter'
module TestRedlandAdapter
include TestWritableAdapter
@@ -1,8 +1,8 @@
-require 'queryengine/query2sparql'
require 'open-uri'
require 'cgi'
require 'rexml/document'
-require "#{File.dirname(__FILE__)}/sparql_result_parser"
+require 'active_rdf/queryengine/query2sparql'
+require 'activerdf_sparql/sparql_result_parser'
module ActiveRDF
# SPARQL adapter
@@ -39,7 +39,7 @@ def initialize(params = {})
@result_format = params[:results] || :json
raise ActiveRdfError, "Result format unsupported" unless [:xml, :json, :sparql_xml].include? @result_format
- @engine = params[:engine]
+ @engine = params[:engine] || :virtuoso
raise ActiveRdfError, "SPARQL engine unsupported" unless [:yars2, :sesame2, :joseki, :virtuoso].include? @engine
@request_method = params[:request_method] || :get
@@ -2,7 +2,7 @@
# Copyright:: (c) 2005-2006
# License:: LGPL
-require 'queryengine/query2jars2'
+require 'active_rdf/queryengine/query2jars2'
require 'net/http'
require 'cgi'
Oops, something went wrong.

0 comments on commit 1bfdcfc

Please sign in to comment.