activerubic 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +41 -0
- data/Manifest.txt +7 -0
- data/README.txt +56 -0
- data/Rakefile +35 -0
- data/bin/active_rubic +0 -0
- data/lib/active_rubic.rb +365 -0
- data/test/test_active_rubic.rb +305 -0
- metadata +63 -0
data/History.txt
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
== 0.8.0 / 2007-12-31
|
2
|
+
|
3
|
+
* This release supports Jena ja Lucene and operates with Rubinstein-0.88. Joseki support has been working reliably, but due to poor performance the model is left unmaintained.
|
4
|
+
|
5
|
+
* Only Ruby-1.8.6 and Rails-1.2.6 have been tested.
|
6
|
+
* See Rubinstein README for notes on JRuby versions.
|
7
|
+
|
8
|
+
== Earlier history:
|
9
|
+
0.78 changed library loading paths, rake is successful
|
10
|
+
0.77 raise errors when connection is not established
|
11
|
+
0.76 removed methods that contained schema data from objectmanager
|
12
|
+
0.75 compatibility with ActiveRDF-1.6.8; including the Namespace patch
|
13
|
+
0.74 cleanup and bug fixes
|
14
|
+
0.73 switch to RDFS::Resource model from sandbox wrapper RdfAbout
|
15
|
+
0.72 cleanup and bug fixes
|
16
|
+
0.71 including enhanced ActiveRubic children models.
|
17
|
+
0.70 major changes; introduction of method_missing, which deprecates
|
18
|
+
around 50% of the existing code while making it more efficient.
|
19
|
+
the code is now cleaner and easier to understand.
|
20
|
+
introduction of ActiveRubinstein::JenaQuery, ::JosekiQuery and
|
21
|
+
::LuceneSearcher with ActiveRubic::Cacher
|
22
|
+
0.60 getNearbyTargets to Lucene methods
|
23
|
+
0.59 getInverse method for properties
|
24
|
+
0.58 start ActiveRubinstein only in client mode
|
25
|
+
0.57 include MysqlCache + some bug fixes
|
26
|
+
0.56 model cleanup
|
27
|
+
0.55 fixed a major bug in Rubic; returned a Hash with an empty resultset.
|
28
|
+
the return value should be an empty Array in this case.
|
29
|
+
0.54 dropped the connection dependency if it is not within RUBIC_DATASTORES
|
30
|
+
0.53 markers from Jena honor the :limit parameter, but Jena cannot handle
|
31
|
+
limit in SPARQL. is this a bug in Jena or EVO from our side?
|
32
|
+
0.52 languages are read correctly from Jena
|
33
|
+
0.51 more coherent structure, rubic-debug is working. logging is improved.
|
34
|
+
0.50 much tweaking to get Jena working properly :)
|
35
|
+
0.43 basic jena-joseki connectivity in Rails
|
36
|
+
0.42 initial work to integrate into Rails. not working yet.
|
37
|
+
0.41 reading selectively from jena, joseki and mysql.
|
38
|
+
0.40 Molding app/models/rubic.rb into ActiveRubic and ActiveRubinstein
|
39
|
+
0.30 Relatively stable version -- sparql and graph handling, no proper logging
|
40
|
+
0.20 Rubic model
|
41
|
+
0.10 ActiveRubinstein model
|
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
ActiveRubic
|
2
|
+
by Mikael Lammentausta
|
3
|
+
activerubic.rubyforge.org
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
ActiveRubic is a Ruby module, written for the Rails web platform. The motivation in making this module was to replace ActiveRecord as the primary data source to be operated with the MVC model.
|
7
|
+
|
8
|
+
With this module it is possible to use semantic data stores instead of relational database on web sites. The module supports plug-in submodules for additional data stores.
|
9
|
+
|
10
|
+
All of them are used via the ActiveRubinstein submodule. Stub for MySQL run-time cache has been made but not yet written. The benefit would be to speed up performance.
|
11
|
+
|
12
|
+
ActiveRubinstein requires the Rubinstein backend server. The server IP address and the TCP port are configurable from Rails' configuration files.
|
13
|
+
|
14
|
+
ActiveRubic has been factored to use submodules. ActiveRubinstein is a module similar to ActiveRecord, which connects to the Rubinstein DRb server to run SPARQL queries from Jena. MySQL-cacher would use the ActiveRecord ORM.
|
15
|
+
|
16
|
+
== FEATURES/PROBLEMS:
|
17
|
+
Currently supported backends are:
|
18
|
+
|
19
|
+
* Jena
|
20
|
+
* Lucene
|
21
|
+
* Joseki
|
22
|
+
|
23
|
+
== SYNOPSIS:
|
24
|
+
See the actual documentation.
|
25
|
+
|
26
|
+
== REQUIREMENTS:
|
27
|
+
* ActiveRDF-1.6.8
|
28
|
+
* Rubinstein-0.88
|
29
|
+
|
30
|
+
* FIX update
|
31
|
+
|
32
|
+
== INSTALL:
|
33
|
+
|
34
|
+
* FIX (sudo gem install, anything else)
|
35
|
+
|
36
|
+
== LICENSE:
|
37
|
+
|
38
|
+
Copyright (c) 2007 Savonia University of Applied Sciences
|
39
|
+
|
40
|
+
a copy of this software and associated documentation files (the
|
41
|
+
'Software'), to deal in the Software without restriction, including
|
42
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
43
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
44
|
+
permit persons to whom the Software is furnished to do so, subject to
|
45
|
+
the following conditions:
|
46
|
+
|
47
|
+
The above copyright notice and this permission notice shall be
|
48
|
+
included in all copies or substantial portions of the Software.
|
49
|
+
|
50
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
51
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
52
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
53
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
54
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
55
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
56
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/active_rubic.rb'
|
6
|
+
|
7
|
+
Hoe.new('ActiveRubic', ActiveRubic::VERSION) do |p|
|
8
|
+
p.rubyforge_name = 'activerubic'
|
9
|
+
# p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
10
|
+
# p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
11
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
12
|
+
|
13
|
+
p.name = "activerubic"
|
14
|
+
p.version = "0.8.0"
|
15
|
+
p.author = "Mikael Lammentausta"
|
16
|
+
p.email = "mikael.lammentausta( at )gmail.com"
|
17
|
+
#p.homepage = "http://openlab.savonia-amk.fi/wiki/index.php/ActiveRubic"
|
18
|
+
#p.rubyforge_project = "activerubic"
|
19
|
+
#p.platform = Gem::Platform::RUBY
|
20
|
+
p.summary = "ActiveRubic is a C/JRuby connector to semantic data stores, such as Jena and Joseki, using ActiveRDF."
|
21
|
+
#p.add_dependency("activerdf", ">= 1.6.8")
|
22
|
+
|
23
|
+
#p.files = FileList["lib/**/*"].to_a
|
24
|
+
#p.require_path = "lib"
|
25
|
+
#p.autorequire = "name"
|
26
|
+
p.test_files = FileList["{test}/**/*test.rb"].to_a
|
27
|
+
|
28
|
+
#p.has_rdoc = true
|
29
|
+
#p.extra_rdoc_files = ["README.txt"]
|
30
|
+
p.remote_rdoc_dir = '' # Release to root
|
31
|
+
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
# vim: syntax=Ruby
|
data/bin/active_rubic
ADDED
File without changes
|
data/lib/active_rubic.rb
ADDED
@@ -0,0 +1,365 @@
|
|
1
|
+
#############################################################################
|
2
|
+
# ActiveRubic emulates ActiveRecord and provides connections to several data stores with the objective to abstract the semantic data from various engines.
|
3
|
+
#
|
4
|
+
# The engines are also attempted to be drop-in replaceable by offering an abstraction method find(). see ActiveRubic::Base for the API reference.
|
5
|
+
# - some of it is still undocumented!!
|
6
|
+
|
7
|
+
|
8
|
+
# The supported backends currently include:
|
9
|
+
#
|
10
|
+
# - ActiveRecord
|
11
|
+
# - ActiveRubinstein
|
12
|
+
#
|
13
|
+
# This module abstracts the query methods (SPARQL, graph handling, SQL, Lucene index)
|
14
|
+
# to parameters so that different storages can be "hot-replaced" without the need to make changes to the request.
|
15
|
+
#
|
16
|
+
# ActiveRubinstein::Base is the API which translates queries to the servers
|
17
|
+
# which are supported by the Rubinstein backend, which replies to queries
|
18
|
+
# over the DRb bridge. This also makes possible to use Java-based repositories
|
19
|
+
# with JRuby without running the whole Rails stack on JRuby.
|
20
|
+
#
|
21
|
+
# http://openlab.savonia-amk.fi/wiki/images/1/12/Rubics_cube.png
|
22
|
+
#
|
23
|
+
# Authors:: Mikael Lammentausta, Lauri Miettinen
|
24
|
+
# Copyright:: Copyright (c) 2007 Savonia University of Applied Sciences
|
25
|
+
# License:: MIT
|
26
|
+
#
|
27
|
+
# = Examples
|
28
|
+
# In this example we'll inspect the instance of the Museum of natural history of Kuopio, Finland. Launch up the Rails console:
|
29
|
+
#
|
30
|
+
# $ ./script/console
|
31
|
+
# Loading development environment.
|
32
|
+
# RUBIC log/irb: * Initializing ActiveRubic, version 0.76
|
33
|
+
# RUBIC log/irb: => loading ActiveRubinstein
|
34
|
+
# RUBIC log/irb: => loading ActiveRubic
|
35
|
+
# RUBIC log/irb: * Rails environment already initialized
|
36
|
+
# DEBUG log/irb: => including ActiveRubinstein to ActiveRubic::Base
|
37
|
+
# RUBIC log/irb: * loading ActiveRDF extensions
|
38
|
+
# DEEP log/irb: Formulating new RDFS::Resource http://www.w3.org/2000/01/rdf-schema#Resource from String
|
39
|
+
# DEEP log/irb: Formulating new RDFS::Resource http://openlab/media#image from String
|
40
|
+
# DEEP log/irb: Formulating new RDFS::Resource http://www.w3.org/2002/07/owl#Class from String
|
41
|
+
# DEEP log/irb: Formulating new RDFS::Resource http://www.w3.org/2002/07/owl#Thing from String
|
42
|
+
# DEEP log/irb: Formulating new RDFS::Resource http://www.w3.org/2002/07/owl#ObjectProperty from String
|
43
|
+
# RUBINSTEIN log/irb: * initializing JenaEndpoint: druby://192.168.0.11:2002
|
44
|
+
# DEBUG log/irb: #<DRb::DRbObject:0xb6e0ed0c @ref=nil, @uri="druby://192.168.0.11:2002">
|
45
|
+
# DEBUG log/irb: => reply from server: Greetings -- this is jRubinstein#JenaLuc/Picard 0.84 on 192.168.0.11:2002, PID 20471808
|
46
|
+
# RUBINSTEIN log/irb: => added #<ActiveRubinstein::JenaEndpoint:0xb6e0edfc @uri="druby://192.168.0.11:2002"> to pool
|
47
|
+
# INFO log/irb: @@jena = #<ActiveRubinstein::JenaEndpoint:0xb6e0edfc @uri="druby://192.168.0.11:2002">
|
48
|
+
# INFO log/irb: @@lucene = #<ActiveRubinstein::JenaEndpoint:0xb6e0edfc @uri="druby://192.168.0.11:2002">
|
49
|
+
#
|
50
|
+
# If everything is fine, fire up a simple query for label:
|
51
|
+
#
|
52
|
+
# resource = KUOPIO::kuopion_museo
|
53
|
+
# => #<RDFS::Resource:0xb6ef1fa8 @uri="http://openlab/kuopio#kuopion_museo">
|
54
|
+
#
|
55
|
+
# resource.label
|
56
|
+
# => ["Kuopion museo"]
|
57
|
+
#
|
58
|
+
# How does this data get from Jena to Rails' console? Let's inspect the entire data passage.
|
59
|
+
#
|
60
|
+
# First of all, the label method looks like this:
|
61
|
+
#
|
62
|
+
# class class RDFS::Resource
|
63
|
+
# def label
|
64
|
+
# if @label.nil?
|
65
|
+
# @label = my( RDFS::label )
|
66
|
+
# end
|
67
|
+
# return @label
|
68
|
+
# end
|
69
|
+
# end
|
70
|
+
#
|
71
|
+
# It calls the private 'my' method within the model:
|
72
|
+
#
|
73
|
+
# private
|
74
|
+
# ### helper
|
75
|
+
# def my( predicate )
|
76
|
+
# if predicate.is_a? String then
|
77
|
+
# predicate = RDFS::Resource.new( predicate )
|
78
|
+
# end
|
79
|
+
# begin
|
80
|
+
# @@log.debug " => find #{self.uri} #{predicate} ?"
|
81
|
+
# ActiveRubic::Base.find( predicate, :subject => self.uri,
|
82
|
+
# :from => RUBIC_DATASTORES,
|
83
|
+
# :lang => @language
|
84
|
+
# ) || Array.new
|
85
|
+
#
|
86
|
+
# rescue
|
87
|
+
# @@log.error $!
|
88
|
+
# return Array.new
|
89
|
+
# end
|
90
|
+
# end
|
91
|
+
#
|
92
|
+
# Which calls the ActiveRubic::Base find() method with the subject, required predicate, and options for used data stores as well as the desired language. The find() method and the following data flow, many lines are removed to simplify the logic behind the module:
|
93
|
+
#
|
94
|
+
# module ActiveRubic #:nodoc:
|
95
|
+
# class Base
|
96
|
+
# class << self # Class methods
|
97
|
+
# def find(*args)
|
98
|
+
# # options:
|
99
|
+
# # :data_stores = Array
|
100
|
+
# # :suffice_to = Array of data_stores that are trusted to return sufficient results. By default all data stores are untrusted to be complete, and the results of each are combined. The results of servers given in the array
|
101
|
+
# # :combine = Array of data stores that are queried and the results combined. If the trusted server returns results, trust that the contents is sufficient.
|
102
|
+
# options = extract_options_from_args!(args)
|
103
|
+
#
|
104
|
+
# serial_query_handler( args.first, options )
|
105
|
+
# end
|
106
|
+
#
|
107
|
+
# private
|
108
|
+
# # runs a query on data stores sequentially
|
109
|
+
# def serial_query_handler(query, options)
|
110
|
+
# begin
|
111
|
+
# data_stores.each do |storage|
|
112
|
+
# my_results = run_query( storage, query, options )
|
113
|
+
# end
|
114
|
+
# end
|
115
|
+
# # merge and return results
|
116
|
+
# end
|
117
|
+
#
|
118
|
+
# # constructs the actual queries and receives the result
|
119
|
+
# def run_query( storage, query, options )
|
120
|
+
# case storage
|
121
|
+
# when :jena
|
122
|
+
# ActiveRubinstein::JenaQuery.execute( query, options )
|
123
|
+
# end
|
124
|
+
# end
|
125
|
+
# end
|
126
|
+
# end
|
127
|
+
# end
|
128
|
+
# end
|
129
|
+
#
|
130
|
+
# The ActiveRubinstein::JenaQuery class, and ActiveRubic in general, accepts three types of 'query' objects:
|
131
|
+
# - Symbol for actions, eg. :parents, :children, :nearby, :properties etc.
|
132
|
+
# - RDFS::Resource (predicate) with the option :subject => uri, to fetch the object, as in the RDFS::label example
|
133
|
+
# - Query, an ActiveRDF object, as a block without the .execute call
|
134
|
+
#
|
135
|
+
# Let's examine the JenaQuery class:
|
136
|
+
#
|
137
|
+
# module ActiveRubinstein #:nodoc:
|
138
|
+
# class JenaQuery < ActiveRubinstein::Base
|
139
|
+
# class << self
|
140
|
+
#
|
141
|
+
# public
|
142
|
+
#
|
143
|
+
# def execute( query, options )
|
144
|
+
# if query.is_a? Symbol or query.is_a? RDFS::Resource
|
145
|
+
# case query
|
146
|
+
# # ... process some symbols
|
147
|
+
# else # construct common SPARQL
|
148
|
+
# sparql = ActiveRubinstein::Base.construct_sparql( query, options )
|
149
|
+
# self.query( sparql, options ) if sparql
|
150
|
+
# end
|
151
|
+
# end
|
152
|
+
# end
|
153
|
+
#
|
154
|
+
# private
|
155
|
+
#
|
156
|
+
# # pretty much the most important method of all :)
|
157
|
+
# # this method sends the request to Rubinstein's DRb server.
|
158
|
+
# def method_missing(method, *args, &block)
|
159
|
+
# @@log.rubinstein "sending the request to DRb server, method #{method}"
|
160
|
+
# @@jena.send( method, *args, &block )
|
161
|
+
# end
|
162
|
+
# end
|
163
|
+
# end
|
164
|
+
# end
|
165
|
+
#
|
166
|
+
# @@jena variable is instantiated in ActiveRubinstein::Base:
|
167
|
+
#
|
168
|
+
# module ActiveRubinstein #:nodoc:
|
169
|
+
# class Base
|
170
|
+
# def shuffle # Initialization of servers
|
171
|
+
#
|
172
|
+
# $serverPool = {} unless defined? $serverPool
|
173
|
+
#
|
174
|
+
# RUBIC_DATASTORES.each do |adapter|
|
175
|
+
# case adapter
|
176
|
+
# when :jena
|
177
|
+
# server = JenaEndpoint.new
|
178
|
+
# if server.ping
|
179
|
+
# $serverPool.update :jena => [ server ]
|
180
|
+
# @@log.rubinstein " => added #{server.inspect} to pool"
|
181
|
+
# end
|
182
|
+
# end
|
183
|
+
# end
|
184
|
+
# end
|
185
|
+
# end
|
186
|
+
#
|
187
|
+
# # create the server pool, start the DRb service, and
|
188
|
+
# # init the required submodules, so that the correct service is
|
189
|
+
# # accessible as a class variable
|
190
|
+
# def initialize
|
191
|
+
# self.shuffle unless defined? $serverPool
|
192
|
+
# DRb.start_service
|
193
|
+
#
|
194
|
+
# RUBIC_DATASTORES.each do |adapter|
|
195
|
+
# case adapter
|
196
|
+
# ##############################
|
197
|
+
# when :jena
|
198
|
+
# # instantiate the server for the JenaQuery class
|
199
|
+
# ActiveRubinstein::JenaQuery.new
|
200
|
+
# end
|
201
|
+
# end
|
202
|
+
# end
|
203
|
+
# end
|
204
|
+
# end
|
205
|
+
# end
|
206
|
+
#
|
207
|
+
# module ActiveRubinstein #:nodoc:
|
208
|
+
# class JenaQuery < ActiveRubinstein::Base
|
209
|
+
# def initialize
|
210
|
+
# server = $serverPool[ :jena ].first
|
211
|
+
# unless server.ping
|
212
|
+
# @@log.error $!.message
|
213
|
+
# else
|
214
|
+
# @@jena = server
|
215
|
+
# @@log.info "@@jena = #{server.inspect}"
|
216
|
+
# end
|
217
|
+
# end
|
218
|
+
# end
|
219
|
+
# end
|
220
|
+
#
|
221
|
+
# Finally, here is the log of the query:
|
222
|
+
#
|
223
|
+
# DEEP log/irb: Formulating new RDFS::Resource http://www.w3.org/2000/01/rdf-schema#label from String
|
224
|
+
# DEBUG log/irb: => find http://openlab/kuopio#kuopion_museo <http://www.w3.org/2000/01/rdf-schema#label> ?
|
225
|
+
# RUBIC log/irb: * Find: <http://www.w3.org/2000/01/rdf-schema#label>, fromjenalucenesubject<http://openlab/kuopio#kuopion_museo>lang
|
226
|
+
# DEEP log/irb: => Querying data stores: jena, lucene
|
227
|
+
# DEEP log/irb: - Will suffice to data from lucene
|
228
|
+
# RUBIC log/irb: => query: <http://www.w3.org/2000/01/rdf-schema#label> (RDFS::Resource)
|
229
|
+
# RUBINSTEIN log/irb: Constructing SPARQL, options: data_storesjenalucenefromjenalucenesubject<http://openlab/kuopio#kuopion_museo>lang
|
230
|
+
# DEBUG log/irb: => constructing Query to find <http://www.w3.org/2000/01/rdf-schema#label>
|
231
|
+
# DEEP log/irb: Constructing SPARQL <http://openlab/kuopio#kuopion_museo> <http://www.w3.org/2000/01/rdf-schema#label> ?
|
232
|
+
# RUBINSTEIN log/irb: sending the request to DRb server, method query
|
233
|
+
# RUBIC log/irb: => Got 1 results from jena in 0.00976 sec
|
234
|
+
# RUBIC log/irb: => query: <http://www.w3.org/2000/01/rdf-schema#label> (RDFS::Resource)
|
235
|
+
# RUBIC log/irb: => No results from lucene in 0.00015 sec
|
236
|
+
# DEEP log/irb: => 1 altogether
|
237
|
+
# RUBIC log/irb: => TOTAL: 1 unique results
|
238
|
+
# DEEP log/irb: => Returning all 1, no limit
|
239
|
+
# => ["Kuopion museo"]
|
240
|
+
#
|
241
|
+
############################################################################
|
242
|
+
|
243
|
+
RUBIC_VERSION = '0.8.0'
|
244
|
+
|
245
|
+
module ActiveRubic
|
246
|
+
VERSION = RUBIC_VERSION
|
247
|
+
class ActiveRubicError < StandardError #:nodoc:
|
248
|
+
end
|
249
|
+
class AdapterNotSpecifiedError < ActiveRubicError # :nodoc:
|
250
|
+
end
|
251
|
+
class AdapterNotFoundError < ActiveRubicError # :nodoc:
|
252
|
+
end
|
253
|
+
class ConnectionNotEstablishedError < ActiveRubicError #:nodoc:
|
254
|
+
end
|
255
|
+
class ConnectionFailedError < ActiveRubicError #:nodoc:
|
256
|
+
end
|
257
|
+
class RubicNotFoundError < ActiveRubicError #:nodoc:
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
|
262
|
+
### the data sources that will be queried
|
263
|
+
RUBIC_DATASTORES = [ :jena, :joseki, :mysql, :lucene, :geolucene ] unless defined? RUBIC_DATASTORES
|
264
|
+
|
265
|
+
# unused
|
266
|
+
RUBIC_CONNECTION_ADAPTERS = [ :rubinstein ] unless defined?(RUBIC_CONNECTION_ADAPTERS)
|
267
|
+
|
268
|
+
### set environment
|
269
|
+
if defined? RAILS_ROOT
|
270
|
+
RUBINSTEIN_HOME = RAILS_ROOT + '/lib/rubinstein' unless defined? RUBINSTEIN_HOME
|
271
|
+
RUBIC_HOME = RAILS_ROOT + '/lib/active_rubic/lib/' unless defined? RUBIC_HOME
|
272
|
+
else
|
273
|
+
unless defined? RUBINSTEIN_HOME
|
274
|
+
if ENV['RUBINSTEIN_HOME'] then
|
275
|
+
RUBINSTEIN_HOME = ENV['RUBINSTEIN_HOME']
|
276
|
+
else
|
277
|
+
# using File.dirname causes /usr/bin/rake to break the system.
|
278
|
+
RUBINSTEIN_HOME = File.dirname($0)
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
unless defined? RUBIC_HOME
|
283
|
+
if ENV['RUBIC_HOME'] then
|
284
|
+
RUBIC_HOME = ENV['RUBIC_HOME']
|
285
|
+
else
|
286
|
+
RUBIC_HOME = RUBINSTEIN_HOME + '/lib/active_rubic/'
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
### load logger + Rubinstein libraries
|
292
|
+
unless (( defined? @@log ) || ( defined? logger ))
|
293
|
+
require RUBINSTEIN_HOME + '/lib/logger'
|
294
|
+
load_logger
|
295
|
+
end
|
296
|
+
|
297
|
+
require 'rubygems'
|
298
|
+
|
299
|
+
### load the DRb server functions
|
300
|
+
require 'drb/drb'
|
301
|
+
# require 'thread'
|
302
|
+
# require 'gen'
|
303
|
+
|
304
|
+
require 'active_rdf'
|
305
|
+
# load the namespace patch to ActiveRDF
|
306
|
+
require RUBIC_HOME + '/lib/objectmanager/namespace'
|
307
|
+
|
308
|
+
# Namespace configuration
|
309
|
+
require RUBINSTEIN_HOME + '/config/namespaces'
|
310
|
+
|
311
|
+
### load helper methods
|
312
|
+
require RUBINSTEIN_HOME + '/lib/helpers'
|
313
|
+
|
314
|
+
### start ActiveRubic
|
315
|
+
begin
|
316
|
+
|
317
|
+
@@log.rubic " * Initializing ActiveRubic, version #{RUBIC_VERSION}"
|
318
|
+
@@in_daemon_mode = false unless defined? @@in_daemon_mode
|
319
|
+
|
320
|
+
RUBIC_CONNECTION_ADAPTERS.each do |adapter|
|
321
|
+
case adapter
|
322
|
+
when :rubinstein
|
323
|
+
## ActiveRubinstein client talks with the Jena/Lucene/Joseki DRb server
|
324
|
+
|
325
|
+
### load the base
|
326
|
+
@@log.rubic " => loading ActiveRubinstein"
|
327
|
+
require RUBIC_HOME + '/lib/active_rubinstein/base'
|
328
|
+
|
329
|
+
@@log.rubic " => loading ActiveRubic"
|
330
|
+
require RUBIC_HOME + '/lib/active_rubic/base'
|
331
|
+
|
332
|
+
@@log.debug " => including ActiveRubinstein to ActiveRubic::Base"
|
333
|
+
ActiveRubic::Base.class_eval do
|
334
|
+
include ActiveRubinstein
|
335
|
+
end
|
336
|
+
# ActiveRubic::Base.class_eval do
|
337
|
+
# include MysqlCache
|
338
|
+
# end
|
339
|
+
|
340
|
+
### load models
|
341
|
+
@@log.rubic " * loading ActiveRDF extensions"
|
342
|
+
require RUBIC_HOME + '/lib/objectmanager/rdfs/resource'
|
343
|
+
require RUBIC_HOME + '/lib/objectmanager/rdfs/image' # should be in the schema
|
344
|
+
require RUBIC_HOME + '/lib/objectmanager/owl/class'
|
345
|
+
require RUBIC_HOME + '/lib/objectmanager/owl/thing'
|
346
|
+
require RUBIC_HOME + '/lib/objectmanager/owl/object_property'
|
347
|
+
|
348
|
+
### load the backend libraries only when required
|
349
|
+
unless @@in_daemon_mode then
|
350
|
+
begin
|
351
|
+
# initialize the server pool
|
352
|
+
ActiveRubinstein::Base.new()
|
353
|
+
rescue
|
354
|
+
raise ActiveRubic::ConnectionFailedError, $!
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
rescue
|
362
|
+
# raise ActiveRubic::ActiveRubicError, $!
|
363
|
+
end
|
364
|
+
|
365
|
+
# EOF
|
@@ -0,0 +1,305 @@
|
|
1
|
+
# Author:: Mikael Lammentausta
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'active_rdf'
|
5
|
+
|
6
|
+
RUBINSTEIN_HOME = "/home/mikael/sematorio/trunk/Seamfora/Rubinstein"
|
7
|
+
RUBIC_HOME = "#{File.dirname(__FILE__)}/../lib/"
|
8
|
+
LOGDIR = "#{File.dirname(__FILE__)}/log/"
|
9
|
+
|
10
|
+
JDRB_SERVER = '192.168.0.11'
|
11
|
+
JDRB_PORT = '2002'
|
12
|
+
|
13
|
+
GEOLUCENE_SERVER = '192.168.0.11'
|
14
|
+
GEOLUCENE_PORT = '2003'
|
15
|
+
|
16
|
+
RUBIC_DATASTORES = :jena
|
17
|
+
|
18
|
+
require RUBINSTEIN_HOME + '/config/namespaces'
|
19
|
+
require RUBIC_HOME + 'active_rubic'
|
20
|
+
|
21
|
+
@@log.level = INFO
|
22
|
+
|
23
|
+
|
24
|
+
# require "/common"
|
25
|
+
# require 'federation/federation_manager'
|
26
|
+
# require 'queryengine/query'
|
27
|
+
# require "#{File.dirname(__FILE__)}/common"
|
28
|
+
|
29
|
+
class TestConnection < Test::Unit::TestCase
|
30
|
+
def test_jena
|
31
|
+
greeting = ActiveRubinstein::JenaQuery.hello
|
32
|
+
assert greeting.is_a?( String )
|
33
|
+
end
|
34
|
+
def test_truth
|
35
|
+
assert true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class TestModels < Test::Unit::TestCase
|
40
|
+
@@resources = [
|
41
|
+
KUOPIO::kuopion_museo,
|
42
|
+
TOIMIJAT::snellman_j_v
|
43
|
+
]
|
44
|
+
@@classes = [
|
45
|
+
OWL::Class.new( KUOPIO::museot ),
|
46
|
+
# OWL::Class.new( KUOPIO::rakennukset ),
|
47
|
+
OWL::Class.new( KUOPIO::rautatieasemat ),
|
48
|
+
OWL::Class.new( KUOPIO::kulkuvaylat ),
|
49
|
+
OWL::Class.new( KUOPIO::leikkipaikat )
|
50
|
+
]
|
51
|
+
|
52
|
+
# def test_uri
|
53
|
+
# ( @@resources + @@classes ).each do |resource|
|
54
|
+
# assert !resource.uri.nil?
|
55
|
+
# assert resource.uri.is_a?( String )
|
56
|
+
# end
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
# def test_label
|
60
|
+
# ( @@resources + @@classes ).flatten.each do |resource|
|
61
|
+
# assert resource.label.is_a?( Array )
|
62
|
+
# assert resource.labelize.is_a?( String )
|
63
|
+
# end
|
64
|
+
# end
|
65
|
+
#
|
66
|
+
# def test_types
|
67
|
+
# @@resources.each do |resource|
|
68
|
+
# assert !resource.is_class?
|
69
|
+
# assert !resource.is_property?
|
70
|
+
# types = resource.types
|
71
|
+
# assert types.is_a?( Array )
|
72
|
+
# types.each do |type|
|
73
|
+
# assert type.is_a?( RDFS::Resource )
|
74
|
+
# end
|
75
|
+
# end
|
76
|
+
# @@classes.each do |resource|
|
77
|
+
# assert resource.is_class?
|
78
|
+
# assert !resource.is_property?
|
79
|
+
# end
|
80
|
+
# end
|
81
|
+
#
|
82
|
+
# def test_properties
|
83
|
+
# ( @@resources + @@classes ).each do |resource|
|
84
|
+
# properties = resource.properties
|
85
|
+
# assert properties.is_a?( Array )
|
86
|
+
#
|
87
|
+
# # test a specific instance
|
88
|
+
# properties << KUOPIO::kuopion_museo.properties
|
89
|
+
# properties.flatten!
|
90
|
+
# assert !properties.empty?
|
91
|
+
#
|
92
|
+
# properties.each do |property|
|
93
|
+
# assert !property.uri.nil?
|
94
|
+
# assert property.is_a?( OWL::ObjectProperty )
|
95
|
+
#
|
96
|
+
# # test inverse
|
97
|
+
# inverse = property.inverse
|
98
|
+
# assert property.inverse.is_a?( OWL::ObjectProperty )
|
99
|
+
#
|
100
|
+
# # assert that the inverse of the inverse is the same
|
101
|
+
# # as the original property
|
102
|
+
# assert property.inverse.inverse.uri == property.uri
|
103
|
+
# end
|
104
|
+
# end
|
105
|
+
# end
|
106
|
+
#
|
107
|
+
# def test_property_domain_and_range
|
108
|
+
# # test cases:
|
109
|
+
# # TOIMIJAT::stromberg_johan KUOPIO::isDesignerOf KUOPIO::kuopion_museo
|
110
|
+
#
|
111
|
+
# test_designer = TOIMIJAT::stromberg_johan
|
112
|
+
# test_property = OWL::ObjectProperty.new( KUOPIO::isDesignerOf )
|
113
|
+
# assert test_property.is_a?( OWL::ObjectProperty )
|
114
|
+
# assert test_property.is_property?
|
115
|
+
# designers = test_property.domain
|
116
|
+
#
|
117
|
+
# # do a hard-coded check on the test_designer
|
118
|
+
# assert test_designer.range( test_property ).include?( KUOPIO::kuopion_museo )
|
119
|
+
#
|
120
|
+
# # all resources that are in the range of this property
|
121
|
+
# property_range = test_property.range
|
122
|
+
#
|
123
|
+
# # test that the designers are RDFS::Resources
|
124
|
+
# # and that the test_property is included in their properties
|
125
|
+
# designers.each do |designer|
|
126
|
+
# # STDERR.puts designer
|
127
|
+
# assert designer.is_a?( RDFS::Resource )
|
128
|
+
# assert designer.labelize.is_a?( String )
|
129
|
+
# assert designer.properties.include?( test_property )
|
130
|
+
#
|
131
|
+
# # check that the resources this designer has designed is included
|
132
|
+
# # in the property_range
|
133
|
+
# designer.range( test_property ).each do |designed_object|
|
134
|
+
# assert designed_object.is_a?( RDFS::Resource )
|
135
|
+
#
|
136
|
+
# # assert that the designed_object has the inverse property to
|
137
|
+
# # the test_property ( isDesignedBy )
|
138
|
+
# assert designed_object.properties.include?( test_property.inverse )
|
139
|
+
#
|
140
|
+
# # assert that this designer is actually the designer of this object
|
141
|
+
# object_designers = designed_object.range( test_property.inverse )
|
142
|
+
# assert object_designers.is_a?( Array )
|
143
|
+
# assert !object_designers.empty?
|
144
|
+
# assert object_designers.include?( designer )
|
145
|
+
#
|
146
|
+
# end
|
147
|
+
# end
|
148
|
+
# end
|
149
|
+
|
150
|
+
def test_recommendation_by_properties
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
end
|
155
|
+
#
|
156
|
+
#
|
157
|
+
# def test_images
|
158
|
+
# @@resources.each do |resource|
|
159
|
+
# images = resource.images
|
160
|
+
# assert images.is_a?( Array )
|
161
|
+
# if images.any?
|
162
|
+
# STDERR.puts "images found for #{resource}"
|
163
|
+
# images.each do |image|
|
164
|
+
# assert image.is_a?( Image )
|
165
|
+
# assert image.url.grep(/^http/).any?
|
166
|
+
# assert image.subjects.include?( resource )
|
167
|
+
# end
|
168
|
+
# end
|
169
|
+
# end
|
170
|
+
# end
|
171
|
+
|
172
|
+
# def test_geopoints
|
173
|
+
# @@resources.each do |resource|
|
174
|
+
# # STDERR.puts resource
|
175
|
+
# geopoint = resource.geopoint
|
176
|
+
# if geopoint
|
177
|
+
# # STDERR.puts "..is mappable"
|
178
|
+
# assert resource.is_mappable?
|
179
|
+
# assert geopoint.is_a?( RDFS::Resource )
|
180
|
+
# assert geopoint.lat != 0.0
|
181
|
+
# assert geopoint.long != 0.0
|
182
|
+
# else
|
183
|
+
# # STDERR.puts "..is not mappable"
|
184
|
+
# assert !resource.is_mappable?
|
185
|
+
# end
|
186
|
+
# end
|
187
|
+
#
|
188
|
+
# # test a specific instance that has a geopoint
|
189
|
+
# geopoint = KUOPIO::kuopion_museo
|
190
|
+
# STDERR.puts geopoint.labelize
|
191
|
+
# assert geopoint.is_mappable?
|
192
|
+
# assert geopoint.lat != 0.0
|
193
|
+
# assert geopoint.long != 0.0
|
194
|
+
#
|
195
|
+
# # test a specific instance, that gets the geopoint
|
196
|
+
# # through a property
|
197
|
+
# resource = TOIMIJAT::isa_camillo
|
198
|
+
# STDERR.puts resource.labelize
|
199
|
+
# assert resource.is_mappable?
|
200
|
+
# assert resource.lat != 0.0
|
201
|
+
# assert resource.long != 0.0
|
202
|
+
#
|
203
|
+
# # test a specific class
|
204
|
+
# owlclass = OWL::Class.new( KUOPIO::museot )
|
205
|
+
# assert owlclass.is_mappable?
|
206
|
+
# assert !owlclass.geopoints.empty?
|
207
|
+
#
|
208
|
+
# @@classes.each do |resource|
|
209
|
+
# STDERR.puts resource
|
210
|
+
# geopoints = resource.geopoints
|
211
|
+
# assert geopoints.is_a?( Array )
|
212
|
+
# if geopoints.any?
|
213
|
+
# STDERR.puts "..is mappable"
|
214
|
+
# assert resource.is_mappable?
|
215
|
+
# geopoints.each do |geopoint|
|
216
|
+
# assert geopoint.is_a?( RDFS::Resource )
|
217
|
+
# assert geopoint.labelize.is_a?( String )
|
218
|
+
# assert geopoint.lat != 0.0
|
219
|
+
# assert geopoint.long != 0.0
|
220
|
+
# assert geopoint.ancestors.include?( resource )
|
221
|
+
# end
|
222
|
+
# else
|
223
|
+
# STDERR.puts "..is not mappable"
|
224
|
+
# assert !resource.is_mappable?
|
225
|
+
# end
|
226
|
+
# end
|
227
|
+
# end
|
228
|
+
|
229
|
+
# def test_ancestors
|
230
|
+
# ( @@resources + @@classes ).each do |resource|
|
231
|
+
# ancestors = resource.ancestors
|
232
|
+
# assert ancestors.is_a?( Array )
|
233
|
+
# assert !ancestors.empty?
|
234
|
+
# ancestors.each do |ancestor|
|
235
|
+
# assert !ancestor.uri.nil?
|
236
|
+
# assert ancestor.is_a?( OWL::Class )
|
237
|
+
# # assert ancestor.is_class?
|
238
|
+
# end
|
239
|
+
# end
|
240
|
+
# end
|
241
|
+
#
|
242
|
+
# def test_parents
|
243
|
+
# ( @@resources + @@classes ).each do |resource|
|
244
|
+
# parents = resource.parents
|
245
|
+
# assert parents.is_a?( Array )
|
246
|
+
# assert !parents.empty?
|
247
|
+
# parents.each do |parent|
|
248
|
+
# assert !parent.uri.nil?
|
249
|
+
# assert parent.is_a?( OWL::Class )
|
250
|
+
# assert parent.is_class?
|
251
|
+
# assert resource.ancestors.include?( parent )
|
252
|
+
# end
|
253
|
+
# end
|
254
|
+
# end
|
255
|
+
#
|
256
|
+
# def test_children
|
257
|
+
# # add a specific class that definitely has children
|
258
|
+
# ( @@classes + [ OWL::Class.new( KUOPIO::rakennukset ) ] ).each do |resource|
|
259
|
+
# children = resource.children
|
260
|
+
# assert children.is_a?( Array )
|
261
|
+
# if children.any?
|
262
|
+
# children.each do |child|
|
263
|
+
# #STDERR.puts child
|
264
|
+
# assert !child.uri.nil?
|
265
|
+
# assert child.is_a?( OWL::Class )
|
266
|
+
# assert child.is_class?
|
267
|
+
# assert resource.descendants.include?( child )
|
268
|
+
# end
|
269
|
+
# end
|
270
|
+
# end
|
271
|
+
# end
|
272
|
+
#
|
273
|
+
# def test_descendants
|
274
|
+
# ( @@classes + [ OWL::Class.new( KUOPIO::rakennukset ) ] ).each do |resource|
|
275
|
+
# descendants = resource.descendants
|
276
|
+
# assert descendants.is_a?( Array )
|
277
|
+
# if descendants.any?
|
278
|
+
# descendants.each do |descendant|
|
279
|
+
# # STDERR.puts descendant
|
280
|
+
# assert !descendant.uri.nil?
|
281
|
+
# assert descendant.is_a?( OWL::Class )
|
282
|
+
# assert descendant.is_class?
|
283
|
+
# end
|
284
|
+
# end
|
285
|
+
# end
|
286
|
+
# end
|
287
|
+
#
|
288
|
+
# def test_class_instances
|
289
|
+
# @@classes.each do |resource|
|
290
|
+
# instances = resource.instances
|
291
|
+
# assert instances.is_a?( Array )
|
292
|
+
# assert !instances.empty?
|
293
|
+
# instances.each do |instance|
|
294
|
+
# assert !instance.uri.nil?
|
295
|
+
# assert instance.is_a?( RDFS::Resource )
|
296
|
+
# assert !instance.is_class?
|
297
|
+
# assert instance.ancestors.include?( resource )
|
298
|
+
# end
|
299
|
+
# end
|
300
|
+
# end
|
301
|
+
|
302
|
+
|
303
|
+
end
|
304
|
+
|
305
|
+
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
4
|
+
name: activerubic
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.8.0
|
7
|
+
date: 2008-01-01 00:00:00 +02:00
|
8
|
+
summary: ActiveRubic is a C/JRuby connector to semantic data stores, such as Jena and Joseki, using ActiveRDF.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: mikael.lammentausta( at )gmail.com
|
12
|
+
homepage: http://www.zenspider.com/ZSS/Products/ActiveRubic/
|
13
|
+
rubyforge_project: activerubic
|
14
|
+
description: The author was too lazy to write a description
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
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:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Mikael Lammentausta
|
31
|
+
files:
|
32
|
+
- History.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- README.txt
|
35
|
+
- Rakefile
|
36
|
+
- bin/active_rubic
|
37
|
+
- lib/active_rubic.rb
|
38
|
+
- test/test_active_rubic.rb
|
39
|
+
test_files:
|
40
|
+
- test/test_active_rubic.rb
|
41
|
+
rdoc_options:
|
42
|
+
- --main
|
43
|
+
- README.txt
|
44
|
+
extra_rdoc_files:
|
45
|
+
- History.txt
|
46
|
+
- Manifest.txt
|
47
|
+
- README.txt
|
48
|
+
executables:
|
49
|
+
- active_rubic
|
50
|
+
extensions: []
|
51
|
+
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
dependencies:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: hoe
|
57
|
+
version_requirement:
|
58
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.4.0
|
63
|
+
version:
|