talia_core 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. data/README.rdoc +41 -0
  2. data/bin/talia +33 -0
  3. data/lib/JXslt/jxslt.rb +60 -0
  4. data/lib/acts_as_roled.rb +11 -0
  5. data/lib/core_ext/platform.rb +9 -0
  6. data/lib/core_ext/string.rb +6 -0
  7. data/lib/core_ext.rb +1 -0
  8. data/lib/custom_template.rb +4 -0
  9. data/lib/loader_helper.rb +62 -0
  10. data/lib/mysql.rb +1214 -0
  11. data/lib/progressbar.rb +236 -0
  12. data/lib/role.rb +12 -0
  13. data/lib/talia_cl/command_line.rb +39 -0
  14. data/lib/talia_cl/commands/standalone/cl_options.rb +9 -0
  15. data/lib/talia_cl/commands/standalone/standalone_generate.rb +75 -0
  16. data/lib/talia_cl/commands/standalone.rb +25 -0
  17. data/lib/talia_cl/commands/talia_console/cl_options.rb +55 -0
  18. data/lib/talia_cl/commands/talia_console/console_commands.rb +37 -0
  19. data/lib/talia_cl/commands/talia_console/talia_commands.rb +131 -0
  20. data/lib/talia_cl/commands/talia_console.rb +47 -0
  21. data/lib/talia_cl/core_commands.rb +11 -0
  22. data/lib/talia_cl.rb +47 -0
  23. data/lib/talia_core/active_source.rb +372 -0
  24. data/lib/talia_core/active_source_parts/class_methods.rb +378 -0
  25. data/lib/talia_core/active_source_parts/predicate_handler.rb +89 -0
  26. data/lib/talia_core/active_source_parts/rdf.rb +131 -0
  27. data/lib/talia_core/active_source_parts/sql_helper.rb +36 -0
  28. data/lib/talia_core/active_source_parts/xml/base_builder.rb +47 -0
  29. data/lib/talia_core/active_source_parts/xml/generic_reader.rb +363 -0
  30. data/lib/talia_core/active_source_parts/xml/rdf_builder.rb +88 -0
  31. data/lib/talia_core/active_source_parts/xml/source_builder.rb +73 -0
  32. data/lib/talia_core/active_source_parts/xml/source_reader.rb +20 -0
  33. data/lib/talia_core/agent.rb +14 -0
  34. data/lib/talia_core/background_jobs/job.rb +82 -0
  35. data/lib/talia_core/background_jobs/progress_job.rb +68 -0
  36. data/lib/talia_core/collection.rb +13 -0
  37. data/lib/talia_core/data_types/data_loader.rb +92 -0
  38. data/lib/talia_core/data_types/data_record.rb +105 -0
  39. data/lib/talia_core/data_types/delayed_copier.rb +76 -0
  40. data/lib/talia_core/data_types/file_record.rb +59 -0
  41. data/lib/talia_core/data_types/file_store.rb +306 -0
  42. data/lib/talia_core/data_types/iip_data.rb +153 -0
  43. data/lib/talia_core/data_types/iip_loader.rb +127 -0
  44. data/lib/talia_core/data_types/image_data.rb +32 -0
  45. data/lib/talia_core/data_types/media_link.rb +19 -0
  46. data/lib/talia_core/data_types/mime_mapping.rb +45 -0
  47. data/lib/talia_core/data_types/path_helpers.rb +77 -0
  48. data/lib/talia_core/data_types/pdf_data.rb +42 -0
  49. data/lib/talia_core/data_types/simple_text.rb +36 -0
  50. data/lib/talia_core/data_types/temp_file_handling.rb +85 -0
  51. data/lib/talia_core/data_types/xml_data.rb +169 -0
  52. data/lib/talia_core/dc_resource.rb +20 -0
  53. data/lib/talia_core/dummy_handler.rb +34 -0
  54. data/lib/talia_core/dummy_source.rb +20 -0
  55. data/lib/talia_core/errors.rb +25 -0
  56. data/lib/talia_core/initializer.rb +427 -0
  57. data/lib/talia_core/ordered_source.rb +228 -0
  58. data/lib/talia_core/rails_ext/actionpack/action_controller/record_identifier.rb +13 -0
  59. data/lib/talia_core/rails_ext/actionpack/action_controller.rb +1 -0
  60. data/lib/talia_core/rails_ext/actionpack.rb +1 -0
  61. data/lib/talia_core/rails_ext.rb +1 -0
  62. data/lib/talia_core/rdf_import.rb +90 -0
  63. data/lib/talia_core/rdf_resource.rb +159 -0
  64. data/lib/talia_core/semantic_collection_item.rb +93 -0
  65. data/lib/talia_core/semantic_collection_wrapper.rb +324 -0
  66. data/lib/talia_core/semantic_property.rb +7 -0
  67. data/lib/talia_core/semantic_relation.rb +67 -0
  68. data/lib/talia_core/source.rb +323 -0
  69. data/lib/talia_core/source_transfer_object.rb +38 -0
  70. data/lib/talia_core/workflow/base.rb +15 -0
  71. data/lib/talia_core/workflow/publication_workflow.rb +62 -0
  72. data/lib/talia_core/workflow.rb +300 -0
  73. data/lib/talia_core.rb +9 -0
  74. data/lib/talia_dependencies.rb +12 -0
  75. data/lib/talia_util/bar_progressor.rb +15 -0
  76. data/lib/talia_util/configuration/config_file.rb +48 -0
  77. data/lib/talia_util/configuration/database_config.rb +40 -0
  78. data/lib/talia_util/configuration/mysql_database_setup.rb +104 -0
  79. data/lib/talia_util/data_import.rb +91 -0
  80. data/lib/talia_util/image_conversions.rb +82 -0
  81. data/lib/talia_util/import_job_helper.rb +132 -0
  82. data/lib/talia_util/io_helper.rb +54 -0
  83. data/lib/talia_util/progressable.rb +38 -0
  84. data/lib/talia_util/progressbar.rb +236 -0
  85. data/lib/talia_util/rdf_update.rb +80 -0
  86. data/lib/talia_util/some_sigla.xml +1960 -0
  87. data/lib/talia_util/test_helpers.rb +151 -0
  88. data/lib/talia_util/util.rb +226 -0
  89. data/lib/talia_util/yaml_import.rb +80 -0
  90. data/lib/talia_util.rb +13 -0
  91. data/lib/user.rb +116 -0
  92. data/lib/version.rb +15 -0
  93. data/test/core_ext/string_test.rb +11 -0
  94. data/test/custom_template_test.rb +8 -0
  95. data/test/talia_core/active_source_predicate_test.rb +54 -0
  96. data/test/talia_core/active_source_rdf_test.rb +89 -0
  97. data/test/talia_core/active_source_test.rb +631 -0
  98. data/test/talia_core/data_types/data_loader_test.rb +123 -0
  99. data/test/talia_core/data_types/data_record_test.rb +40 -0
  100. data/test/talia_core/data_types/file_record_test.rb +171 -0
  101. data/test/talia_core/data_types/iip_data_test.rb +130 -0
  102. data/test/talia_core/data_types/image_data_test.rb +88 -0
  103. data/test/talia_core/data_types/pdf_data_test.rb +68 -0
  104. data/test/talia_core/data_types/xml_data_test.rb +134 -0
  105. data/test/talia_core/generic_xml_test.rb +83 -0
  106. data/test/talia_core/initializer_test.rb +36 -0
  107. data/test/talia_core/ordered_source_test.rb +398 -0
  108. data/test/talia_core/rdf_resource_test.rb +115 -0
  109. data/test/talia_core/semantic_collection_item_test.rb +129 -0
  110. data/test/talia_core/source_reader_test.rb +33 -0
  111. data/test/talia_core/source_test.rb +484 -0
  112. data/test/talia_core/source_transfer_object_test.rb +24 -0
  113. data/test/talia_core/workflow/publication_workflow_test.rb +242 -0
  114. data/test/talia_core/workflow/user_class_for_workflow.rb +35 -0
  115. data/test/talia_core/workflow/workflow_base_test.rb +21 -0
  116. data/test/talia_core/workflow_test.rb +19 -0
  117. data/test/talia_util/import_job_helper_test.rb +46 -0
  118. data/test/test_helper.rb +68 -0
  119. metadata +262 -0
@@ -0,0 +1,236 @@
1
+ #
2
+ # Ruby/ProgressBar - a text progress bar library
3
+ #
4
+ # Copyright (C) 2001-2005 Satoru Takabayashi <satoru@namazu.org>
5
+ # All rights reserved.
6
+ # This is free software with ABSOLUTELY NO WARRANTY.
7
+ #
8
+ # You can redistribute it and/or modify it under the terms
9
+ # of Ruby's license.
10
+ #
11
+
12
+ class ProgressBar
13
+ VERSION = "0.9"
14
+
15
+ def initialize (title, total, out = STDERR)
16
+ @title = title
17
+ @total = total
18
+ @out = out
19
+ @terminal_width = 80
20
+ @bar_mark = "o"
21
+ @current = 0
22
+ @previous = 0
23
+ @finished_p = false
24
+ @start_time = Time.now
25
+ @previous_time = @start_time
26
+ @title_width = 14
27
+ @format = "%-#{@title_width}s %3d%% %s %s"
28
+ @format_arguments = [:title, :percentage, :bar, :stat]
29
+ clear
30
+ show
31
+ end
32
+ attr_reader :title
33
+ attr_reader :current
34
+ attr_reader :total
35
+ attr_accessor :start_time
36
+
37
+ private
38
+ def fmt_bar
39
+ bar_width = do_percentage * @terminal_width / 100
40
+ sprintf("|%s%s|",
41
+ @bar_mark * bar_width,
42
+ " " * (@terminal_width - bar_width))
43
+ end
44
+
45
+ def fmt_percentage
46
+ do_percentage
47
+ end
48
+
49
+ def fmt_stat
50
+ if @finished_p then elapsed else eta end
51
+ end
52
+
53
+ def fmt_stat_for_file_transfer
54
+ if @finished_p then
55
+ sprintf("%s %s %s", bytes, transfer_rate, elapsed)
56
+ else
57
+ sprintf("%s %s %s", bytes, transfer_rate, eta)
58
+ end
59
+ end
60
+
61
+ def fmt_title
62
+ @title[0,(@title_width - 1)] + ":"
63
+ end
64
+
65
+ def convert_bytes (bytes)
66
+ if bytes < 1024
67
+ sprintf("%6dB", bytes)
68
+ elsif bytes < 1024 * 1000 # 1000kb
69
+ sprintf("%5.1fKB", bytes.to_f / 1024)
70
+ elsif bytes < 1024 * 1024 * 1000 # 1000mb
71
+ sprintf("%5.1fMB", bytes.to_f / 1024 / 1024)
72
+ else
73
+ sprintf("%5.1fGB", bytes.to_f / 1024 / 1024 / 1024)
74
+ end
75
+ end
76
+
77
+ def transfer_rate
78
+ bytes_per_second = @current.to_f / (Time.now - @start_time)
79
+ sprintf("%s/s", convert_bytes(bytes_per_second))
80
+ end
81
+
82
+ def bytes
83
+ convert_bytes(@current)
84
+ end
85
+
86
+ def format_time (t)
87
+ t = t.to_i
88
+ sec = t % 60
89
+ min = (t / 60) % 60
90
+ hour = t / 3600
91
+ sprintf("%02d:%02d:%02d", hour, min, sec);
92
+ end
93
+
94
+ # ETA stands for Estimated Time of Arrival.
95
+ def eta
96
+ if @current == 0
97
+ "ETA: --:--:--"
98
+ else
99
+ elapsed = Time.now - @start_time
100
+ eta = elapsed * @total / @current - elapsed;
101
+ sprintf("ETA: %s", format_time(eta))
102
+ end
103
+ end
104
+
105
+ def elapsed
106
+ elapsed = Time.now - @start_time
107
+ sprintf("Time: %s", format_time(elapsed))
108
+ end
109
+
110
+ def eol
111
+ if @finished_p then "\n" else "\r" end
112
+ end
113
+
114
+ def do_percentage
115
+ if @total.zero?
116
+ 100
117
+ else
118
+ @current * 100 / @total
119
+ end
120
+ end
121
+
122
+ def get_width
123
+ # FIXME: I don't know how portable it is.
124
+ default_width = 80
125
+ begin
126
+ tiocgwinsz = 0x5413
127
+ data = [0, 0, 0, 0].pack("SSSS")
128
+ if @out.ioctl(tiocgwinsz, data) >= 0 then
129
+ rows, cols, xpixels, ypixels = data.unpack("SSSS")
130
+ if cols >= 0 then cols else default_width end
131
+ else
132
+ default_width
133
+ end
134
+ rescue Exception
135
+ default_width
136
+ end
137
+ end
138
+
139
+ def show
140
+ arguments = @format_arguments.map {|method|
141
+ method = sprintf("fmt_%s", method)
142
+ send(method)
143
+ }
144
+ line = sprintf(@format, *arguments)
145
+
146
+ width = get_width
147
+ if line.length == width - 1
148
+ @out.print(line + eol)
149
+ @out.flush
150
+ elsif line.length >= width
151
+ @terminal_width = [@terminal_width - (line.length - width + 1), 0].max
152
+ if @terminal_width == 0 then @out.print(line + eol) else show end
153
+ else # line.length < width - 1
154
+ @terminal_width += width - line.length + 1
155
+ show
156
+ end
157
+ @previous_time = Time.now
158
+ end
159
+
160
+ def show_if_needed
161
+ if @total.zero?
162
+ cur_percentage = 100
163
+ prev_percentage = 0
164
+ else
165
+ cur_percentage = (@current * 100 / @total).to_i
166
+ prev_percentage = (@previous * 100 / @total).to_i
167
+ end
168
+
169
+ # Use "!=" instead of ">" to support negative changes
170
+ if cur_percentage != prev_percentage ||
171
+ Time.now - @previous_time >= 1 || @finished_p
172
+ show
173
+ end
174
+ end
175
+
176
+ public
177
+ def clear
178
+ @out.print "\r"
179
+ @out.print(" " * (get_width - 1))
180
+ @out.print "\r"
181
+ end
182
+
183
+ def finish
184
+ @current = @total
185
+ @finished_p = true
186
+ show
187
+ end
188
+
189
+ def finished?
190
+ @finished_p
191
+ end
192
+
193
+ def file_transfer_mode
194
+ @format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
195
+ end
196
+
197
+ def format= (format)
198
+ @format = format
199
+ end
200
+
201
+ def format_arguments= (arguments)
202
+ @format_arguments = arguments
203
+ end
204
+
205
+ def halt
206
+ @finished_p = true
207
+ show
208
+ end
209
+
210
+ def inc (step = 1)
211
+ @current += step
212
+ @current = @total if @current > @total
213
+ show_if_needed
214
+ @previous = @current
215
+ end
216
+
217
+ def set (count)
218
+ if count < 0 || count > @total
219
+ raise "invalid count: #{count} (total: #{@total})"
220
+ end
221
+ @current = count
222
+ show_if_needed
223
+ @previous = @current
224
+ end
225
+
226
+ def inspect
227
+ "#<ProgressBar:#{@current}/#{@total}>"
228
+ end
229
+ end
230
+
231
+ class ReversedProgressBar < ProgressBar
232
+ def do_percentage
233
+ 100 - super
234
+ end
235
+ end
236
+
data/lib/role.rb ADDED
@@ -0,0 +1,12 @@
1
+ class Role < ActiveRecord::Base
2
+ has_and_belongs_to_many :users
3
+
4
+ def self.find_all_names
5
+ self.find(:all, :select => :name).map(&:name)
6
+ end
7
+
8
+ def self.find_by_names(names)
9
+ names = names.map(&:to_s)
10
+ self.find(:all, :conditions => [ "name IN (?)", names])
11
+ end
12
+ end
@@ -0,0 +1,39 @@
1
+ #
2
+ # This are the methods to set up the commands for the talia command line tool.
3
+ #
4
+ module TaliaCommandLine
5
+
6
+ # Hash with the command line commands
7
+ @commands = {}
8
+
9
+ # Set command description
10
+ def self.desc(description)
11
+ @description = description
12
+ end
13
+
14
+ # Create a new command for the command line
15
+ def self.command(name, &block)
16
+ description = @description ? @description : ""
17
+ @commands[name.to_sym] = [ description, block ]
18
+ end
19
+
20
+ # Run this to iterate through all the commands. This will pass the following
21
+ # parameters to the block: command name, description
22
+ def self.each(&block)
23
+ @commands.each do |key, value|
24
+ block.call(key, value[0], value[1])
25
+ end
26
+ end
27
+
28
+ # Returns true if the command exists
29
+ def self.command?(command)
30
+ command && @commands[command.to_sym] != nil
31
+ end
32
+
33
+ # Run the given command
34
+ def self.run_command(command, *options)
35
+ raise(RuntimeError, "Command does not exist: #{command}") unless @commands[command.to_sym]
36
+ @commands[command.to_sym][1].call(*options)
37
+ end
38
+
39
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ gem 'optiflag'
3
+ require 'optiflag'
4
+
5
+ # Parse for the command line
6
+ module TaliaCommands extend OptiFlagSet
7
+
8
+ and_process!
9
+ end
@@ -0,0 +1,75 @@
1
+ require 'ftools'
2
+ require 'fileutils'
3
+
4
+ # This is used to create a skeleton directory with the necessary
5
+ # files to set up a standalone Talia application.
6
+ module TaliaCommandLine
7
+
8
+ class << self
9
+
10
+ # Create a standalone installation directory for Talia
11
+ def create_standalone(directory)
12
+ if(File.exist?(directory))
13
+ puts "The target directory already exists: #{directory}"
14
+ return -1
15
+ end
16
+
17
+ begin
18
+ puts("Creating Talia standalone in #{directory}")
19
+ File.makedirs(directory)
20
+
21
+ # Copy the rake task extensions
22
+ copy_dir(directory, "tasks")
23
+
24
+ # Copy the rakefile
25
+ copy_file(directory, "", File.join('standalone_templates', 'Rakefile'), 'Rakefile')
26
+
27
+ # copy the config directory
28
+ File.makedirs(File.join(directory, "config"))
29
+ copy_file(directory, "config", "database.yml.example", "database.yml")
30
+ copy_file(directory, "config", "r„dfstore.yml.redland_example", "rdfstore.yml")
31
+ copy_file(directory, "config", "talia_core.yml.example", "talia_core.yml")
32
+ rescue
33
+ puts "Error creating. Removing files."
34
+ FileUtils.rm_rf(directory)
35
+ raise
36
+ end
37
+ end
38
+
39
+ protected
40
+
41
+
42
+ # This goes to the root directory for the "shared" templates. (The ones
43
+ # contained in the talia generators.
44
+ def core_root
45
+ File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "..", "..")
46
+ end
47
+
48
+
49
+ # Recursively copies a directory of template files.
50
+ def copy_dir(targetdir, dirname)
51
+ puts "Processing directory #{dirname}"
52
+ targetdir = dirname unless(targetdir)
53
+ File.makedirs(File.join(targetdir, dirname))
54
+ Dir["#{File.join(core_root, dirname)}/**"].each do |file|
55
+ unless(file =~ /^\..*/) # exclude hidden/directory files
56
+ if(File.directory?(file))
57
+ copy_dir(targetdir, File.join(dirname, File.basename(file)))
58
+ else
59
+ copy_file(targetdir, dirname, File.basename(file))
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ # Copies a file to the new target directory in the given path
66
+ def copy_file(targetdir, relative_path, name, target_name = nil)
67
+ source = File.join(core_root, relative_path, name)
68
+ target_name = name unless(target_name)
69
+ target = File.join(targetdir, relative_path, target_name)
70
+ File.cp(source, target)
71
+ puts "Copied #{File.join(relative_path, name)} to #{target_name}"
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,25 @@
1
+ # Define the command for generating a standalone Talia application
2
+ module TaliaCommandLine
3
+
4
+ desc "Generate a standalone application"
5
+ command(:standalone) do
6
+ # Loader file for the talia console
7
+ $: << File.join(File.expand_path(File.dirname(__FILE__)), "standalone")
8
+
9
+ require 'cl_options'
10
+ require 'standalone_generate'
11
+
12
+ directory = ARGV.shift
13
+
14
+ unless(directory)
15
+ puts("No directory given. Please use 'talia standalone <directory> [options]'")
16
+ exit -1
17
+ end
18
+
19
+ # flags = TaliaCommands::flags
20
+
21
+ create_standalone(directory)
22
+ end
23
+
24
+ end
25
+
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ gem 'optiflag'
3
+ require 'optiflag'
4
+
5
+ # Parse for the command line
6
+ module TaliaCommands extend OptiFlagSet
7
+
8
+ optional_flag "talia_root" do
9
+ description "Path to the TALIA_ROOT. (default: automatic)"
10
+ one_arg
11
+ end
12
+
13
+ optional_flag "talia_config" do
14
+ description "Talia configuration file name. (default: talia_core.yml)"
15
+ one_arg
16
+ end
17
+
18
+ optional_flag "environment" do
19
+ description "Environment for connections. (default: devlopement)"
20
+ one_arg
21
+ end
22
+
23
+ optional_switch_flag "reset_db" do
24
+ description "Reset the database"
25
+ end
26
+
27
+ optional_switch_flag "reset_rdf" do
28
+ description "Reset the RDF store"
29
+ end
30
+
31
+ optional_switch_flag "verbose" do
32
+ description "Turn on the verbose mode"
33
+ end
34
+
35
+ optional_switch_flag "noinit" do
36
+ description "Do not initialize the Talia core"
37
+ end
38
+
39
+ and_process!
40
+
41
+ # Putting the flags into the environment, and remove them to avoid
42
+ # having them interpreted by irb
43
+ flags.each do |flag, content|
44
+ my_content = content
45
+ my_content = "yes" if(content == true)
46
+ ENV[flag.to_s] = my_content
47
+ killed = ARGV.index("-#{flag}") # Delete the flag
48
+ if(killed)
49
+ ARGV.delete_at(killed + 1) if(content.is_a?(String)) # delete the parameter, if there is one
50
+ ARGV.delete_at(killed)
51
+ end
52
+ end
53
+
54
+ # puts ENV.each { |k,v| puts "#{k} - #{v}"} if(flags[:verbose])
55
+ end
@@ -0,0 +1,37 @@
1
+ # This adds the console commands for the talia console
2
+
3
+ module TaliaCommandLine
4
+
5
+ # Array with command descriptions
6
+ @console_commands = Array.new
7
+
8
+ # Add a new console command
9
+ def self.console(command, &command_block)
10
+ # Add the description
11
+ description = @desc ? @desc : "Generic command: #{command}"
12
+ @desc = nil
13
+ @console_commands << [command.to_s, description]
14
+
15
+ command = command.to_sym
16
+
17
+ (class << MAIN_OBJECT; self; end).class_eval do
18
+ define_method(command, command_block)
19
+ end
20
+ end
21
+
22
+ # Add an instance variable
23
+ def self.to_var(name, value)
24
+ (class << MAIN_OBJECT; self; end).class_eval do
25
+ raise(RuntimeError, "Method already defined: #{name}") if(method_defined?(name))
26
+ define_method(name) { value }
27
+ end
28
+ value
29
+ end
30
+
31
+ # Returns the defined console commands
32
+ def self.console_commands
33
+ @console_commands
34
+ end
35
+
36
+ end
37
+
@@ -0,0 +1,131 @@
1
+ # Create the commands for the Talia console
2
+ require 'console_commands'
3
+
4
+ module TaliaCommandLine
5
+
6
+ desc "Show help on the talia console commands"
7
+ console(:thelp) do
8
+ puts "Talia console commands:\n\n"
9
+ TaliaCommandLine::console_commands.each do |command|
10
+ puts "#{command[0]}\t- #{command[1]}"
11
+ end
12
+ nil
13
+ end
14
+
15
+ desc "Get all sources"
16
+ console(:sources) do
17
+ TaliaCore::Source.find(:all)
18
+ end
19
+
20
+ desc "Find a source by local uri"
21
+ console(:tsrc) do |uri|
22
+ TaliaCore::Source.find(N::LOCAL + uri)
23
+ end
24
+
25
+ desc "Add a RDF source adapter. Result set to 'adapter'. Use: :type, option => ..."
26
+ console(:rdf_source) do |type, options|
27
+ options[:type] = type
28
+ to_var :adapter, ConnectionPool.add_data_source(options)
29
+ end
30
+
31
+ desc "Drop RDF data sources."
32
+ console(:rdf_down) do
33
+ ConnectionPool.clear
34
+ end
35
+
36
+ desc "Create a RDFS::Resource. Result set to 'res'"
37
+ console(:resource) do |uri|
38
+ to_var :res, RDFS::Resource.new(uri)
39
+ end
40
+
41
+ desc "Print the given element"
42
+ console(:tprint) do |element|
43
+ puts element.class
44
+ if(element.kind_of?(TaliaCore::Source))
45
+ puts "Source: #{element.uri}"
46
+ puts "Name: #{element.name}m"
47
+ element.direct_predicates.each do |pred|
48
+ puts "#{pred.to_name_s}:"
49
+ pred.each { |val| puts val}
50
+ end
51
+ elsif(element.kind_of?(RDFS::Resource))
52
+ puts "RDFS::Resource #{element.uri}"
53
+ element.direct_predicates.each do |pred|
54
+ puts "#{pred.uri}:"
55
+ element[pred.uri].each { |val| puts "\t#{Uri.new(val).to_name_s}\n\n" }
56
+ end
57
+ elsif(element.kind_of?(String))
58
+ puts element
59
+ elsif(element.respond_to?("each"))
60
+ element.each { |el| puts el.to_s }
61
+ else
62
+ puts "Unknown type: #{element.class}"
63
+ end
64
+ nil
65
+ end
66
+
67
+ desc "Print the rdf types"
68
+ console(:put_types) do
69
+ N::SourceClass.rdf_types.each do |type|
70
+ puts type.to_name_s
71
+ end
72
+ nil
73
+ end
74
+
75
+ desc "Import into the Talia store. Can be called with {rdf|data|yaml} as parameter"
76
+ console(:talia_import) do |type|
77
+ unless(type)
78
+ print "Import which type? (rdf|data|yaml) : "
79
+ type = readline
80
+ end
81
+ type = type.to_s.strip
82
+ print "Enter file pattern: "
83
+ filepattern = readline
84
+ case(type)
85
+ when "rdf":
86
+ print "Select data file format (ntriples|rdfxml): "
87
+ dataformat = readline
88
+ RdfImport::import(dataformat, FileList.new(filepattern))
89
+ when "yaml":
90
+ YamlImport::import_multi_files(FileList.new(filepattern))
91
+ when "data":
92
+ print "Select data type to import: "
93
+ datatype = readline
94
+ DataImport::import(FileList.new(filepattern), datatype)
95
+ end
96
+ end
97
+
98
+ desc "Quick query for sources. Use nil as a placeholder"
99
+ console(:tquery) do |subject, predicate, object|
100
+ variables = []
101
+ q_subject = if(subject)
102
+ RDFS::Resource.new(N::URI::make_uri(subject).to_s)
103
+ else
104
+ variables << :s
105
+ :s
106
+ end
107
+ q_predicate = if(predicate)
108
+ RDFS::Resource.new(N::URI::make_uri(predicate).to_s)
109
+ else
110
+ variables << :p
111
+ :p
112
+ end
113
+ q_object = if(object)
114
+ if(object.include?(":"))
115
+ RDFS::Resource.new(N::URI::make_uri(object).to_s)
116
+ else
117
+ object
118
+ end
119
+ else
120
+ variables << :o
121
+ :o
122
+ end
123
+ my_query = Query.new.select(*variables).distinct
124
+ my_query.where(q_subject, q_predicate, q_object)
125
+ puts "SPARQL: #{Query2SPARQL.translate(my_query)}"
126
+ puts ""
127
+ my_query.execute
128
+ end
129
+ end
130
+
131
+
@@ -0,0 +1,47 @@
1
+ # We just capture the main object for later reuse, as a workaround for adding
2
+ # the command line commands to it.
3
+ MAIN_OBJECT = self
4
+
5
+ # Define the command for the Talia console
6
+ module TaliaCommandLine
7
+
8
+ desc "Start the Talia console"
9
+ command(:console) do
10
+ # Loader file for the talia console
11
+ $: << File.join(File.expand_path(File.dirname(__FILE__)), "talia_console")
12
+
13
+ # Console modules
14
+ require "talia_commands"
15
+ require "cl_options"
16
+
17
+ # Foreign modules
18
+ require "irb"
19
+ require "rake"
20
+
21
+ puts "\nEnter <thelp> for help on the Talia-specific commands."
22
+ puts ""
23
+
24
+ flags = TaliaCommands::flags
25
+
26
+ unless(flags.noinit?)
27
+ Util::init_talia
28
+ Util::talia_config if(flags.verbose?)
29
+ else
30
+ puts "Talia not initialized, as requested."
31
+ end
32
+
33
+ IRB.start
34
+
35
+ # if __FILE__ == $0
36
+ # IRB.start(__FILE__)
37
+ # else
38
+ # # check -e option
39
+ # if /^-e$/ =~ $0
40
+ # IRB.start(__FILE__)
41
+ # else
42
+ # IRB.setup(__FILE__)
43
+ # end
44
+ # end
45
+ end
46
+
47
+ end
@@ -0,0 +1,11 @@
1
+ #
2
+ # Loads the commands that are defined for the talia core
3
+ #
4
+
5
+ command_dir = File.expand_path(File.join(File.dirname(__FILE__), 'commands'))
6
+
7
+ $: << command_dir
8
+
9
+ Dir["#{command_dir}/*.rb"].each do |file|
10
+ require File.basename(file.gsub(/\.rb$/, ''))
11
+ end