activerdf_net7 1.6.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. data/CHANGELOG +79 -0
  2. data/LICENSE +504 -0
  3. data/README.rdoc +34 -0
  4. data/activerdf-jena/CHANGELOG +14 -0
  5. data/activerdf-jena/LICENSE +504 -0
  6. data/activerdf-jena/README +57 -0
  7. data/activerdf-jena/Rakefile +87 -0
  8. data/activerdf-jena/TODO +18 -0
  9. data/activerdf-jena/VERSION +1 -0
  10. data/activerdf-jena/ext/antlr-2.7.5.jar +0 -0
  11. data/activerdf-jena/ext/arq-extra.jar +0 -0
  12. data/activerdf-jena/ext/arq.jar +0 -0
  13. data/activerdf-jena/ext/aterm-java-1.6.jar +0 -0
  14. data/activerdf-jena/ext/commons-logging-1.1.jar +0 -0
  15. data/activerdf-jena/ext/concurrent.jar +0 -0
  16. data/activerdf-jena/ext/icu4j_3_4.jar +0 -0
  17. data/activerdf-jena/ext/iri.jar +0 -0
  18. data/activerdf-jena/ext/jena.jar +0 -0
  19. data/activerdf-jena/ext/jenatest.jar +0 -0
  20. data/activerdf-jena/ext/json.jar +0 -0
  21. data/activerdf-jena/ext/junit.jar +0 -0
  22. data/activerdf-jena/ext/log4j-1.2.12.jar +0 -0
  23. data/activerdf-jena/ext/lucene-core-2.0.0.jar +0 -0
  24. data/activerdf-jena/ext/ng4j.jar +0 -0
  25. data/activerdf-jena/ext/pellet.jar +0 -0
  26. data/activerdf-jena/ext/relaxngDatatype.jar +0 -0
  27. data/activerdf-jena/ext/stax-api-1.0.jar +0 -0
  28. data/activerdf-jena/ext/wstx-asl-3.0.0.jar +0 -0
  29. data/activerdf-jena/ext/xercesImpl.jar +0 -0
  30. data/activerdf-jena/ext/xml-apis.jar +0 -0
  31. data/activerdf-jena/ext/xsdlib.jar +0 -0
  32. data/activerdf-jena/lib/activerdf_jena/init.rb +26 -0
  33. data/activerdf-jena/lib/activerdf_jena/jena.rb +59 -0
  34. data/activerdf-jena/lib/activerdf_jena/jena_adapter.rb +515 -0
  35. data/activerdf-jena/lib/activerdf_jena/lucene.rb +22 -0
  36. data/activerdf-jena/lib/activerdf_jena/ng4j.rb +50 -0
  37. data/activerdf-jena/lib/activerdf_jena/ng4j_adapter.rb +379 -0
  38. data/activerdf-jena/lib/activerdf_jena/pellet.rb +25 -0
  39. data/activerdf-jena/test/bnode_org_rss.rdf +793 -0
  40. data/activerdf-jena/test/eyal-foaf.nt +39 -0
  41. data/activerdf-jena/test/fun_with_bnodes.nt +2 -0
  42. data/activerdf-jena/test/s1.n3 +18 -0
  43. data/activerdf-jena/test/test_data.nt +32 -0
  44. data/activerdf-jena/test/test_jena_adapter.rb +451 -0
  45. data/activerdf-jena/test/test_ng4j_adapter.rb +354 -0
  46. data/activerdf-rdflite/CHANGELOG +31 -0
  47. data/activerdf-rdflite/LICENSE +504 -0
  48. data/activerdf-rdflite/README +16 -0
  49. data/activerdf-rdflite/Rakefile +73 -0
  50. data/activerdf-rdflite/VERSION +1 -0
  51. data/activerdf-rdflite/lib/activerdf_rdflite/fetching.rb +34 -0
  52. data/activerdf-rdflite/lib/activerdf_rdflite/init.rb +13 -0
  53. data/activerdf-rdflite/lib/activerdf_rdflite/rdflite.rb +582 -0
  54. data/activerdf-rdflite/lib/activerdf_rdflite/suggesting.rb +87 -0
  55. data/activerdf-rdflite/test/test_bnode_data.nt +5 -0
  56. data/activerdf-rdflite/test/test_data.nt +32 -0
  57. data/activerdf-rdflite/test/test_escaped_data.nt +2 -0
  58. data/activerdf-rdflite/test/test_fetching.rb +33 -0
  59. data/activerdf-rdflite/test/test_rdflite.rb +277 -0
  60. data/activerdf-redland/CHANGELOG +12 -0
  61. data/activerdf-redland/LICENSE +504 -0
  62. data/activerdf-redland/README +9 -0
  63. data/activerdf-redland/Rakefile +72 -0
  64. data/activerdf-redland/VERSION +1 -0
  65. data/activerdf-redland/lib/activerdf_redland/init.rb +10 -0
  66. data/activerdf-redland/lib/activerdf_redland/redland.rb +362 -0
  67. data/activerdf-redland/test/test_person_data.nt +42 -0
  68. data/activerdf-redland/test/test_redland_adapter.rb +242 -0
  69. data/activerdf-sesame/CHANGELOG +6 -0
  70. data/activerdf-sesame/LICENSE +10 -0
  71. data/activerdf-sesame/LICENSE-aduna +10 -0
  72. data/activerdf-sesame/LICENSE-lgpl +504 -0
  73. data/activerdf-sesame/README +33 -0
  74. data/activerdf-sesame/Rakefile +77 -0
  75. data/activerdf-sesame/VERSION +1 -0
  76. data/activerdf-sesame/ext/commons-codec-1.3.jar +0 -0
  77. data/activerdf-sesame/ext/commons-dbcp-1.2.2.jar +0 -0
  78. data/activerdf-sesame/ext/commons-httpclient-3.1.jar +0 -0
  79. data/activerdf-sesame/ext/commons-logging-1.1.1.jar +0 -0
  80. data/activerdf-sesame/ext/commons-pool-1.3.jar +0 -0
  81. data/activerdf-sesame/ext/commons-pool-1.5.2.jar +0 -0
  82. data/activerdf-sesame/ext/junit-3.8.2.jar +0 -0
  83. data/activerdf-sesame/ext/openrdf-sesame-2.0-onejar.jar +0 -0
  84. data/activerdf-sesame/ext/openrdf-sesame-2.3-pr1-onejar.jar +0 -0
  85. data/activerdf-sesame/ext/slf4j-api-1.4.3.jar +0 -0
  86. data/activerdf-sesame/ext/slf4j-nop-1.4.3.jar +0 -0
  87. data/activerdf-sesame/ext/wrapper-sesame2.jar +0 -0
  88. data/activerdf-sesame/java/build.number +3 -0
  89. data/activerdf-sesame/java/build.xml +313 -0
  90. data/activerdf-sesame/java/javadoc/allclasses-frame.html +31 -0
  91. data/activerdf-sesame/java/javadoc/allclasses-noframe.html +31 -0
  92. data/activerdf-sesame/java/javadoc/constant-values.html +146 -0
  93. data/activerdf-sesame/java/javadoc/deprecated-list.html +146 -0
  94. data/activerdf-sesame/java/javadoc/help-doc.html +223 -0
  95. data/activerdf-sesame/java/javadoc/index-files/index-1.html +150 -0
  96. data/activerdf-sesame/java/javadoc/index-files/index-10.html +145 -0
  97. data/activerdf-sesame/java/javadoc/index-files/index-2.html +157 -0
  98. data/activerdf-sesame/java/javadoc/index-files/index-3.html +146 -0
  99. data/activerdf-sesame/java/javadoc/index-files/index-4.html +145 -0
  100. data/activerdf-sesame/java/javadoc/index-files/index-5.html +145 -0
  101. data/activerdf-sesame/java/javadoc/index-files/index-6.html +142 -0
  102. data/activerdf-sesame/java/javadoc/index-files/index-7.html +145 -0
  103. data/activerdf-sesame/java/javadoc/index-files/index-8.html +152 -0
  104. data/activerdf-sesame/java/javadoc/index-files/index-9.html +146 -0
  105. data/activerdf-sesame/java/javadoc/index.html +36 -0
  106. data/activerdf-sesame/java/javadoc/org/activerdf/wrapper/sesame2/WrapperForSesame2.html +665 -0
  107. data/activerdf-sesame/java/javadoc/org/activerdf/wrapper/sesame2/class-use/WrapperForSesame2.html +144 -0
  108. data/activerdf-sesame/java/javadoc/org/activerdf/wrapper/sesame2/package-frame.html +32 -0
  109. data/activerdf-sesame/java/javadoc/org/activerdf/wrapper/sesame2/package-summary.html +157 -0
  110. data/activerdf-sesame/java/javadoc/org/activerdf/wrapper/sesame2/package-tree.html +150 -0
  111. data/activerdf-sesame/java/javadoc/org/activerdf/wrapper/sesame2/package-use.html +144 -0
  112. data/activerdf-sesame/java/javadoc/overview-summary.html +156 -0
  113. data/activerdf-sesame/java/javadoc/overview-tree.html +152 -0
  114. data/activerdf-sesame/java/javadoc/package-list +1 -0
  115. data/activerdf-sesame/java/javadoc/resources/inherit.gif +0 -0
  116. data/activerdf-sesame/java/javadoc/stylesheet.css +29 -0
  117. data/activerdf-sesame/java/lib/commons-codec-1.3.jar +0 -0
  118. data/activerdf-sesame/java/lib/commons-dbcp-1.2.2.jar +0 -0
  119. data/activerdf-sesame/java/lib/commons-httpclient-3.1.jar +0 -0
  120. data/activerdf-sesame/java/lib/commons-logging-1.1.1.jar +0 -0
  121. data/activerdf-sesame/java/lib/commons-pool-1.3.jar +0 -0
  122. data/activerdf-sesame/java/lib/commons-pool-1.5.2.jar +0 -0
  123. data/activerdf-sesame/java/lib/junit-3.8.2.jar +0 -0
  124. data/activerdf-sesame/java/lib/openrdf-sesame-2.0-onejar.jar +0 -0
  125. data/activerdf-sesame/java/lib/openrdf-sesame-2.3-pr1-onejar.jar +0 -0
  126. data/activerdf-sesame/java/lib/slf4j-api-1.4.3.jar +0 -0
  127. data/activerdf-sesame/java/lib/slf4j-nop-1.4.3.jar +0 -0
  128. data/activerdf-sesame/java/manifest.mf +3 -0
  129. data/activerdf-sesame/java/settings.xml +135 -0
  130. data/activerdf-sesame/java/src/org/activerdf/wrapper/sesame2/WrapperForSesame2.java +145 -0
  131. data/activerdf-sesame/java/test-src/org/activerdf/wrapper/sesame2/TestWrapperForSesame2.java +41 -0
  132. data/activerdf-sesame/lib/activerdf_sesame/init.rb +11 -0
  133. data/activerdf-sesame/lib/activerdf_sesame/sesame.rb +400 -0
  134. data/activerdf-sesame/test/eyal-foaf.nt +39 -0
  135. data/activerdf-sesame/test/eyal-foaf.rdf +65 -0
  136. data/activerdf-sesame/test/test_sesame_adapter.rb +341 -0
  137. data/activerdf-sparql/CHANGELOG +35 -0
  138. data/activerdf-sparql/LICENSE +504 -0
  139. data/activerdf-sparql/README +10 -0
  140. data/activerdf-sparql/Rakefile +78 -0
  141. data/activerdf-sparql/VERSION +1 -0
  142. data/activerdf-sparql/lib/activerdf_sparql/init.rb +10 -0
  143. data/activerdf-sparql/lib/activerdf_sparql/sparql.rb +212 -0
  144. data/activerdf-sparql/lib/activerdf_sparql/sparql_result_parser.rb +55 -0
  145. data/activerdf-sparql/test/test_sparql_adapter.rb +108 -0
  146. data/activerdf-yars/LICENSE +504 -0
  147. data/activerdf-yars/README +10 -0
  148. data/activerdf-yars/Rakefile +38 -0
  149. data/activerdf-yars/lib/activerdf_yars/init.rb +10 -0
  150. data/activerdf-yars/lib/activerdf_yars/jars2.rb +119 -0
  151. data/lib/active_rdf.rb +85 -0
  152. data/lib/active_rdf/directaccess/direct_access.rb +49 -0
  153. data/lib/active_rdf/federation/active_rdf_adapter.rb +47 -0
  154. data/lib/active_rdf/federation/connection_pool.rb +156 -0
  155. data/lib/active_rdf/federation/federation_manager.rb +112 -0
  156. data/lib/active_rdf/instance_exec.rb +13 -0
  157. data/lib/active_rdf/objectmanager/bnode.rb +7 -0
  158. data/lib/active_rdf/objectmanager/literal.rb +71 -0
  159. data/lib/active_rdf/objectmanager/namespace.rb +106 -0
  160. data/lib/active_rdf/objectmanager/object_manager.rb +119 -0
  161. data/lib/active_rdf/objectmanager/ordered_set.rb +116 -0
  162. data/lib/active_rdf/objectmanager/property_list.rb +76 -0
  163. data/lib/active_rdf/objectmanager/resource.rb +609 -0
  164. data/lib/active_rdf/objectmanager/resource_like.rb +28 -0
  165. data/lib/active_rdf/queryengine/ntriples_parser.rb +90 -0
  166. data/lib/active_rdf/queryengine/query.rb +245 -0
  167. data/lib/active_rdf/queryengine/query2jars2.rb +22 -0
  168. data/lib/active_rdf/queryengine/query2sparql.rb +139 -0
  169. data/lib/active_rdf_helpers.rb +30 -0
  170. data/lib/active_rdf_log.rb +100 -0
  171. data/test/common.rb +119 -0
  172. data/test/directaccess/test_direct_access.rb +64 -0
  173. data/test/federation/test_connection_pool.rb +86 -0
  174. data/test/federation/test_federation_manager.rb +145 -0
  175. data/test/objectmanager/test_literal.rb +52 -0
  176. data/test/objectmanager/test_namespace.rb +83 -0
  177. data/test/objectmanager/test_object_manager.rb +96 -0
  178. data/test/objectmanager/test_ordered_set.rb +110 -0
  179. data/test/objectmanager/test_resource_reading.rb +150 -0
  180. data/test/objectmanager/test_resource_writing.rb +39 -0
  181. data/test/objectmanager/test_talia_syntax.rb +68 -0
  182. data/test/queryengine/my_external_resource.rb +24 -0
  183. data/test/queryengine/test_external_resource_class.rb +49 -0
  184. data/test/queryengine/test_ntriples_parser.rb +71 -0
  185. data/test/queryengine/test_query.rb +55 -0
  186. data/test/queryengine/test_query2jars2.rb +51 -0
  187. data/test/queryengine/test_query2sparql.rb +76 -0
  188. data/test/queryengine/test_query_engine.rb +52 -0
  189. data/test/test_adapters.rb +58 -0
  190. metadata +266 -0
@@ -0,0 +1,10 @@
1
+ == ActiveRDF YARS adapter
2
+ This is the ActiveRDF adapter to the YARS and Jars2 RDF stores.
3
+ See http://www.activerdf.org/ for more information.
4
+
5
+ == License
6
+ This adapter is distributed under the LGPL license.
7
+
8
+ == Authors
9
+ * Eyal Oren
10
+
@@ -0,0 +1,38 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/clean'
4
+ require 'rake/gempackagetask'
5
+ require 'rake/rdoctask'
6
+ require 'tools/rakehelp'
7
+ require 'fileutils'
8
+ include FileUtils
9
+
10
+ setup_tests
11
+ setup_clean ["pkg", "lib/*.bundle", "*.gem", ".config"]
12
+
13
+ setup_rdoc ['README', 'LICENSE', 'lib/**/*.rb', 'doc/**/*.rdoc']
14
+
15
+ desc "Does a full compile, test run"
16
+ task :default => [:test, :package]
17
+
18
+ version="xx"
19
+ name="activerdf_yars"
20
+
21
+ setup_gem(name, version) do |spec|
22
+ spec.summary = "ActiveRDF adapter to YARS RDF store"
23
+ spec.description = spec.summary
24
+ spec.author="Eyal Oren <eyal.oren@deri.org"
25
+ spec.add_dependency('gem_plugin', '>= 0.2.1')
26
+ spec.add_dependency('activerdf', '>= 0.9.2')
27
+ end
28
+
29
+
30
+ task :install => [:test, :package] do
31
+ sh %{sudo gem install pkg/#{name}-#{version}.gem}
32
+ end
33
+
34
+ task :uninstall => [:clean] do
35
+ sh %{sudo gem uninstall #{name}}
36
+ end
37
+
38
+ task :reinstall => [:uninstall, :install]
@@ -0,0 +1,10 @@
1
+ # add the directory in which this file is located to the ruby loadpath
2
+ file =
3
+ if File.symlink?(__FILE__)
4
+ File.readlink(__FILE__)
5
+ else
6
+ __FILE__
7
+ end
8
+ $: << File.dirname(File.expand_path(file))
9
+
10
+ require 'jars2'
@@ -0,0 +1,119 @@
1
+ # Author:: Eyal Oren
2
+ # Copyright:: (c) 2005-2006
3
+ # License:: LGPL
4
+
5
+ # require 'active_rdf'
6
+ require 'queryengine/query2jars2'
7
+ require 'net/http'
8
+ require 'cgi'
9
+
10
+ # Read-only adapter to jars2
11
+ # (experimental YARS branch for SWSE engine)
12
+ class Jars2Adapter < ActiveRdfAdapter
13
+ ActiveRdfLogger::log_info "Loading Jars2 adapter", self
14
+ ConnectionPool.register_adapter(:jars2, self)
15
+
16
+ # initialises connection to jars2 datastore
17
+ # available parameters are:
18
+ # * :host (default 'm3pe.org')
19
+ # * :port (default 2020)
20
+ def initialize(params = {})
21
+ super()
22
+ @reads = true
23
+ @writes = false
24
+
25
+ @host = params[:host] || 'm3pe.org'
26
+ @port = params[:port] || 2020
27
+ ActiveRdfLogger::log_info(self) { "Initializing new instance with host: #{@host} port: #{@port}" }
28
+ @yars = Net::HTTP.new(@host, @port)
29
+ end
30
+
31
+ def translate query
32
+ Query2Jars2.translate(query)
33
+ end
34
+
35
+ # executes query on jars2 datastore
36
+ def query(query)
37
+ qs = Query2Jars2.translate(query)
38
+ header = { 'Accept' => 'application/rdf+n3' }
39
+
40
+ # querying Jars2, adding 'eyal' parameter to get all variable bindings in
41
+ # the result
42
+ response = @yars.get("/?q=#{CGI.escape(qs)}&eyal", header)
43
+
44
+ ActiveRdfLogger::log_debug(self) { "Jars2Adapter: query executed: #{qs}" }
45
+
46
+ # return empty array if no content
47
+ return [] if response.is_a?(Net::HTTPNoContent)
48
+
49
+ # return false unless HTTP OK returned
50
+ return false unless response.is_a?(Net::HTTPOK)
51
+
52
+ # parse the result
53
+ results = parse_result(response.body, query)
54
+
55
+ # remove duplicates if asked for distinct results
56
+ if query.distinct?
57
+ final_results = results.uniq
58
+ else
59
+ final_results = results
60
+ end
61
+
62
+ ActiveRdfLogger::log_debug_pp "Query returned %s", final_results if ActiveRdfLogger::log_level == Logger::DEBUG
63
+ final_results
64
+ end
65
+
66
+ private
67
+ Resource = /<[^>]*>/
68
+ Literal = /"[^"]*"/
69
+ Node = Regexp.union(Resource,Literal)
70
+
71
+ # parses Jars2 results into array of ActiveRDF objects
72
+ def parse_result(response, query)
73
+ # Jars2 responses contain one result per line
74
+ results = response.split("\n")
75
+
76
+ # the first line of the response contains the variable bindings of the
77
+ # results: we look at that line to figure out which column contains the
78
+ # data we are looking for (which is the variables mentioned in the select
79
+ # clauses of the query
80
+ bindings = results[0].split(' ')
81
+
82
+ # array of found answers, will be filled by iterating over the results and
83
+ # only including the requested (i.e. selected) clauses
84
+ answers = []
85
+
86
+ # we iterate over the real results, and extract the clauses that we're
87
+ # looking for (i.e. the select clauses from the query)
88
+ results[1..-1].each do |result|
89
+
90
+ # scan row for occurence of nodes (either resources or literals)
91
+ row = result.scan(Node)
92
+
93
+ # for each select clause, we find its index, and add the value at that
94
+ # location in the result row to our answer
95
+ row = query.select_clauses.collect do |clause|
96
+ clause_index = bindings.index(clause)
97
+ convert_into_activerdf(row[clause_index], query.resource_class)
98
+ end
99
+ answers << row
100
+ end
101
+
102
+ answers
103
+ end
104
+
105
+ # converts ntriples serialisation of resource or literal into ActiveRDF object.
106
+ #
107
+ # resource_type is the class to be used for "resource" objects.
108
+ def convert_into_activerdf(string, resource_type)
109
+ case string
110
+ when /<(.*)>/
111
+ # <http://foaf/Person> is a resource
112
+ resource_type.new($1)
113
+ when /"(.*)"/
114
+ # "30" is a literal
115
+ # TODO: handle datatypes
116
+ String.new($1)
117
+ end
118
+ end
119
+ end
data/lib/active_rdf.rb ADDED
@@ -0,0 +1,85 @@
1
+
2
+ require 'rubygems'
3
+
4
+ # ActiveRDF loader
5
+
6
+ file = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
7
+ this_dir = File.dirname(File.expand_path(file))
8
+
9
+ $: << this_dir + '/'
10
+ $: << this_dir + '/active_rdf/'
11
+
12
+ require 'active_rdf_helpers'
13
+ require 'active_rdf_log'
14
+
15
+
16
+ # load standard classes that need to be loaded at startup
17
+ require 'objectmanager/resource_like'
18
+ require 'objectmanager/resource'
19
+ require 'objectmanager/bnode'
20
+ require 'objectmanager/literal'
21
+ require 'objectmanager/namespace'
22
+ require 'federation/connection_pool'
23
+ require 'queryengine/query'
24
+ require 'federation/active_rdf_adapter'
25
+
26
+ ActiveRdfLogger::log_info "ActiveRDF loaded, logging level: #{ActiveRdfLogger::logger.level}"
27
+
28
+ def load_adapter s
29
+ begin
30
+ require s
31
+ rescue Exception => e
32
+ ActiveRdfLogger::log_info "Could not load adapter #{s}: #{e}"
33
+ #raise exception if the environment variable is specified
34
+ raise ActiveRdfError, "Could not load adapter #{s}: #{e}" unless ENV['ACTIVE_RDF_ADAPTERS'].nil?
35
+ end
36
+ end
37
+
38
+
39
+ # determine whether activerdf is installed as a gem:
40
+ if Gem::cache.search(/^activerdf$/).empty?
41
+ # we are not running as a gem
42
+ ActiveRdfLogger::log_info 'ActiveRDF is NOT installed as a Gem', self
43
+ if ENV['ACTIVE_RDF_ADAPTERS'].nil?
44
+ if RUBY_PLATFORM =~ /java/
45
+ load_adapter this_dir + '/activerdf/activerdf-jena/lib/activerdf_jena/init'
46
+ load_adapter this_dir + '/activerdf/activerdf-sparql/lib/activerdf_sparql/sparql'
47
+ load_adapter this_dir + '/../activerdf-sesame/lib/activerdf_sesame/sesame'
48
+ else
49
+ load_adapter this_dir + '/../activerdf-rdflite/lib/activerdf_rdflite/rdflite'
50
+ load_adapter this_dir + '/../activerdf-rdflite/lib/activerdf_rdflite/fetching'
51
+ load_adapter this_dir + '/../activerdf-rdflite/lib/activerdf_rdflite/suggesting'
52
+ load_adapter this_dir + '/../activerdf-redland/lib/activerdf_redland/redland'
53
+ load_adapter this_dir + '/../activerdf-sparql/lib/activerdf_sparql/sparql'
54
+ #load_adapter this_dir + '/../activerdf-yars/lib/activerdf_yars/jars2'
55
+ end
56
+ else
57
+ #load specified adapters
58
+ #for example: ENV['ACTIVE_RDF_ADAPTERS'] = "redland,sparql"
59
+ ENV['ACTIVE_RDF_ADAPTERS'].split(",").uniq.each { |adapterItem|
60
+ case adapterItem.strip.downcase
61
+ when "rdflite"
62
+ load_adapter this_dir + '/../activerdf-rdflite/lib/activerdf_rdflite/rdflite'
63
+ load_adapter this_dir + '/../activerdf-rdflite/lib/activerdf_rdflite/fetching'
64
+ load_adapter this_dir + '/../activerdf-rdflite/lib/activerdf_rdflite/suggesting'
65
+ when "redland"
66
+ load_adapter this_dir + '/../activerdf-redland/lib/activerdf_redland/redland'
67
+ when "sparql"
68
+ load_adapter this_dir + '/../activerdf-sparql/lib/activerdf_sparql/sparql'
69
+ when "jars"
70
+ load_adapter this_dir + '/../activerdf-yars/lib/activerdf_yars/jars2'
71
+ when "sesame"
72
+ load_adapter this_dir + '/../activerdf-sesame/lib/activerdf_sesame/sesame'
73
+ else
74
+ ActiveRdfLogger::log_error "Unknown adapter #{name}"
75
+ raise ActiveRdfError, "Unknown adapter #{name}"
76
+ end
77
+ }
78
+ end
79
+ else
80
+ # we are running as a gem
81
+ require 'gem_plugin'
82
+ ActiveRdfLogger::log_info 'ActiveRDF is installed as a Gem'
83
+ GemPlugin::Manager.instance.load "activerdf" => GemPlugin::INCLUDE
84
+ end
85
+
@@ -0,0 +1,49 @@
1
+ require 'active_rdf_helpers'
2
+
3
+
4
+ # Direct access for Redland adapter
5
+ #
6
+ # Syntax
7
+ # "<http://......>" = Resource
8
+ # "abc" = Literal
9
+ # "_:" = Blank Node
10
+ # "_:123" = Blank Node with id
11
+ class DirectAccess
12
+
13
+ # Execute a SPARQL query. The second parameter specify the result format (:json, :xml, :array) (optional)
14
+ #
15
+ # The return default value is an Array.
16
+ # If you specify :xml or :json in result_format, the return value is a String that contain the request format.
17
+ #
18
+ # Example: query("SELECT ?p ?o WHERE {<http://activerdf.org/test/eyal> ?p ?o}", :json)
19
+ def self.sparql_query(query, result_format=:array)
20
+ # verify input
21
+ if query.nil?
22
+ raise ActiveRdfError, "cannot execute empty query"
23
+ end
24
+
25
+ # verify class type
26
+ if query.class != String
27
+ raise ActiveRdfError, "query must be String."
28
+ end
29
+
30
+ # execute query
31
+ FederationManager.query(query, {:result_format => result_format})
32
+ end
33
+
34
+ # Find all triple by subject and predicate
35
+ # The return value is a PropertyList
36
+ def self.find_all_by_subject_and_predicate(s,p)
37
+ # verify input
38
+ if s.nil? || p.nil?
39
+ raise ActiveRdfError, "subject and predicate can't be nil"
40
+ end
41
+
42
+ # execute query
43
+ query_result = self.sparql_query("SELECT ?o WHERE {#{s} #{p} ?o}")
44
+
45
+ # return propertyList
46
+ return PropertyList.new(p, query_result, s)
47
+ end
48
+
49
+ end
@@ -0,0 +1,47 @@
1
+ # require 'active_rdf'
2
+ require 'queryengine/query2sparql'
3
+
4
+ # Generic superclass of all adapters
5
+
6
+ class ActiveRdfAdapter
7
+ # indicate if adapter can read and write
8
+ bool_accessor :reads, :writes, :enabled
9
+
10
+ def initialize
11
+ @enabled = true
12
+ end
13
+
14
+ # Indicate if the adapter supports contexts
15
+ def supports_context?
16
+ self.class.supports_context?
17
+ end
18
+
19
+ # translate a query to its string representation
20
+ def translate(query)
21
+ Query2SPARQL.translate(query)
22
+ end
23
+
24
+ # Clear the adapter. Crude default implementation, which can be overwritten
25
+ # in subclasses. TODO: This queries all adapters, this may lead to problems...
26
+ def clear
27
+ raise(ActiveRdfError, "Can only delete from writing adapters") unless(writes?)
28
+ to_delete = Query.new.select(:s, :p, :o).where(:s, :p, :o).execute
29
+ to_delete.each do |s, p, o|
30
+ delete(s, p, o)
31
+ end
32
+ end
33
+
34
+ # Indicates if this adapter class supports contexts
35
+ def self.supports_context?
36
+ @context_supported = false if(@context_supported == nil)
37
+ @context_supported
38
+ end
39
+
40
+ private
41
+
42
+ # Method to set the "context_supported" flag
43
+ def self.supports_context
44
+ @context_supported = true
45
+ end
46
+
47
+ end
@@ -0,0 +1,156 @@
1
+ # require 'active_rdf'
2
+
3
+ # Maintains pool of adapter instances that are connected to datasources. Returns
4
+ # right adapter for a given datasource, by either reusing an
5
+ # existing adapter-instance or creating new a adapter-instance.
6
+
7
+ class ConnectionPool
8
+ class << self
9
+ attr_accessor :write_adapter
10
+
11
+ # sets automatic flushing of data from adapters to original datasources
12
+ # (e.g. redland on-file database). If disabled, changes to an adapter are
13
+ # not written back into the original source: you need to invoke
14
+ # ConnectionPool.flush manually
15
+ bool_accessor :auto_flush
16
+ end
17
+ # pool of all adapters
18
+ @@adapter_pool = Array.new
19
+
20
+ # pool of connection parameters to all adapter
21
+ @@adapter_parameters = Array.new
22
+
23
+ # currently active write-adapter (we can only write to one at a time)
24
+ self.write_adapter = nil
25
+
26
+ # default setting for auto_flush
27
+ self.auto_flush = true
28
+
29
+ # adapters-classes known to the pool, registered by the adapter-class
30
+ # itself using register_adapter method, used to select new
31
+ # adapter-instance for requested connection type
32
+ @@registered_adapter_types = Hash.new
33
+
34
+ # clears the pool: removes all registered data sources
35
+ def ConnectionPool.clear
36
+ ActiveRdfLogger::log_info "Clear called", self
37
+ @@adapter_pool.clear
38
+ @@adapter_parameters.clear
39
+ self.write_adapter = nil
40
+ end
41
+
42
+ def ConnectionPool.adapters
43
+ @@adapter_pool.dup
44
+ end
45
+
46
+ # flushes all openstanding changes into the original datasource.
47
+ def ConnectionPool.flush
48
+ write_adapter.flush
49
+ end
50
+
51
+ def ConnectionPool.adapter_types
52
+ @@registered_adapter_types.keys
53
+ end
54
+
55
+ # returns the set of currently registered read-access datasources
56
+ def ConnectionPool.read_adapters
57
+ @@adapter_pool.select {|adapter| adapter.reads? && adapter.enabled?}
58
+ end
59
+
60
+ def ConnectionPool.write_adapters
61
+ @@adapter_pool.select {|adapter| adapter.writes? && adapter.enabled?}
62
+ end
63
+
64
+ # returns adapter-instance for given parameters (either existing or new)
65
+ def ConnectionPool.add_data_source(connection_params)
66
+ ActiveRdfLogger::log_info(self) { "add_data_source with params: #{connection_params.inspect}" }
67
+
68
+ # either get the adapter-instance from the pool
69
+ # or create new one (and add it to the pool)
70
+ index = @@adapter_parameters.index(connection_params)
71
+ if index.nil?
72
+ # adapter not in the pool yet: create it,
73
+ # register its connection parameters in parameters-array
74
+ # and add it to the pool (at same index-position as parameters)
75
+ ActiveRdfLogger::log_debug(self) { "Create a new adapter for parameters #{connection_params.inspect}" }
76
+ adapter = create_adapter(connection_params)
77
+ @@adapter_parameters << connection_params
78
+ @@adapter_pool << adapter
79
+ else
80
+ # if adapter parametrs registered already,
81
+ # then adapter must be in the pool, at the same index-position as its parameters
82
+ ActiveRdfLogger::log_debug("Reusing existing adapter")
83
+ adapter = @@adapter_pool[index]
84
+ end
85
+
86
+ # sets the adapter as current write-source if it can write
87
+ self.write_adapter = adapter if adapter.writes?
88
+
89
+ return adapter
90
+ end
91
+
92
+ # remove one adapter from activerdf
93
+ def ConnectionPool.remove_data_source(adapter)
94
+ ActiveRdfLogger.log_info(self) { "ConnectionPool: remove_data_source with params: #{adapter.to_s}" }
95
+
96
+ index = @@adapter_pool.index(adapter)
97
+
98
+ # remove_data_source mit be called repeatedly, e.g because the adapter object is stale
99
+ unless index.nil?
100
+ @@adapter_parameters.delete_at(index)
101
+ @@adapter_pool.delete_at(index)
102
+ if self.write_adapters.empty?
103
+ self.write_adapter = nil
104
+ else
105
+ self.write_adapter = self.write_adapters.first
106
+ end
107
+ end
108
+
109
+ end
110
+
111
+ # sets adapter-instance for connection parameters (if you want to re-enable an existing adapter)
112
+ def ConnectionPool.set_data_source(adapter, connection_params = {})
113
+ index = @@adapter_parameters.index(connection_params)
114
+ if index.nil?
115
+ @@adapter_parameters << connection_params
116
+ @@adapter_pool << adapter
117
+ else
118
+ @@adapter_pool[index] = adapter
119
+ end
120
+ self.write_adapter = adapter if adapter.writes?
121
+ adapter
122
+ end
123
+
124
+ # aliasing add_data_source as add
125
+ # (code bit more complicad since they are class methods)
126
+ class << self
127
+ alias add add_data_source
128
+ end
129
+
130
+ # adapter-types can register themselves with connection pool by
131
+ # indicating which adapter-type they are
132
+ def ConnectionPool.register_adapter(type, klass)
133
+ ActiveRdfLogger::log_info(self) { "Registering adapter of type #{type} for class #{klass}" }
134
+ @@registered_adapter_types[type] = klass
135
+ end
136
+
137
+ # unregister adapter-type
138
+ def ConnectionPool.unregister_adapter(type)
139
+ ActiveRdfLogger::log_info(self) { "ConnectionPool: deregistering adapter of type #{type}" }
140
+ @@registered_adapter_types.delete type
141
+ end
142
+
143
+ # create new adapter from connection parameters
144
+ def ConnectionPool.create_adapter connection_params
145
+ # lookup registered adapter klass
146
+ klass = @@registered_adapter_types[connection_params[:type].to_sym]
147
+
148
+ # raise error if adapter type unknown
149
+ raise(ActiveRdfError, "unknown adapter type #{connection_params[:type]}") if klass.nil?
150
+
151
+ # create new adapter-instance
152
+ klass.send(:new, connection_params)
153
+ end
154
+
155
+ private_class_method :create_adapter
156
+ end