talia_core 0.5.4 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +2 -2
- data/config/talia_core.yml.example +37 -35
- data/generators/talia_admin/templates/app/models/fake_source.rb +93 -0
- data/generators/talia_admin/templates/app/models/talia_collection.rb +13 -37
- data/generators/talia_base/talia_base_generator.rb +0 -1
- data/generators/talia_base/templates/app/controllers/custom_templates_controller.rb +2 -1
- data/generators/talia_base/templates/app/controllers/sources_controller.rb +1 -1
- data/generators/talia_base/templates/script/configure_talia +56 -73
- data/generators/talia_swicky/talia_swicky_generator.rb +18 -0
- data/generators/talia_swicky/templates/app/controllers/swicky_notebooks_controller.rb +111 -0
- data/generators/talia_swicky/templates/app/helpers/swicky_notebooks_helper.rb +29 -0
- data/generators/talia_swicky/templates/app/views/swicky_notebooks/index.builder +6 -0
- data/generators/talia_swicky/templates/app/views/swicky_notebooks/index.html.erb +10 -0
- data/generators/talia_swicky/templates/app/views/swicky_notebooks/show.html.erb +11 -0
- data/generators/talia_swicky/templates/test/fixtures/notebook.rdf +862 -0
- data/generators/talia_swicky/templates/test/functional/swicky_notebooks_controller_test.rb +44 -0
- data/lib/core_ext/boolean.rb +23 -0
- data/lib/core_ext/jdbc_rake_monkeypatch.rb +22 -0
- data/lib/core_ext/nil_class.rb +11 -0
- data/lib/core_ext/object.rb +34 -0
- data/lib/core_ext/string.rb +15 -0
- data/lib/custom_template.rb +3 -1
- data/lib/loader_helper.rb +16 -3
- data/lib/mysql.rb +7 -7
- data/lib/progressbar.rb +2 -2
- data/lib/swicky/exhibit_json/item.rb +129 -0
- data/lib/swicky/exhibit_json/item_collection.rb +129 -0
- data/lib/swicky/fragment.rb +0 -0
- data/lib/swicky/note.rb +7 -0
- data/lib/swicky/notebook.rb +78 -12
- data/lib/talia_core/active_source.rb +45 -13
- data/lib/talia_core/active_source_parts/class_methods.rb +154 -26
- data/lib/talia_core/active_source_parts/finders.rb +49 -26
- data/lib/talia_core/active_source_parts/predicate_handler.rb +71 -23
- data/lib/talia_core/active_source_parts/rdf/ntriples_reader.rb +13 -0
- data/lib/talia_core/active_source_parts/rdf/rdf_reader.rb +99 -0
- data/lib/talia_core/active_source_parts/rdf/rdfxml_reader.rb +12 -0
- data/lib/talia_core/active_source_parts/{rdf.rb → rdf_handler.rb} +52 -19
- data/lib/talia_core/active_source_parts/xml/generic_reader.rb +151 -260
- data/lib/talia_core/active_source_parts/xml/generic_reader_add_statements.rb +97 -0
- data/lib/talia_core/active_source_parts/xml/generic_reader_helpers.rb +88 -0
- data/lib/talia_core/active_source_parts/xml/generic_reader_import_statements.rb +239 -0
- data/lib/talia_core/active_source_parts/xml/rdf_builder.rb +14 -7
- data/lib/talia_core/active_source_parts/xml/source_builder.rb +7 -3
- data/lib/talia_core/active_source_parts/xml/source_reader.rb +17 -2
- data/lib/talia_core/collection.rb +192 -1
- data/lib/talia_core/data_types/data_loader.rb +88 -18
- data/lib/talia_core/data_types/data_record.rb +24 -2
- data/lib/talia_core/data_types/delayed_copier.rb +13 -3
- data/lib/talia_core/data_types/file_record.rb +24 -13
- data/lib/talia_core/data_types/file_store.rb +111 -94
- data/lib/talia_core/data_types/iip_data.rb +104 -23
- data/lib/talia_core/data_types/iip_loader.rb +102 -56
- data/lib/talia_core/data_types/image_data.rb +3 -1
- data/lib/talia_core/data_types/media_link.rb +4 -1
- data/lib/talia_core/data_types/mime_mapping.rb +65 -38
- data/lib/talia_core/data_types/path_helpers.rb +23 -17
- data/lib/talia_core/data_types/pdf_data.rb +9 -6
- data/lib/talia_core/data_types/simple_text.rb +5 -4
- data/lib/talia_core/data_types/xml_data.rb +53 -25
- data/lib/talia_core/dummy_handler.rb +3 -2
- data/lib/talia_core/errors.rb +13 -27
- data/lib/talia_core/initializer.rb +44 -4
- data/lib/talia_core/oai/active_source_model.rb +13 -6
- data/lib/talia_core/oai/active_source_oai_adapter.rb +13 -12
- data/lib/talia_core/rdf_import.rb +1 -1
- data/lib/talia_core/rdf_resource.rb +2 -1
- data/lib/talia_core/semantic_collection_wrapper.rb +143 -151
- data/lib/talia_core/semantic_property.rb +4 -0
- data/lib/talia_core/semantic_relation.rb +84 -33
- data/lib/talia_core/source.rb +45 -25
- data/lib/talia_core/source_fragment.rb +7 -0
- data/lib/talia_core/source_transfer_object.rb +3 -1
- data/lib/talia_core/source_types/agent.rb +16 -0
- data/lib/talia_core/source_types/dc_resource.rb +3 -3
- data/lib/talia_core/source_types/marcont_resource.rb +15 -0
- data/lib/talia_core/source_types/skos_concept.rb +17 -0
- data/lib/talia_dependencies.rb +1 -1
- data/lib/talia_util.rb +1 -1
- data/lib/talia_util/bar_progressor.rb +1 -1
- data/lib/talia_util/image_conversions.rb +8 -2
- data/lib/talia_util/import_job_helper.rb +40 -3
- data/lib/talia_util/io_helper.rb +15 -4
- data/lib/talia_util/progressable.rb +50 -1
- data/lib/talia_util/rake_tasks.rb +3 -21
- data/lib/talia_util/test_helpers.rb +6 -1
- data/lib/talia_util/util.rb +108 -27
- data/lib/talia_util/xml/base_builder.rb +28 -1
- data/lib/talia_util/xml/rdf_builder.rb +81 -5
- data/lib/tasks/talia_core_tasks.rake +2 -0
- data/test/core_ext/boolean_test.rb +26 -0
- data/test/core_ext/nil_class_test.rb +14 -0
- data/test/core_ext/object_test.rb +26 -0
- data/test/core_ext/string_test.rb +11 -0
- data/test/swicky/json_encoder_test.rb +51 -42
- data/test/swicky/notebook_test.rb +13 -6
- data/test/talia_core/active_source_finder_interface_test.rb +30 -0
- data/test/talia_core/active_source_test.rb +445 -34
- data/test/talia_core/collection_test.rb +332 -0
- data/test/talia_core/data_types/file_record_test.rb +2 -23
- data/test/talia_core/ntriples_reader_test.rb +49 -0
- data/test/talia_core/rdfxml_reader_test.rb +51 -0
- data/test/talia_core/source_test.rb +12 -0
- data/test/talia_util/import_job_helper_test.rb +19 -12
- metadata +190 -90
- data/config/database.yml +0 -19
- data/config/rdfstore.yml +0 -13
- data/config/talia_core.yml +0 -24
- data/generators/talia_base/templates/migrations/bj_migration.rb +0 -10
- data/lib/JXslt/jxslt.rb +0 -60
- data/lib/swicky/json_encoder.rb +0 -179
- data/lib/talia_core/agent.rb +0 -14
- data/lib/talia_core/background_jobs/job.rb +0 -82
- data/lib/talia_core/background_jobs/progress_job.rb +0 -68
- data/lib/talia_core/data_types/temp_file_handling.rb +0 -85
- data/lib/talia_core/ordered_source.rb +0 -228
- data/lib/talia_core/semantic_collection_item.rb +0 -94
- data/lib/talia_core/source_types/collection.rb +0 -15
- data/lib/talia_util/progressbar.rb +0 -236
- data/tasks/talia_core_tasks.rake +0 -2
- data/test/talia_core/ordered_source_test.rb +0 -394
- data/test/talia_core/semantic_collection_item_test.rb +0 -125
@@ -7,7 +7,34 @@ module TaliaUtil
|
|
7
7
|
# All builders will be used through the #open method, which can be passed either a Builder::XmlMarkup
|
8
8
|
# object, or the options to create one.
|
9
9
|
#
|
10
|
-
# Subclasses must provide a build_structure method
|
10
|
+
# Subclasses must provide a method named "build_structure" method. The method must accept a block,
|
11
|
+
# and should create the outer structure of the XML document and yield to the block to build the
|
12
|
+
# inner content.
|
13
|
+
#
|
14
|
+
# = Example:
|
15
|
+
#
|
16
|
+
# class ABuilder < BaseBuilder
|
17
|
+
#
|
18
|
+
# def build_structure
|
19
|
+
# @builder.div { yield }
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# def write_stuff(text)
|
23
|
+
# @builder.p { @builder.text!(text) }
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# xml = ABuilder.make_xml_string do |builder|
|
28
|
+
# builder.write_stuff("Hello")
|
29
|
+
# builder.write_stuff("world")
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# Which would result in:
|
33
|
+
#
|
34
|
+
# <div>
|
35
|
+
# <p>Hello</p>
|
36
|
+
# <p>World</p>
|
37
|
+
# </div>
|
11
38
|
class BaseBuilder
|
12
39
|
|
13
40
|
# Creates a new builder. The options are equivalent for the options of the
|
@@ -1,6 +1,30 @@
|
|
1
1
|
module TaliaUtil
|
2
2
|
module Xml
|
3
|
-
#
|
3
|
+
# Extends the BaseBuilder to allow for easy writing of xml-rdf data. This can
|
4
|
+
# be used in a very self-contained way, by simply passing the triples to write
|
5
|
+
# out to the #open_for_triples or #xml_string_for_triples methods.
|
6
|
+
#
|
7
|
+
# If those self-contained methods are used the, builder will also "group" the
|
8
|
+
# rdf triples, by including all relations for a single subjects in a single tag,
|
9
|
+
# etc.
|
10
|
+
#
|
11
|
+
# Each triple is expected to be an array of 3 elements, for subject, predicate
|
12
|
+
# and object. Multiple triples are passed as an array of such arrays.
|
13
|
+
#
|
14
|
+
# It is also possible to create a builder manually and use the #write_triple
|
15
|
+
# inside.
|
16
|
+
#
|
17
|
+
# The resulting XML will contain namespace definitions for all namespaces
|
18
|
+
# currently known by N::Namespace.
|
19
|
+
#
|
20
|
+
# If the self-contained writer methods is used, it will also build namespace
|
21
|
+
# definitions for all predicates (so that each predicate is expressed as
|
22
|
+
# namespace:name).
|
23
|
+
#
|
24
|
+
# The namespaces for predicates are not built when using write
|
25
|
+
# methods like write_triple directly. In that case a predicate that is
|
26
|
+
# outside a known namespace would cause an invalid xml-rdf, as predicates
|
27
|
+
# must not be expressed as full URIs in that format.
|
4
28
|
class RdfBuilder < BaseBuilder
|
5
29
|
|
6
30
|
# Writes a simple "flat" triple. If the object is a string, it will be
|
@@ -24,7 +48,9 @@ module TaliaUtil
|
|
24
48
|
end
|
25
49
|
end
|
26
50
|
|
27
|
-
#
|
51
|
+
# Opens a new builder with the given options (see BaseBuilder.open) and
|
52
|
+
# writes all the triples given into an xml-rdf document. This will
|
53
|
+
# try to intelligently group the tags to make the result more compact.
|
28
54
|
def self.open_for_triples(triples, options = nil)
|
29
55
|
my_builder = self.new(options)
|
30
56
|
|
@@ -36,6 +62,8 @@ module TaliaUtil
|
|
36
62
|
end
|
37
63
|
|
38
64
|
|
65
|
+
# Same as open_for_triples, but writes into a string and returns that
|
66
|
+
# string.
|
39
67
|
def self.xml_string_for_triples(triples)
|
40
68
|
xml = ''
|
41
69
|
open_for_triples(triples, :target => xml, :indent => 2)
|
@@ -44,7 +72,19 @@ module TaliaUtil
|
|
44
72
|
|
45
73
|
private
|
46
74
|
|
47
|
-
|
75
|
+
# "Prepares" all the triples into a hash of hashes. This will take the triples
|
76
|
+
# and build a hash which has all subjects as keys. The value for each subject
|
77
|
+
# will be another hash that has all predicates as keys. The value for each
|
78
|
+
# predicate will be an array with all object values for the triple.
|
79
|
+
#
|
80
|
+
# = Pseudo-Example:
|
81
|
+
# # Input:
|
82
|
+
# [["subject", "predicate1", "value"], ["subject", "predicate2", "value2"], ["subject", "predicate2", "value3"]]
|
83
|
+
# # Output:
|
84
|
+
# {
|
85
|
+
# "subject" => { "predicate1" => ["value", "value2"], "predicate2" => ["value3"] }
|
86
|
+
# }
|
87
|
+
#
|
48
88
|
def prepare_triples(triples)
|
49
89
|
triple_hash = {}
|
50
90
|
triples.each do |triple|
|
@@ -63,7 +103,8 @@ module TaliaUtil
|
|
63
103
|
triple_hash
|
64
104
|
end
|
65
105
|
|
66
|
-
#
|
106
|
+
# Special writer that takes a hash of triples that is produced by #prepare_triples
|
107
|
+
# and writes it out to the XML document.
|
67
108
|
def write_for_triples(triple_hash)
|
68
109
|
triple_hash.each do |subject, values|
|
69
110
|
@builder.rdf :Description, 'rdf:about' => subject.to_uri.to_name_s do # Element describing this resource
|
@@ -74,6 +115,12 @@ module TaliaUtil
|
|
74
115
|
end
|
75
116
|
end
|
76
117
|
|
118
|
+
# This is used to make a namespace for a given predicate. It splits
|
119
|
+
# the URI using #split_uri! and passes the "namespace" part of the
|
120
|
+
# URI to #make_namespace to create a symbolic name for it.
|
121
|
+
#
|
122
|
+
# The method returns the uri of the predicate in a "namespace:local_name"
|
123
|
+
# notation.
|
77
124
|
def make_predicate_namespace(predicate)
|
78
125
|
pred_uri = URI.parse(predicate.to_s)
|
79
126
|
path_parts = split_uri!(pred_uri)
|
@@ -82,6 +129,12 @@ module TaliaUtil
|
|
82
129
|
"#{namespace}:#{path_parts[1]}"
|
83
130
|
end
|
84
131
|
|
132
|
+
|
133
|
+
# Split a URI into a namespace part and local part. The local part
|
134
|
+
# is either the fragment (part after the # character), or the part
|
135
|
+
# after the last forward slash.
|
136
|
+
#
|
137
|
+
# This method needs an URI object from the standard ruby library.
|
85
138
|
def split_uri!(uri)
|
86
139
|
if(uri.fragment)
|
87
140
|
fragment = uri.fragment
|
@@ -94,6 +147,15 @@ module TaliaUtil
|
|
94
147
|
end
|
95
148
|
end
|
96
149
|
|
150
|
+
# Create a namespace from a given uri. The method creates a
|
151
|
+
# symbolic name for the namespace from the uri; it will try to
|
152
|
+
# create a "readable" result.
|
153
|
+
#
|
154
|
+
# The method checks all the previously created namespaces, in case
|
155
|
+
# of a name collision, a number is added to the namespace name.
|
156
|
+
#
|
157
|
+
# All newly created namespaces are added to a hash that can be
|
158
|
+
# accessed with #additional_namespaces
|
97
159
|
def make_namespace(namespace_uri)
|
98
160
|
candidate = /([^\.]+)(\.[^\.]*)?\Z/.match(namespace_uri.host)[1]
|
99
161
|
raise(ArgumentError, "Illegal namespace #{namespace_uri.to_s}") if(candidate.blank?)
|
@@ -117,16 +179,27 @@ module TaliaUtil
|
|
117
179
|
end
|
118
180
|
end
|
119
181
|
|
182
|
+
# Automatically created namespaces for predicates as a hash. Namespaces
|
183
|
+
# are added when they are created using the #make_namespace method.
|
120
184
|
def additional_namespaces
|
121
185
|
@additional_namespaces ||= {}
|
122
186
|
end
|
123
187
|
|
188
|
+
# Returns all namespaces configured in N::Namespace and adds the
|
189
|
+
# #additional_namespaces to the result
|
190
|
+
#
|
191
|
+
# Returns a hash where the keys are the xmlns namespace name and the values are
|
192
|
+
# the namespace URIs
|
124
193
|
def namespaces
|
125
194
|
namespaces = self.class.namespaces
|
126
195
|
additional_namespaces.each { |key, value| namespaces["xmlns:#{key.to_s}"] = value.to_s }
|
127
196
|
namespaces
|
128
197
|
end
|
129
198
|
|
199
|
+
# Returns all namespaces configured in N::Namespace
|
200
|
+
#
|
201
|
+
# Returns a hash where the keys are the xmlns namespace name and the values are
|
202
|
+
# the namespace URIs
|
130
203
|
def self.namespaces
|
131
204
|
@namespaces ||= begin
|
132
205
|
namespaces = {}
|
@@ -135,11 +208,14 @@ module TaliaUtil
|
|
135
208
|
end
|
136
209
|
end
|
137
210
|
|
138
|
-
# Build an rdf/xml string for one predicate, with the given values
|
211
|
+
# Build an rdf/xml string for one predicate, with the given values. This is the
|
212
|
+
# same as #write_single_predicate for multiple values.
|
139
213
|
def write_predicate(predicate, values, check_predicate = true)
|
140
214
|
values.each { |val| write_single_predicate(predicate, val, check_predicate) }
|
141
215
|
end # end method
|
142
216
|
|
217
|
+
# Writes a single predicate with the given value. When check_predicate is set, this
|
218
|
+
# will raise an error if the predicate cannot be represented as "namespace:name"
|
143
219
|
def write_single_predicate(predicate, value, check_predicate = true)
|
144
220
|
is_property = value.respond_to?(:uri)
|
145
221
|
value_properties = is_property ? { 'value' => value } : extract_values(value.to_s)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'core_ext', 'boolean')
|
3
|
+
|
4
|
+
class BooleanTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_true_yes
|
7
|
+
assert(true.yes?)
|
8
|
+
assert(true.true?)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_true_no
|
12
|
+
assert(!true.no?)
|
13
|
+
assert(!true.false?)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_false_yes
|
17
|
+
assert(!false.yes?)
|
18
|
+
assert(!false.true?)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_false_no
|
22
|
+
assert(false.no?)
|
23
|
+
assert(false.false?)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'core_ext', 'nil_class')
|
3
|
+
|
4
|
+
class NilClassTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_yes
|
7
|
+
assert(!nil.yes?)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_no
|
11
|
+
assert(nil.no?)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'core_ext', 'object')
|
3
|
+
|
4
|
+
class ObjectTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_try_call_on_existing
|
7
|
+
assert_equal('abc', 'abc'.try_call.to_s)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_try_call_on_not_existing
|
11
|
+
assert_nothing_raised do
|
12
|
+
assert_equal(nil, 'abc'.try_call.foo)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_try_call_on_existing_alternative
|
17
|
+
assert_equal('abc', 'abc'.try_call(:to_s))
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_try_call_on_not_existing_alternative
|
21
|
+
assert_nothing_raised do
|
22
|
+
assert_equal(nil, 'abc'.try_call(:foo))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -13,4 +13,15 @@ class StringTest < Test::Unit::TestCase
|
|
13
13
|
assert_equal(N::URI.new('http://foo-foo.com'), 'http://foo-foo.com'.to_uri)
|
14
14
|
assert_kind_of(N::URI, 'foo-foo.com'.to_uri)
|
15
15
|
end
|
16
|
+
|
17
|
+
def test_yes
|
18
|
+
assert(" YeS ".yes?)
|
19
|
+
assert("TRUE".yes?)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_no
|
23
|
+
assert("No ".no?)
|
24
|
+
assert("false".no?)
|
25
|
+
end
|
26
|
+
|
16
27
|
end
|
@@ -6,43 +6,17 @@ module Swicky
|
|
6
6
|
class JsonEncoderTest < ActiveSupport::TestCase
|
7
7
|
|
8
8
|
def setup
|
9
|
-
@encoder =
|
9
|
+
@encoder = ExhibitJson::ItemCollection.new(test_triples)
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
|
14
|
-
assert_equal('
|
15
|
-
assert_equal({ 'foobar' => { 'uri' => N::TALIA.foobar.to_s, 'valueType' => 'item' } }, @encoder.instance_variable_get(:@properties_hash))
|
12
|
+
def test_item_label
|
13
|
+
fake_item = ExhibitJson::Item.new(N::TALIA.item_label_test, @encoder)
|
14
|
+
assert_equal('item_label_test', fake_item.label)
|
16
15
|
end
|
17
16
|
|
18
|
-
def
|
19
|
-
|
20
|
-
@encoder.
|
21
|
-
@encoder.send(:make_predicate_local, N::TALIA.foobar)
|
22
|
-
local = @encoder.send(:make_predicate_local, N::RDF.foobar)
|
23
|
-
assert_equal('foobar3', local)
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_make_type_local
|
27
|
-
local = @encoder.send(:make_type_local, N::TALIA.Foobar)
|
28
|
-
assert_equal('Foobar', local)
|
29
|
-
assert_equal({ 'Foobar' => { 'uri' => N::TALIA.Foobar.to_s } }, @encoder.instance_variable_get(:@types_hash))
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_build_item
|
33
|
-
item = @encoder.send(:build_item, N::LOCAL.Foo, {
|
34
|
-
N::RDF.type => [ N::TALIA.Foobar ],
|
35
|
-
N::TALIA.hasIt => ['blarg', 'bar'],
|
36
|
-
N::TALIA.strangeThing => ['what'],
|
37
|
-
'label' => 'bar'
|
38
|
-
})
|
39
|
-
assert_equal([{
|
40
|
-
'uri' => N::LOCAL.Foo.to_s,
|
41
|
-
'type' => [ 'Foobar' ],
|
42
|
-
'label' => 'bar',
|
43
|
-
'hasIt' => ['blarg', 'bar'],
|
44
|
-
'strangeThing' => 'what'
|
45
|
-
}], item)
|
17
|
+
def test_make_id
|
18
|
+
fake_item = ExhibitJson::Item.new(N::TALIA.test_make_id, @encoder)
|
19
|
+
assert_equal('test_make_id', @encoder.make_id(fake_item))
|
46
20
|
end
|
47
21
|
|
48
22
|
def test_to_json
|
@@ -55,53 +29,88 @@ module Swicky
|
|
55
29
|
{
|
56
30
|
"items" => [
|
57
31
|
{
|
32
|
+
"label" => 'toplevel',
|
33
|
+
"uri" => "http://toplevel.org/",
|
34
|
+
"id" => "toplevel",
|
35
|
+
"hash" => "h_d11eb7d2122d6af02a9079d975eaec35",
|
36
|
+
"type" => [ "MyType" ]
|
37
|
+
},
|
38
|
+
{
|
39
|
+
"label"=>"foobar",
|
58
40
|
"uri"=>N::LOCAL.foobar.to_s,
|
41
|
+
"id"=>"foobar",
|
42
|
+
"hash"=>digest(N::LOCAL.foobar.to_s),
|
59
43
|
"type"=>["MyType"],
|
60
44
|
"label"=>"foobar",
|
61
45
|
"first"=>["worksit", "worksit2"]
|
62
46
|
},
|
63
47
|
{
|
64
|
-
"uri"=>N::TALIA.whatever.to_s,
|
65
|
-
"type"=>["Resource"],
|
66
48
|
"label"=>"whatever",
|
67
|
-
"
|
68
|
-
"
|
49
|
+
"uri"=>N::TALIA.whatever.to_s,
|
50
|
+
"id"=>"whatever",
|
51
|
+
"hash"=>digest(N::TALIA.whatever.to_s),
|
52
|
+
"type"=>["Resource"],
|
53
|
+
"predicate"=>"fun",
|
54
|
+
"first2"=>"fun"
|
69
55
|
},
|
70
56
|
{
|
57
|
+
"label"=>"The cool thing",
|
71
58
|
"uri"=>"http://www.barbaa.com/fun",
|
59
|
+
"id"=>"fun",
|
60
|
+
"hash"=>digest("http://www.barbaa.com/fun"),
|
72
61
|
"type"=>["Resource"],
|
73
|
-
"label"=>"The cool thing",
|
74
62
|
"predicate"=>"whatever"
|
75
63
|
}
|
76
64
|
],
|
77
65
|
"types" => {
|
78
66
|
"MyType"=>
|
79
67
|
{
|
80
|
-
"
|
68
|
+
"label"=>"MyType",
|
69
|
+
"uri"=>N::TALIA.MyType.to_s,
|
70
|
+
"id"=>"MyType",
|
71
|
+
"hash"=>digest(N::TALIA.MyType.to_s)
|
81
72
|
},
|
82
73
|
"Resource"=> {
|
83
|
-
"
|
74
|
+
"label"=>"Resource",
|
75
|
+
"uri"=>"http://www.w3.org/1999/02/22-rdf-syntax-ns#Resource",
|
76
|
+
"id"=>"Resource",
|
77
|
+
"hash"=>digest("http://www.w3.org/1999/02/22-rdf-syntax-ns#Resource")
|
84
78
|
}
|
85
79
|
},
|
86
80
|
"properties"=> {
|
87
81
|
"first"=> {
|
82
|
+
"label"=>"first",
|
88
83
|
"uri"=>"http://www.foobar.com/bar/moo/first",
|
89
|
-
"
|
84
|
+
"id"=>"first",
|
85
|
+
"hash"=>digest("http://www.foobar.com/bar/moo/first"),
|
86
|
+
"valueType"=>"text"
|
90
87
|
},
|
91
88
|
"predicate"=>{
|
89
|
+
"label"=>"predicate",
|
92
90
|
"uri"=>N::TALIA.predicate.to_s,
|
91
|
+
"id"=>"predicate",
|
92
|
+
"hash"=>digest(N::TALIA.predicate.to_s),
|
93
93
|
"valueType"=>"item"
|
94
94
|
},
|
95
95
|
"first2"=>{
|
96
|
-
"
|
96
|
+
"label"=>"first",
|
97
|
+
"uri"=>"http://www.foobar.com/bar/moo#first",
|
98
|
+
"id"=>"first2",
|
99
|
+
"hash"=>digest("http://www.foobar.com/bar/moo#first"),
|
100
|
+
"valueType"=>"item"
|
97
101
|
}
|
98
102
|
}
|
99
103
|
}
|
100
104
|
end
|
101
105
|
|
102
106
|
|
107
|
+
def digest(value)
|
108
|
+
('h_' << Digest::MD5.hexdigest(value))
|
109
|
+
end
|
110
|
+
|
103
111
|
def test_triples
|
104
112
|
[
|
113
|
+
[ 'http://toplevel.org/', N::RDF.type, N::TALIA.MyType ],
|
105
114
|
[ N::LOCAL.foobar, 'http://www.foobar.com/bar/moo/first', "worksit"],
|
106
115
|
[ N::LOCAL.foobar, 'http://www.foobar.com/bar/moo/first', "worksit2"],
|
107
116
|
[ N::LOCAL.foobar, N::RDF.type, N::TALIA.MyType ],
|
@@ -11,6 +11,7 @@ module Swicky
|
|
11
11
|
setup_once(:flush) { TaliaCore::TestHelper::flush_store }
|
12
12
|
@notebook = Notebook.new('dan', 'booky')
|
13
13
|
@testpointer = "http://dbin.org/swickynotes/demo/HanselAndGretel.htm#xpointer(start-point(string-range(//DIV[@id='http://dbin.org/swickynotes/demo/HG_1']/P[1]/SPAN[1]/text()[1],'',0))/range-to(string-range(//DIV[@id='http://dbin.org/swickynotes/demo/HG_1']/P[1]/SPAN[1]/text()[1],'',266)))"
|
14
|
+
@testfragment = "http://discovery-project.eu/ontologies/philoSpace/SourceFragment#ec9796a5349b290a7610763dcbc47af2"
|
14
15
|
end
|
15
16
|
|
16
17
|
def teardown
|
@@ -25,6 +26,12 @@ module Swicky
|
|
25
26
|
assert_equal(@notebook.user_url, N::LOCAL + 'users/dan')
|
26
27
|
end
|
27
28
|
|
29
|
+
def test_url_from_string
|
30
|
+
nb = Notebook.new('http://foobar.org/')
|
31
|
+
assert_kind_of(N::URI, nb.uri)
|
32
|
+
assert_equal(nb.uri, 'http://foobar.org/'.to_uri)
|
33
|
+
end
|
34
|
+
|
28
35
|
def test_load
|
29
36
|
assert_notebook_empty
|
30
37
|
load_notebook
|
@@ -57,12 +64,12 @@ module Swicky
|
|
57
64
|
|
58
65
|
def test_find_all_existing
|
59
66
|
load_notebook
|
60
|
-
assert_equal([@notebook.url], Notebook.find_all)
|
67
|
+
assert_equal([Notebook.new(@notebook.url)], Notebook.find_all)
|
61
68
|
end
|
62
69
|
|
63
70
|
def test_find_all_user
|
64
71
|
load_notebook
|
65
|
-
assert_equal([@notebook.url], Notebook.find_all('dan'))
|
72
|
+
assert_equal([Notebook.new(@notebook.url)], Notebook.find_all('dan'))
|
66
73
|
end
|
67
74
|
|
68
75
|
def test_find_all_user_nonexistent
|
@@ -73,17 +80,17 @@ module Swicky
|
|
73
80
|
def test_get_coordinates
|
74
81
|
load_notebook
|
75
82
|
coords = Notebook.coordinates_for("http://dbin.org/swickynotes/demo/HanselAndGretel.htm")
|
76
|
-
assert_equal([ @testpointer
|
83
|
+
assert_equal([{"fragment" => @testfragment, "coordinates" => @testpointer}], coords)
|
77
84
|
end
|
78
85
|
|
79
86
|
def test_annotations_for_url
|
80
87
|
load_notebook
|
81
|
-
assert_equal(
|
88
|
+
assert_equal(135, Notebook.annotations_for_url("http://discovery-project.eu/ontologies/philoSpace/SourceFragment#ec9796a5349b290a7610763dcbc47af2").size)
|
82
89
|
end
|
83
90
|
|
84
91
|
def test_annotations_for_xpointer
|
85
92
|
load_notebook
|
86
|
-
assert_equal(
|
93
|
+
assert_equal(135, Notebook.annotations_for_xpointer(@testpointer).size)
|
87
94
|
end
|
88
95
|
|
89
96
|
private
|
@@ -104,4 +111,4 @@ module Swicky
|
|
104
111
|
|
105
112
|
end
|
106
113
|
|
107
|
-
end
|
114
|
+
end
|