talia_core 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. data/README.rdoc +6 -27
  2. data/VERSION.yml +3 -2
  3. data/config/database.yml +11 -11
  4. data/config/talia_core.yml +11 -6
  5. data/config/talia_core.yml.example +11 -6
  6. data/generators/talia_base/talia_base_generator.rb +3 -0
  7. data/generators/talia_base/templates/README +1 -1
  8. data/generators/talia_base/templates/app/controllers/source_data_controller.rb +1 -1
  9. data/generators/talia_base/templates/app/controllers/sources_controller.rb +31 -12
  10. data/generators/talia_base/templates/app/helpers/sources_helper.rb +77 -1
  11. data/generators/talia_base/templates/app/views/layouts/sources.html.erb +22 -0
  12. data/generators/talia_base/templates/app/views/sources/_data_list.html.erb +17 -0
  13. data/generators/talia_base/templates/app/views/sources/_property_item.html.erb +10 -0
  14. data/generators/talia_base/templates/app/views/sources/_property_list.html.erb +13 -0
  15. data/generators/talia_base/templates/app/views/sources/index.html.erb +16 -11
  16. data/generators/talia_base/templates/app/views/sources/semantic_templates/default/default.html.erb +8 -19
  17. data/generators/talia_base/templates/config/routes.rb +11 -0
  18. data/generators/talia_base/templates/migrations/create_semantic_relations.rb +2 -1
  19. data/generators/talia_base/templates/public/images/core/arrow.png +0 -0
  20. data/generators/talia_base/templates/public/images/core/building.png +0 -0
  21. data/generators/talia_base/templates/public/images/core/contents_top_left.gif +0 -0
  22. data/generators/talia_base/templates/public/images/core/document-horizontal-text.png +0 -0
  23. data/generators/talia_base/templates/public/images/core/document.png +0 -0
  24. data/generators/talia_base/templates/public/images/core/gear.png +0 -0
  25. data/generators/talia_base/templates/public/images/core/group.png +0 -0
  26. data/generators/talia_base/templates/public/images/core/header_bg.gif +0 -0
  27. data/generators/talia_base/templates/public/images/core/image.png +0 -0
  28. data/generators/talia_base/templates/public/images/core/imagebig.png +0 -0
  29. data/generators/talia_base/templates/public/images/core/left_edge.gif +0 -0
  30. data/generators/talia_base/templates/public/images/core/letter.png +0 -0
  31. data/generators/talia_base/templates/public/images/core/line.png +0 -0
  32. data/generators/talia_base/templates/public/images/core/logo.gif +0 -0
  33. data/generators/talia_base/templates/public/images/core/map.png +0 -0
  34. data/generators/talia_base/templates/public/images/core/period.png +0 -0
  35. data/generators/talia_base/templates/public/images/core/person.png +0 -0
  36. data/generators/talia_base/templates/public/images/core/person_default.png +0 -0
  37. data/generators/talia_base/templates/public/images/core/place.png +0 -0
  38. data/generators/talia_base/templates/public/images/core/source.png +0 -0
  39. data/generators/talia_base/templates/public/images/core/television.png +0 -0
  40. data/generators/talia_base/templates/public/images/core/text.png +0 -0
  41. data/generators/talia_base/templates/public/images/core/type.png +0 -0
  42. data/generators/talia_base/templates/public/images/core/video.png +0 -0
  43. data/generators/talia_base/templates/public/stylesheets/img/arrow.png +0 -0
  44. data/generators/talia_base/templates/public/stylesheets/main.css +276 -0
  45. data/generators/talia_base/templates/script/configure_talia +1 -1
  46. data/generators/talia_base/templates/script/setup_talia_backend +2 -0
  47. data/lib/core_ext/platform.rb +1 -0
  48. data/lib/core_ext/string.rb +6 -0
  49. data/lib/talia_core/active_source.rb +62 -3
  50. data/lib/talia_core/active_source_parts/class_methods.rb +36 -122
  51. data/lib/talia_core/active_source_parts/finders.rb +158 -0
  52. data/lib/talia_core/active_source_parts/predicate_handler.rb +7 -8
  53. data/lib/talia_core/active_source_parts/xml/generic_reader.rb +95 -11
  54. data/lib/talia_core/active_source_parts/xml/rdf_builder.rb +6 -13
  55. data/lib/talia_core/active_source_parts/xml/source_reader.rb +8 -3
  56. data/lib/talia_core/data_types/data_loader.rb +14 -6
  57. data/lib/talia_core/data_types/data_record.rb +5 -1
  58. data/lib/talia_core/data_types/iip_data.rb +1 -1
  59. data/lib/talia_core/data_types/mime_mapping.rb +8 -3
  60. data/lib/talia_core/errors.rb +4 -0
  61. data/lib/talia_core/initializer.rb +1 -8
  62. data/lib/talia_core/property_string.rb +58 -0
  63. data/lib/talia_core/semantic_collection_item.rb +3 -2
  64. data/lib/talia_core/semantic_collection_wrapper.rb +236 -198
  65. data/lib/talia_core/source.rb +130 -178
  66. data/lib/talia_core/source_types/collection.rb +15 -0
  67. data/lib/talia_core/source_types/dc_resource.rb +22 -0
  68. data/lib/talia_core/source_types/dummy_source.rb +22 -0
  69. data/lib/talia_core.rb +0 -1
  70. data/lib/talia_util/import_job_helper.rb +44 -16
  71. data/lib/talia_util/io_helper.rb +21 -1
  72. data/lib/talia_util/rake_tasks.rb +48 -72
  73. data/lib/talia_util/rdf_update.rb +22 -13
  74. data/lib/talia_util/test_helpers.rb +1 -1
  75. data/lib/talia_util.rb +0 -2
  76. data/test/core_ext/string_test.rb +5 -0
  77. data/test/talia_core/active_source_test.rb +151 -14
  78. data/test/talia_core/generic_xml_test.rb +46 -2
  79. data/test/talia_core/initializer_test.rb +0 -1
  80. data/test/talia_core/property_string_test.rb +78 -0
  81. data/test/talia_core/source_reader_test.rb +5 -1
  82. data/test/talia_core/source_test.rb +23 -32
  83. data/test/talia_util/import_job_helper_test.rb +1 -1
  84. data/test/talia_util/io_helper_test.rb +44 -0
  85. metadata +399 -373
  86. data/generators/talia_base/templates/app/views/sources/semantic_templates/default/province.html.erb +0 -19
  87. data/lib/acts_as_roled.rb +0 -11
  88. data/lib/talia_core/collection.rb +0 -13
  89. data/lib/talia_core/dc_resource.rb +0 -20
  90. data/lib/talia_core/dummy_source.rb +0 -20
  91. data/lib/talia_core/rails_ext/actionpack/action_controller/record_identifier.rb +0 -13
  92. data/lib/talia_core/rails_ext/actionpack/action_controller.rb +0 -1
  93. data/lib/talia_core/rails_ext/actionpack.rb +0 -1
  94. data/lib/talia_core/rails_ext.rb +0 -1
  95. data/lib/talia_util/data_import.rb +0 -91
  96. data/lib/talia_util/yaml_import.rb +0 -80
@@ -0,0 +1,78 @@
1
+ require 'test/unit'
2
+
3
+ # Load the helper class
4
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
5
+
6
+ module TaliaCore
7
+ class PropertyStringTest < Test::Unit::TestCase
8
+
9
+ def test_simple_value
10
+ props = PropertyString.parse('value')
11
+ assert_equal('value', props)
12
+ assert_equal(nil, props.lang)
13
+ assert_equal(nil, props.type)
14
+ end
15
+
16
+ def test_language
17
+ props = PropertyString.parse('value@en')
18
+ assert_equal('value', props)
19
+ assert_equal('en', props.lang)
20
+ assert_equal(nil, props.type)
21
+ end
22
+
23
+ def test_lang_type
24
+ props = PropertyString.parse('value@en^^string')
25
+ assert_equal('value', props)
26
+ assert_equal('en', props.lang)
27
+ assert_equal('string', props.type)
28
+ end
29
+
30
+ def test_type_lang
31
+ props = PropertyString.parse('value^^string@en')
32
+ assert_equal('value', props)
33
+ assert_equal('en', props.lang)
34
+ assert_equal('string', props.type)
35
+ end
36
+
37
+ def test_type
38
+ props = PropertyString.parse('value^^string')
39
+ assert_equal('value', props)
40
+ assert_equal(nil, props.lang)
41
+ assert_equal('string', props.type)
42
+ end
43
+
44
+ def test_type_no_val
45
+ props = PropertyString.parse('^^string')
46
+ assert_equal('', props)
47
+ assert_equal(nil, props.lang)
48
+ assert_equal('string', props.type)
49
+ end
50
+
51
+ def test_lang_no_val
52
+ props = PropertyString.parse('@en')
53
+ assert_equal('', props)
54
+ assert_equal('en', props.lang)
55
+ assert_equal(nil, props.type)
56
+ end
57
+
58
+ def test_lang_type_no_val
59
+ props = PropertyString.parse('@en^^string')
60
+ assert_equal('', props)
61
+ assert_equal('en', props.lang)
62
+ assert_equal('string', props.type)
63
+ end
64
+
65
+ def test_to_rdf
66
+ props = PropertyString.parse('value^^string@en')
67
+ assert_equal('value^^string@en', props.to_rdf)
68
+ assert_equal('value', props)
69
+ end
70
+
71
+ def test_to_rdf_lang_with_new
72
+ props = PropertyString.new('value', 'en')
73
+ assert_equal('value@en', props.to_rdf)
74
+ assert_equal('value', props)
75
+ end
76
+
77
+ end
78
+ end
@@ -9,7 +9,7 @@ module TaliaCore
9
9
  suppress_fixtures
10
10
 
11
11
  def setup
12
- @test_xml = "<sources><source><attribute><predicate>uri\n</predicate>\n<value>http://foodonga.com</value></attribute><attribute><predicate>http://bongobongo.com</predicate><value>foo\n</value><value> bar</value><object>http:/bingobongo.com</object></attribute></source></sources>"
12
+ @test_xml = "<sources><source><attribute><predicate>uri\n</predicate>\n<value>http://foodonga.com</value></attribute><attribute><predicate>http://bongobongo.com</predicate><value>foo\n</value><value xml:lang='en'>bar</value><object>http:/bingobongo.com</object></attribute></source></sources>"
13
13
  @sources = ActiveSourceParts::Xml::SourceReader.sources_from(@test_xml)
14
14
  end
15
15
 
@@ -29,5 +29,9 @@ module TaliaCore
29
29
  assert_equal(['foo', 'bar', '<http:/bingobongo.com>'], @sources.first['http://bongobongo.com'])
30
30
  end
31
31
 
32
+ def test_i18n_value
33
+ assert_equal('en', @sources.first['http://bongobongo.com'].detect { |el| el == 'bar'}.lang)
34
+ end
35
+
32
36
  end
33
37
  end
@@ -155,9 +155,9 @@ module TaliaCore
155
155
 
156
156
  # Direct RDF property
157
157
  def test_rdf_direct_property
158
- @valid_source.default::test_predicate << "moofoo"
159
- assert_equal(@valid_source.default::test_predicate[0], "moofoo")
160
- assert_equal(1, @valid_source.default::test_predicate.size)
158
+ @valid_source.talia::test_predicate << "moofoo"
159
+ assert_equal(@valid_source.talia::test_predicate[0], "moofoo")
160
+ assert_equal(1, @valid_source.talia::test_predicate.size)
161
161
  end
162
162
 
163
163
  # Namespaced RDF property
@@ -173,18 +173,18 @@ module TaliaCore
173
173
 
174
174
  # Relation properties
175
175
  def test_relations
176
- @valid_source.default::rel_it << Source.new("http://foobar.com/")
177
- assert_kind_of(SemanticCollectionWrapper, @valid_source.default::rel_it)
178
- assert_kind_of(Source, @valid_source.default::rel_it[0])
179
- assert_equal("http://foobar.com/", @valid_source.default::rel_it[0].uri.to_s)
176
+ @valid_source.talia::rel_it << Source.new("http://foobar.com/")
177
+ assert_kind_of(SemanticCollectionWrapper, @valid_source.talia::rel_it)
178
+ assert_kind_of(Source, @valid_source.talia::rel_it[0])
179
+ assert_equal("http://foobar.com/", @valid_source.talia::rel_it[0].uri.to_s)
180
180
  end
181
181
 
182
182
  # RDF load and save
183
183
  def test_rdf_save_load
184
- @valid_source.default::hero << "napoleon"
184
+ @valid_source.talia::hero << "napoleon"
185
185
  @valid_source.save
186
186
  loaded = Source.find(@valid_source.uri)
187
- assert_equal("napoleon", loaded.default::hero[0])
187
+ assert_equal("napoleon", loaded.talia::hero[0])
188
188
  end
189
189
 
190
190
  # Test limit
@@ -223,7 +223,7 @@ module TaliaCore
223
223
  source.types << @test_type
224
224
  source.primary_source = false
225
225
  source.save!
226
- source.default::author << "napoleon"
226
+ source.talia::author << "napoleon"
227
227
  source.save!
228
228
  print source.to_xml
229
229
  print source.to_rdf # also check rdf
@@ -232,13 +232,13 @@ module TaliaCore
232
232
  # Test for direct predicates
233
233
  def test_direct_predicates
234
234
  my_source = make_dummy_source("http://direct_predicate_haver/")
235
- my_source.default::author << "napoleon"
235
+ my_source.talia::author << "napoleon"
236
236
  my_source.save!
237
237
 
238
238
  # Expected size of direct predicates: One for the predicate set above,
239
239
  # one for the default type and one for the default type
240
240
  assert_equal(3, my_source.direct_predicates.size, "Direct predicates expected to have 3 elements. Real value: #{my_source.direct_predicates.inspect}")
241
- assert(my_source.direct_predicates.include?(N::DEFAULT::author))
241
+ assert(my_source.direct_predicates.include?(N::TALIA::author))
242
242
  end
243
243
 
244
244
  # Test for inverse predicates
@@ -261,13 +261,13 @@ module TaliaCore
261
261
 
262
262
  def test_grouped_direct_predicates_should_collect_rdf_objects
263
263
  source = make_dummy_source("http://direct_predicate_for_napoleon/")
264
- source.default::historical_character << Source.new("#{N::LOCAL}napoleon")
265
- source.default::historical_character << "Giuseppe Garibaldi"
264
+ source.talia::historical_character << Source.new("#{N::LOCAL}napoleon")
265
+ source.talia::historical_character << "Giuseppe Garibaldi"
266
266
 
267
267
  source.save!
268
268
 
269
- assert_equal(3, source.grouped_direct_predicates.size)
270
- predicates = source.grouped_direct_predicates['default']
269
+ assert_equal(2, source.grouped_direct_predicates.size)
270
+ predicates = source.grouped_direct_predicates['talia']
271
271
  predicates.each do |group, source_list|
272
272
  source_list.flatten.each do |source|
273
273
  assert_kind_of(SourceTransferObject, source)
@@ -278,18 +278,18 @@ module TaliaCore
278
278
 
279
279
  def test_predicate_objects
280
280
  source = make_dummy_source("http://star-wars.org/")
281
- source.default::jedi_knight << Source.new("http://star-wars.org/luke-skywalker")
282
- source.default::jedi_knight << "Obi-Wan Kenobi"
281
+ source.talia::jedi_knight << Source.new("http://star-wars.org/luke-skywalker")
282
+ source.talia::jedi_knight << "Obi-Wan Kenobi"
283
283
 
284
- assert_included source.predicate_objects('default', 'jedi_knight'), "http://star-wars.org/luke-skywalker"
285
- assert_included source.predicate_objects('default', 'jedi_knight'), "Obi-Wan Kenobi"
284
+ assert_included source.predicate_objects('talia', 'jedi_knight'), "http://star-wars.org/luke-skywalker"
285
+ assert_included source.predicate_objects('talia', 'jedi_knight'), "Obi-Wan Kenobi"
286
286
  end
287
287
 
288
288
  def test_associated
289
289
  source = make_dummy_source("http://star-wars.org/")
290
290
  associated_source = Source.new("http://star-wars.org/luke-skywalker")
291
- source.default::jedi_knight << associated_source
292
- assert(source.associated?('default', 'jedi_knight', associated_source.to_s))
291
+ source.talia::jedi_knight << associated_source
292
+ assert(source.associated?('talia', 'jedi_knight', associated_source.to_s))
293
293
  end
294
294
 
295
295
  def test_predicates_attributes_setter
@@ -322,16 +322,6 @@ module TaliaCore
322
322
  assert_equal("http://star-wars.org/obi-wan-kenobi", Source.normalize_uri('http://star-wars.org/obi-wan-kenobi').to_s)
323
323
  end
324
324
 
325
- def test_extract_attributes
326
- source = make_dummy_source("http://star-wars.org/")
327
- attributes, rdf_attributes = source.send(:extract_attributes!, @params)
328
-
329
- assert_equal(%w( uri ), attributes.keys)
330
- rdf_attributes['predicates_attributes'].each do |attributes_hash|
331
- assert_kind_of Hash, attributes_hash
332
- end
333
- end
334
-
335
325
  def test_instantiate_source_or_rdf_object
336
326
  source = make_dummy_source("http://springfield.org/")
337
327
 
@@ -374,6 +364,7 @@ module TaliaCore
374
364
  end
375
365
 
376
366
  # Write an db attribute by symbol
367
+
377
368
  def test_write_access_db_symbol
378
369
  source = Source.new('http://localnode.org/something')
379
370
  source[:uri] = "http://somethingelse.com/"
@@ -35,7 +35,7 @@ module TaliaCore
35
35
  end
36
36
 
37
37
  def test_relation
38
- assert_property(@imported[N::RDF.relatit], DummySource.new('http://localnode.org/as_create_attr_dummy_2'), DummySource.new('http://localnode.org/as_create_attr_dummy_1'))
38
+ assert_property(@imported[N::RDF.relatit], SourceTypes::DummySource.new('http://localnode.org/as_create_attr_dummy_2'), SourceTypes::DummySource.new('http://localnode.org/as_create_attr_dummy_1'))
39
39
  end
40
40
 
41
41
  end
@@ -0,0 +1,44 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ module TaliaCore
4
+ class IoTester
5
+ include TaliaUtil::IoHelper
6
+ end
7
+
8
+ # Test the Generic Xml Import
9
+ class IoHelperTest < Test::Unit::TestCase
10
+
11
+ def setup
12
+ setup_once(:io) { IoTester.new }
13
+ setup_once(:self) { File.expand_path(__FILE__) }
14
+ setup_once(:self_dir) { File.dirname(@self) }
15
+ end
16
+
17
+ def test_file_url
18
+ assert_equal('/test/file', @io.file_url('file:///test/file'))
19
+ end
20
+
21
+ def test_file_url_not
22
+ assert_equal('http://foobar.com', @io.file_url('http://foobar.com'))
23
+ end
24
+
25
+ def test_base_for_file
26
+ assert_equal(@self_dir, @io.base_for(@self))
27
+ end
28
+
29
+ def test_base_for_dir
30
+ assert_equal(@self_dir, @io.base_for(@self_dir))
31
+ end
32
+
33
+ def test_base_for_uri
34
+ assert_equal(URI.parse('http://foobar.com/foodanga/'), @io.base_for('http://foobar.com/foodanga/'))
35
+ end
36
+
37
+ def test_base_for_uri_doc
38
+ assert_equal(URI.parse('http://foobar.com/foodanga/'), @io.base_for('http://foobar.com/foodanga/doc.xml'))
39
+ end
40
+
41
+ # TODO: Actual reader tests missing
42
+
43
+ end
44
+ end