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
@@ -6,16 +6,15 @@ require 'talia_core'
6
6
  require 'talia_util'
7
7
  require 'talia_util/util'
8
8
  require 'rake/testtask'
9
- require 'rake/rdoctask'
10
9
  require 'progressbar'
11
10
 
12
11
  include TaliaUtil
13
12
 
14
13
  namespace :talia_core do
15
-
14
+
16
15
  # Standard initialization
17
16
  desc "Initialize the TaliaCore"
18
- task :talia_init do
17
+ task :init do
19
18
  Util::title
20
19
  Util::init_talia
21
20
  TLoad::force_rails_parts unless(defined?(ActiveRecord))
@@ -25,15 +24,15 @@ namespace :talia_core do
25
24
  model_path = File.join(TALIA_ROOT, 'app', 'models')
26
25
  ActiveSupport::Dependencies.load_paths << model_path if(File.directory?(model_path))
27
26
  end
28
-
27
+
29
28
  # Removes all data
30
29
  desc "Reset the Talia data store"
31
- task :clear_store => :talia_init do
30
+ task :clear_store => :init do
32
31
  Util::flush_db
33
32
  Util::flush_rdf
34
33
  puts "Flushed data store"
35
34
  end
36
-
35
+
37
36
  # Init for the unit tests
38
37
  desc "Initialize Talia for the tests"
39
38
  task :test_setup do
@@ -43,9 +42,9 @@ namespace :talia_core do
43
42
  end
44
43
 
45
44
  # Invoke the init after the setup
46
- Rake::Task["talia_core:talia_init"].invoke
45
+ Rake::Task["talia_core:init"].invoke
47
46
  end
48
-
47
+
49
48
  # Test task
50
49
  desc 'Test the talia_core plugin.'
51
50
  task :test => :test_setup
@@ -56,46 +55,46 @@ namespace :talia_core do
56
55
  t.test_files = FileList["#{File.dirname(__FILE__)}/../../test/**/*_test.rb"]
57
56
  t.verbose = true
58
57
  end
59
-
58
+
60
59
  # Queue an import in the background
61
60
  desc "Xml Background import. Options: [index=<indexfile>] [xml=<datafile>] [importer=<importclass>] [reset_store=true] [...]"
62
61
  task :xml_background_import do
63
62
  background_job('xml_import', :tag => 'import')
64
63
  puts "Queued XML background import."
65
64
  end
66
-
65
+
67
66
  desc "Xml Import. Options: see xml_background_import"
68
- task :xml_import => :talia_init do
67
+ task :xml_import => :init do
69
68
  importer = TaliaUtil::ImportJobHelper.new(STDOUT, TaliaUtil::BarProgressor)
70
69
  importer.do_import
71
70
  end
72
-
71
+
73
72
  # Just run the Talia init to test it
74
73
  desc "Test the TaliaCore startup"
75
- task :init_test => :talia_init do
74
+ task :init_test => :init do
76
75
  Util::talia_config
77
76
  end
78
-
77
+
79
78
  # Task for importing ontologies/raw RDF data
80
79
  desc "Import ontologies. This imports the given rdf files (same as rdf_import), and sets the context automatically"
81
- task :ontology_import => :talia_init do
80
+ task :ontology_import => :init do
82
81
  TaliaCore::RdfImport::import(ENV['rdf_syntax'], TaliaUtil::Util::get_files, :auto)
83
82
  end
84
-
83
+
85
84
  # RDF importing task. A context can be freely assigned.
86
85
  desc "Import RDF data directly into the triple store. Option: rdf_syntax={ntriples|rdfxml} [context=<context>]"
87
- task :rdf_import => :talia_init do
86
+ task :rdf_import => :init do
88
87
  TaliaCore::RdfImport::import(ENV['rdf_syntax'], TaliaUtil::Util::get_files, ENV['context'])
89
88
  end
90
89
 
91
90
  desc "Update the Ontologies. Options [ontologies=<ontology_folder>]"
92
- task :setup_ontologies => :talia_init do
91
+ task :setup_ontologies => :init do
93
92
  Util::setup_ontologies
94
93
  end
95
94
 
96
95
  # Rewrite your base URL. This will loose any comments in the config file
97
96
  desc "Rewrite the database to move it to a new URL. Options new_home=<url>."
98
- task :move_site => :talia_init do
97
+ task :move_site => :init do
99
98
  new_site = ENV['new_home']
100
99
  # Check if this looks like an URL
101
100
  raise(RuntimeError, "Illegal new_home given. (It must start with http(s):// and end with a slash)") unless(new_site =~ /^https?:\/\/\S+\/$/)
@@ -121,56 +120,12 @@ namespace :talia_core do
121
120
  puts "New configuration saved. Finished site rebuilding."
122
121
  end
123
122
 
124
- # Task for importing YAML data into the data store
125
- desc "Import YAML data file in Talia format."
126
- task :yaml_import => :talia_init do
127
- YamlImport::import_multi_files(TaliaUtil::Util::get_files)
128
- end
129
-
130
123
  # Task for updating the OWL classes with RDFS class information
131
124
  desc "Update OWL classes with RDFS class information."
132
- task :owl_to_rdfs_update => :talia_init do
125
+ task :owl_to_rdfs_update => :init do
133
126
  RdfUpdate::owl_to_rdfs
134
127
  end
135
-
136
- # Task to import data files into the Talia system
137
- desc "Import data files. Options data_type=<data_type> replace_files={yes|no}"
138
- task :data_import => :talia_init do
139
- DataImport::import(TaliaUtil::Util::get_files, ENV['data_type'])
140
- end
141
-
142
- # Task to import demo data from a demo directory
143
- desc "Import demo data (for default demo data). Opions: demodir=<dir> [owlify=no]"
144
- task :demo_import do
145
- unless(demodir = ENV['demodir'])
146
- puts "ERROR: Need demodir option for import"
147
- Util::print_options
148
- exit(1)
149
- end
150
-
151
- # Force some options to default
152
- ENV['reset_db'] = "yes" unless(ENV['reset_db'])
153
- ENV['reset_rdf'] = "yes" unless(ENV['reset_rdf'])
154
-
155
- # Invoke the init after the setup
156
- Rake::Task["talia_core:talia_init"].invoke
157
-
158
- puts "Importing ontologies..."
159
- RdfImport::import("rdfxml", FileList.new(File.join(demodir, '*.rdf*'), File.join(demodir, '*.owl')))
160
- puts "Importing data records..."
161
- YamlImport::import_multi_files([File.join(demodir, "demo_data.yml")])
162
- puts "Importing files..."
163
- Dir.foreach(File.join(demodir)) do |entry|
164
- if(FileTest.directory?(File.join(demodir,entry)) && entry != ".." && entry != "." && entry != ".svn")
165
- puts "Importing for type #{entry}"
166
- DataImport::import(FileList.new(File.join(demodir, entry, '*')), entry)
167
- end
168
- end
169
- if(ENV['owlify'].to_s.downcase == 'yes')
170
- RdfUpdate::owl_to_rdfs
171
- end
172
- end
173
-
128
+
174
129
  # Helper task to bootstrap Redland RDF (should usually only be a problem when
175
130
  # using Redland with mysql store)
176
131
  desc "Initialize Redland RDF store. Option: rdfconf=<rdfconfig_file> [environment=env]"
@@ -180,12 +135,12 @@ namespace :talia_core do
180
135
  environment = ENV['environment'] || "development"
181
136
  raise(ArgumentError, "Must have rdfconf=<config_file>") unless(ENV['rdfconf'])
182
137
  options = YAML::load(File.open(ENV['rdfconf']))[environment]
183
-
138
+
184
139
  rdf_cfg = Hash.new
185
140
  options.each { |key, value| rdf_cfg[key.to_sym] = value }
186
-
141
+
187
142
  rdf_cfg[:new] = "yes"
188
-
143
+
189
144
  ConnectionPool.add_data_source(rdf_cfg)
190
145
  end
191
146
 
@@ -198,7 +153,7 @@ namespace :talia_core do
198
153
  end
199
154
 
200
155
  desc "Rebuild the RDF store from the database. Option [hard_reset=(true|false)]"
201
- task :rebuild_rdf => :talia_init do
156
+ task :rebuild_rdf => :init do
202
157
  count = TaliaCore::SemanticRelation.count
203
158
  puts "Rebuilding RDF for #{count} triples."
204
159
  prog = ProgressBar.new('Rebuilding', count)
@@ -206,9 +161,30 @@ namespace :talia_core do
206
161
  prog.finish
207
162
  puts "Finished rewriting. ATTENTION: You may want to call setup_ontologies now."
208
163
  end
209
-
164
+
165
+ desc "Generate large database for load tests. [count=<number of sources>]"
166
+ task :generate_large_data => :init do
167
+ count = (ENV['count'] || '10000').to_i
168
+ prog = ProgressBar.new('Creating', count)
169
+ (1..count).each do |idx|
170
+ src = TaliaCore::ActiveSource.new(:uri => N::LOCAL + "large_sample_#{idx}")
171
+ if(idx > 1)
172
+ # For now an easy approach: Each source has 10 connections to the previous
173
+ # one.
174
+ prev = TaliaCore::ActiveSource.find(N::LOCAL + "large_sample_#{idx - 1}")
175
+ (1..10).each do |rel_idx|
176
+ src[N::RDF + "dummy_rel_#{rel_idx}"] << prev
177
+ src[N::RDFS + "dummy_prop_#{rel_idx}"] << 'Some property'
178
+ end
179
+ end
180
+ src.save!
181
+ prog.inc
182
+ end
183
+ prog.finish
184
+ end
185
+
210
186
  # Helper methods
211
-
187
+
212
188
  # Queue the long-running task in the background processing queue.
213
189
  # This will simply queue the job, and doesn't start the runner
214
190
  # by itself
@@ -219,5 +195,5 @@ namespace :talia_core do
219
195
  options[:no_tickle] = true
220
196
  TaliaCore::BackgroundJobs::Job.submit_with_progress(job, options)
221
197
  end
222
-
198
+
223
199
  end
@@ -38,29 +38,38 @@ module TaliaUtil
38
38
  # Remove previous auto rdfs triples
39
39
  FederationManager.clear(N::TALIA.auto_rdfs.context)
40
40
 
41
- # Get all OWL classes
42
- qry = Query.new(N::URI).distinct.select(:klass, :type)
43
- qry.where(:klass, N::RDF::type, N::OWL + 'Class')
44
- qry.where(:klass, N::RDF::type, :type)
45
- classes_with_types = qry.execute
41
+ # This gets all OWL classes in the store
42
+ all_qry = Query.new(N::URI).distinct.select(:class)
43
+ all_qry.where(:class, N::RDF::type, N::OWL.Class)
44
+ all_owl = all_qry.execute
45
+
46
+ # This gets all OWL classes that already have an RDF class attached
47
+ qry_rdfs = Query.new(N::URI).distinct.select(:class)
48
+ qry_rdfs.where(:class, N::RDF::type, N::OWL.Class)
49
+ qry_rdfs.where(:class, N::RDF::type, N::RDFS.Class)
50
+ classes_with_rdfs = qry_rdfs.execute
51
+
52
+
46
53
  modified = 0
47
54
  blanks = 0
48
55
 
49
56
  class_hash = {}
50
57
 
51
- # We have a list of all combinations of klass elements with their types
52
- # The next step is to find all things where a RDFS.Class type already
53
- # exists
54
- classes_with_types.each do |class_with_type|
55
- if(class_with_type.first.is_a?(RDFS::BNode))
58
+ # Put all the existing owl classes in a hash
59
+ all_owl.each do |owl_class|
60
+ if(owl_class.is_a?(RDFS::BNode))
56
61
  blanks = blanks + 1
57
62
  next
58
63
  end
59
64
 
60
- klass, type = class_with_type
65
+ class_hash[owl_class] = :has_rdfs_class
66
+ end
67
+
68
+ # Now remove the ones that already have an RDF class
69
+ classes_with_rdfs.each do |owl_class|
70
+ next if(owl_class.is_a?(RDFS::BNode))
61
71
 
62
- class_hash[klass.to_s] ||= :no_rdfs_class
63
- class_hash[klass.to_s] = :has_rdfs_class if(type == N::RDFS.Class)
72
+ class_hash[owl_class] = :no_rdfs_class
64
73
  end
65
74
 
66
75
  # Now go through all klasses and add the missing triples
@@ -20,7 +20,7 @@ module TaliaUtil
20
20
  # Source given by the URI.
21
21
  def assert_property(property, *values)
22
22
  assert_kind_of(TaliaCore::SemanticCollectionWrapper, property) # Just to be sure
23
- assert_equal(values.size, property.size, "Expected #{values.size} values instead of #{property.size}")
23
+ assert_equal(values.size, property.size, "Expected #{values.size} values instead of #{property.size}.")
24
24
  property.each do |value|
25
25
  assert(values.detect { |val| val.respond_to?(:uri) ? (val.uri.to_s == value.uri.to_s) : (value == val) }, "Found unexpected value #{value}. Value is a #{value.class}\nExpected:\n#{values.join("\n")}")
26
26
  end
data/lib/talia_util.rb CHANGED
@@ -2,9 +2,7 @@
2
2
  require File.join(File.dirname(__FILE__), 'talia_dependencies')
3
3
 
4
4
  require 'core_ext'
5
- require 'talia_util/data_import'
6
5
  require 'talia_core/rdf_import'
7
- require 'talia_util/yaml_import'
8
6
  require 'talia_util/rdf_update'
9
7
  require 'talia_util/progressbar'
10
8
 
@@ -8,4 +8,9 @@ class StringTest < Test::Unit::TestCase
8
8
  assert_equal('Should_Titleize_Mixed_Case_Strings', 'sHoULD tItLEIzE mIxEd cAsE sTrINgS'.to_permalink)
9
9
  assert_equal('Should_Replace_Spaces_With_Underscores', 'should replace spaces with underscores'.to_permalink)
10
10
  end
11
+
12
+ def test_to_uri
13
+ assert_equal(N::URI.new('http://foo-foo.com'), 'http://foo-foo.com'.to_uri)
14
+ assert_kind_of(N::URI, 'foo-foo.com'.to_uri)
15
+ end
11
16
  end
@@ -12,6 +12,10 @@ module TaliaCore
12
12
  fixtures :active_sources, :semantic_properties, :semantic_relations, :data_records
13
13
 
14
14
  N::Namespace.shortcut(:as_test_preds, 'http://testvalue.org/')
15
+
16
+ def setup
17
+ setup_once(:test_file) { File.join(ActiveSupport::TestCase.fixture_path, 'generic_test.xml') }
18
+ end
15
19
 
16
20
  def test_has_type
17
21
  src = ActiveSource.new('http://xsource/has_type_test')
@@ -20,8 +24,8 @@ module TaliaCore
20
24
  end
21
25
 
22
26
  def test_type_field
23
- src = DummySource.new('http://xsource/has_type_test')
24
- assert_equal(src.type, 'TaliaCore::DummySource')
27
+ src = SourceTypes::DummySource.new('http://xsource/has_type_test')
28
+ assert_equal(src.type, 'TaliaCore::SourceTypes::DummySource')
25
29
  end
26
30
 
27
31
  def test_exists
@@ -207,11 +211,71 @@ module TaliaCore
207
211
  assert_equal(4, preds.size)
208
212
  assert(preds.include?('http://testvalue.org/pred_b'), "#{preds} does not include the expected value")
209
213
  end
214
+
215
+ def test_i18n_predicates
216
+ src = active_sources(:i18n_test)
217
+ assert_property(src.predicate(:as_test_preds, :i18n), 'value', 'wert')
218
+ end
219
+
220
+ def test_values_with_lang
221
+ src = active_sources(:i18n_test)
222
+ assert_equal(src.predicate(:as_test_preds, :i18n).values_with_lang('de'), ['wert'])
223
+ assert_equal(src.predicate(:as_test_preds, :i18n).values_with_lang('en'), ['value'])
224
+ end
225
+
226
+ def test_values_with_lang_fallback
227
+ src = active_sources(:i18n_test)
228
+ assert_equal(src.predicate(:as_test_preds, :i18n).values_with_lang('ar'), ['value'])
229
+ end
230
+
231
+ def test_values_with_lang_fallback_unset
232
+ src_preds = active_sources(:testy).predicate(:as_test_preds, :the_rel1)
233
+ assert_equal(src_preds.values_with_lang('de'), ['The test value'])
234
+ assert_equal(src_preds.values_with_lang('en'), ['The test value'])
235
+ end
236
+
237
+ def test_property_string_values
238
+ src = active_sources(:i18n_test)
239
+ pred = src.predicate(:as_test_preds, :i18n).first
240
+ assert_kind_of(PropertyString, pred)
241
+ assert(!pred.lang.blank?)
242
+ end
243
+
244
+ def test_property_string_adding
245
+ src = TaliaCore::ActiveSource.new('http://testy.org/do_the_property_string')
246
+ src[N::RDF.testpred] << PropertyString.new('value', 'en', 'string')
247
+ assert(src[N::RDF.testpred].first.lang, 'en')
248
+ src.save!
249
+ src_new = TaliaCore::ActiveSource.find(src.uri)
250
+ assert_property(src_new[N::RDF.testpred], 'value')
251
+ pred = src_new[N::RDF.testpred].first
252
+ assert_equal(pred.lang, 'en')
253
+ assert_equal(pred.type, 'string')
254
+ end
210
255
 
211
- def tes_predicates_prefetch
256
+ def test_predicates_prefetch
212
257
  uri = active_sources(:testy)
213
258
  src = TaliaCore::ActiveSource.find(uri, :prefetch_relations => true)
214
- assert_equal('The test value', src.predicate(:as_test_preds, :the_rel1)[0])
259
+ assert_equal(true, src.instance_variable_get(:@prefetched))
260
+ type_cache = src.instance_variable_get(:@type_cache)
261
+ assert_equal('The test value', type_cache[N::AS_TEST_PREDS.the_rel1.to_s].first)
262
+ end
263
+
264
+ def test_prefetch_finder
265
+ srcs = TaliaCore::ActiveSource.find(:all, :prefetch_relations => true)
266
+ src = srcs.detect { |s| s.uri.to_s == 'http://testy.com/testme/hard'}
267
+ assert(src)
268
+ assert_equal(true, src.instance_variable_get(:@prefetched))
269
+ type_cache = src.instance_variable_get(:@type_cache)
270
+ assert(type_cache)
271
+ assert_equal('The test value', type_cache[N::AS_TEST_PREDS.the_rel1.to_s].first)
272
+ assert_equal('The test value', src.predicate(:as_test_preds, :the_rel1).first)
273
+ end
274
+
275
+ def test_prefetch_count
276
+ count = TaliaCore::ActiveSource.count(:prefetch_relations => true)
277
+ real_count = TaliaCore::ActiveSource.count
278
+ assert_equal(count, real_count)
215
279
  end
216
280
 
217
281
  def test_inverse_predicates
@@ -308,6 +372,11 @@ module TaliaCore
308
372
  assert_equal(active_sources(:find_through_test), result[0])
309
373
  end
310
374
 
375
+ def test_count_through
376
+ result = ActiveSource.count(:find_through => ['http://testvalue.org/pred_find_through', active_sources(:find_through_target).uri])
377
+ assert_equal(1, result)
378
+ end
379
+
311
380
  def test_find_through_props
312
381
  result = ActiveSource.find(:all, :find_through => ['http://testvalue.org/pred_find_through', 'the_value'])
313
382
  assert_equal(1, result.size)
@@ -446,6 +515,13 @@ module TaliaCore
446
515
  assert(!ActiveSource.db_attr?('http://www.foobar.org/'))
447
516
  end
448
517
 
518
+ def test_db_id
519
+ assert(ActiveSource.db_attr?(:id))
520
+ assert(ActiveSource.db_attr?('id'))
521
+ assert_equal(active_sources(:testy)['id'], active_sources(:testy)[:id])
522
+ assert_equal(active_sources(:testy)['id'], active_sources(:testy).id)
523
+ end
524
+
449
525
  def test_expand_uri
450
526
  assert_equal(N::LOCAL.foo.to_s, ActiveSource.expand_uri(':foo'))
451
527
  assert_equal(N::LOCAL.foo.to_s, ActiveSource.expand_uri('foo'))
@@ -459,7 +535,7 @@ module TaliaCore
459
535
  src.save!
460
536
  src.update_attributes(:uri => 'http://as_test/test_update_attributes_on_2', 'rdf:foo' => 'value', N::LOCAL.relatit.to_s => "<#{N::LOCAL + 'attr_on_save_test_dummy'}>" )
461
537
  src = ActiveSource.find('http://as_test/test_update_attributes_on_2')
462
- assert_kind_of(DummySource, src[N::LOCAL.relatit].first)
538
+ assert_kind_of(SourceTypes::DummySource, src[N::LOCAL.relatit].first)
463
539
  assert_equal(N::LOCAL + 'attr_on_save_test_dummy', src[N::LOCAL.relatit].first.uri)
464
540
  assert_equal('value', src[N::RDF.foo].first)
465
541
  end
@@ -521,6 +597,11 @@ module TaliaCore
521
597
  assert_property(src[N::RDF.relatit], N::LOCAL.as_create_attr_dummy_1, N::LOCAL.as_create_attr_dummy_1)
522
598
  end
523
599
 
600
+ def test_create_with_attributes_plain_uri
601
+ src = ActiveSource.new(:uri => 'test_create_with_attributes_plain_uri')
602
+ assert_equal(N::LOCAL.test_create_with_attributes_plain_uri, src.uri)
603
+ end
604
+
524
605
  def test_create_source
525
606
  src = ActiveSource.create_source(:uri => 'http://as_test/create_with_type', ':localthi' => 'value', 'rdf:relatit' => ["<:as_create_attr_dummy_1>", "<:as_create_attr_dummy_1>"], 'type' => 'TaliaCore::SingularAccessorTest')
526
607
  assert_kind_of(SingularAccessorTest, src)
@@ -536,7 +617,7 @@ module TaliaCore
536
617
  xml = src.to_xml
537
618
  # Quickly change something inside, but leave the URL
538
619
  xml.gsub!('valueFOOOO', 'valorz')
539
- new_src = ActiveSource.create_from_xml(xml)
620
+ new_src = ActiveSource.create_from_xml(xml, 'duplicates' => 'update')
540
621
  # Now test as above
541
622
  assert_equal(src.uri.to_s, new_src.uri.to_s)
542
623
  assert_equal('valorz', new_src[N::LOCAL.localthi].first)
@@ -549,7 +630,7 @@ module TaliaCore
549
630
  { :uri => N::LOCAL.test_create_multi_stuff, 'rdf:relatit' => [ "<#{N::LOCAL.test_create_multi_stuff_two}>" ], 'type' => 'TaliaCore::SingularAccessorTest' },
550
631
  { :uri => N::LOCAL.test_create_multi_stuff_two, ':localthi' => 'valueFOOOO', 'rdf:relatit' => ["<#{N::LOCAL.test_create_multi_stuff}>"], 'type' => 'TaliaCore::SingularAccessorTest' }
551
632
  ]
552
- ActiveSource.create_multi_from(src_attribs)
633
+ ActiveSource.create_multi_from(src_attribs, :duplicates => :update)
553
634
  src = TaliaCore::ActiveSource.find(N::LOCAL.test_create_multi_stuff)
554
635
  src_two = TaliaCore::ActiveSource.find(N::LOCAL.test_create_multi_stuff_two)
555
636
  assert(src && src_two)
@@ -562,13 +643,16 @@ module TaliaCore
562
643
 
563
644
 
564
645
  def test_xml_forth_and_back
565
- src = ActiveSource.create_source(:uri => 'http://as_test/create_forth_and_back', ':localthi' => 'value', 'rdf:relatit' => ["<:as_create_attr_dummy_1>", "<:as_create_attr_dummy_1>"], 'type' => 'TaliaCore::DummySource')
646
+ src = ActiveSource.create_source(:uri => 'http://as_test/create_forth_and_back', ':localthi' => 'value', 'rdf:relatit' => ["<:as_create_attr_dummy_1>", "<:as_create_attr_dummy_1>"], 'type' => 'TaliaCore::SourceTypes::DummySource')
566
647
  xml = src.to_xml
567
- assert_kind_of(TaliaCore::DummySource, src)
648
+ assert_kind_of(TaliaCore::SourceTypes::DummySource, src)
568
649
  # Quickly change the URI for the new thing
569
650
  xml.gsub!(src.uri.to_s, 'http://as_test/create_forth_and_forth')
651
+ # this is for the type attribute in the xml
652
+ xml.gsub!('SourceTypes::DummySource', 'SingularAccessorTest')
653
+ # The next is for the 'type' semantic triple already existing
570
654
  xml.gsub!('DummySource', 'SingularAccessorTest')
571
- new_src = ActiveSource.create_from_xml(xml)
655
+ new_src = ActiveSource.create_from_xml(xml, :duplicates => :update)
572
656
  assert_kind_of(TaliaCore::SingularAccessorTest, new_src)
573
657
  # Now test as above
574
658
  assert_equal('http://as_test/create_forth_and_forth', new_src.uri.to_s)
@@ -578,13 +662,12 @@ module TaliaCore
578
662
  end
579
663
 
580
664
  def test_create_with_file
581
- test_file = File.join(ActiveSupport::TestCase.fixture_path, 'generic_test.xml')
582
- src = ActiveSource.create_source(:uri => 'http://as_test/create_with_file', 'type' => 'TaliaCore::Source', 'files' => {'url' => test_file })
665
+ src = ActiveSource.create_source(:uri => 'http://as_test/create_with_file', 'type' => 'TaliaCore::Source', 'files' => {'url' => @test_file })
583
666
  assert_equal(1, src.data_records.size)
584
667
  src.save!
585
668
  assert(!src.data_records.first.new_record?)
586
669
  assert_kind_of(DataTypes::XmlData, src.data_records.first)
587
- File.open(test_file) do |io|
670
+ File.open(@test_file) do |io|
588
671
  assert_equal(src.data_records.first.all_text, io.read)
589
672
  end
590
673
  end
@@ -615,7 +698,61 @@ module TaliaCore
615
698
  assert_equal(0, data.size)
616
699
  data = data_source.data("SimpleText", "noop.txt")
617
700
  assert_nil(data)
618
- end
701
+ end
702
+
703
+ def test_update_source_skip
704
+ src = ActiveSource.create_source(:uri => 'http://as_test/update_source_skip', ':localthi' => 'value', 'rdf:somethi' => 'value2', 'type' => 'TaliaCore::Source', 'files' => {'url' => @test_file })
705
+ src.save!
706
+ src.update_source({ ':localthi' => ['value2', 'value3'] }, :skip)
707
+ assert_property(src[N::LOCAL.localthi], 'value')
708
+ assert_property(src[N::RDF.somethi], 'value2')
709
+ assert_equal(1, src.data_records.size)
710
+ end
711
+
712
+ def test_update_source_skip_dummy
713
+ src = ActiveSource.create_source(:uri => 'http://as_test/update_source_skip_dummy', ':localthi' => 'value', 'rdf:somethi' => 'value2', 'type' => 'TaliaCore::SourceTypes::DummySource')
714
+ src.save!
715
+ assert_kind_of(SourceTypes::DummySource, src)
716
+ src.update_source({ ':localthi' => ['value2', 'value3'] }, :skip)
717
+ assert_property(src[N::LOCAL.localthi], 'value2', 'value3')
718
+ assert_property(src[N::RDF.somethi], 'value2')
719
+ end
720
+
721
+ def test_update_source_overwrite
722
+ src = ActiveSource.create_source(:uri => 'http://as_test/update_source_overwrite', ':localthi' => 'value', 'rdf:somethi' => 'value2', 'type' => 'TaliaCore::Source', 'files' => {'url' => @test_file })
723
+ src.save!
724
+ new_file = File.join(ActiveSupport::TestCase.fixture_path, 'tiny.jpg')
725
+ src.update_source({ ':localthi' => ['value2', 'value3'] }, :overwrite)
726
+ assert_property(src[N::LOCAL.localthi], 'value2', 'value3')
727
+ assert_property(src[N::RDF.somethi])
728
+ assert_equal(0, src.data_records.size)
729
+ end
730
+
731
+ def test_update_source_update
732
+ src = ActiveSource.create_source(:uri => 'http://as_test/update_source_update', ':localthi' => 'value', 'rdf:somethi' => 'value2', 'type' => 'TaliaCore::Source', 'files' => {'url' => @test_file })
733
+ src.save!
734
+ new_file = File.join(ActiveSupport::TestCase.fixture_path, 'tiny.jpg')
735
+ src.update_source({ ':localthi' => ['value2', 'value3'], 'files' => {'url' => new_file } }, :update)
736
+ assert_property(src[N::LOCAL.localthi], 'value2', 'value3')
737
+ assert_property(src[N::RDF.somethi], 'value2')
738
+ assert_kind_of(DataTypes::IipData, src.data_records.first)
739
+ end
740
+
741
+ def test_update_source_add
742
+ src = ActiveSource.create_source(:uri => 'http://as_test/update_source_add', ':localthi' => 'value', 'rdf:somethi' => 'value2', 'type' => 'TaliaCore::Source', 'files' => {'url' => @test_file })
743
+ src.save!
744
+ new_file = File.join(ActiveSupport::TestCase.fixture_path, 'tiny.jpg')
745
+ src.update_source({ ':localthi' => ['value2', 'value3'], 'files' => {'url' => new_file } }, :add)
746
+ assert_property(src[N::LOCAL.localthi], 'value', 'value2', 'value3')
747
+ assert_property(src[N::RDF.somethi], 'value2')
748
+ # Expect 2 records: The original, the iip image and the orig_image
749
+ assert_equal(3, src.data_records.size)
750
+ end
751
+
752
+ def test_to_uri
753
+ src = ActiveSource.new('http://xsource/has_type_test')
754
+ assert_equal(N::URI.new('http://xsource/has_type_test'), src.to_uri)
755
+ end
619
756
 
620
757
  private
621
758
 
@@ -36,10 +36,11 @@ module TaliaCore
36
36
  setup_once(:test_xml) do
37
37
  File.open(TestHelper.fixture_file('generic_test.xml')) { |io| io.read }
38
38
  end
39
+
39
40
  setup_once(:imported) do
40
- import = GenericImporterTest.sources_from(@test_xml)
41
- import
41
+ GenericImporterTest.sources_from(@test_xml)
42
42
  end
43
+
43
44
  setup_once(:sources) do
44
45
  sources = {}
45
46
  @imported.each do |el|
@@ -48,6 +49,17 @@ module TaliaCore
48
49
  end
49
50
  sources
50
51
  end
52
+
53
+ setup_once(:reader_fs) do
54
+ GenericImporterTest.new(@test_xml)
55
+ end
56
+
57
+ setup_once(:reader_net) do
58
+ reader = GenericImporterTest.new(@test_xml)
59
+ reader.base_file_url = 'http://www.talia.org/foobar/moff'
60
+ reader
61
+ end
62
+
51
63
  # setup_once(:source_objects) do
52
64
  # ActiveSource.create_from_xml(@test_xml, "TaliaCore::GenericImporterTest")
53
65
  # end
@@ -75,6 +87,38 @@ module TaliaCore
75
87
  assert_equal(['<http://www.otherfoo.com/>'], @sources['http://first_sub/Y'][N::TALIA.part_of.to_s])
76
88
  end
77
89
 
90
+ def test_absolute_url_absolute
91
+ assert_equal('/file', @reader_fs.send(:get_absolute_file_url, '/file'))
92
+ end
93
+
94
+ def test_absolute_url_relative
95
+ assert_equal(File.join(TALIA_ROOT, 'file'), @reader_fs.send(:get_absolute_file_url, 'file'))
96
+ end
97
+
98
+ def test_absolute_net_url_on_fs
99
+ assert_equal('http://foobar.com/', @reader_fs.send(:get_absolute_file_url, 'http://foobar.com/'))
100
+ end
101
+
102
+ def test_absolute_net_url
103
+ assert_equal('http://foobar.com/', @reader_net.send(:get_absolute_file_url, 'http://foobar.com/'))
104
+ end
105
+
106
+ def test_relative_net_path
107
+ assert_equal('http://www.talia.org/foobar/file', @reader_net.send(:get_absolute_file_url, 'file'))
108
+ end
109
+
110
+ def test_absolute_net_path
111
+ assert_equal('http://www.talia.org/file', @reader_net.send(:get_absolute_file_url, '/file'))
112
+ end
113
+
114
+ def test_file_url_on_net_absolute
115
+ assert_equal('/test/file', @reader_net.send(:get_absolute_file_url, 'file:///test/file'))
116
+ end
117
+
118
+ def test_file_url_on_net_relative
119
+ assert_equal('test/file', @reader_net.send(:get_absolute_file_url, 'file://test/file'))
120
+ end
121
+
78
122
  # def test_create
79
123
  # assert(@source_objects)
80
124
  # end
@@ -19,7 +19,6 @@ module TaliaCore
19
19
  # Test namespaces
20
20
  def test_namespaces
21
21
  assert(N::LOCAL.to_s, "http://localnode.org/")
22
- assert_equal(N::DEFAULT.to_s, "http://default.talia.eu/")
23
22
  assert_equal(N::FOO.to_s, "http://foo.com/")
24
23
  assert_kind_of(N::Namespace, N::FOO)
25
24
  end