spread2rdf 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZDBiNzc0ZTVkZTk5ZjY0OWEwZjA2YTYyYzgxN2MyYzNkYTBkZjkyYw==
5
+ data.tar.gz: !binary |-
6
+ N2M2YTZlNDVmZjE0ZTFjYjFjMzAwMDBhYWQ4NzkzNjJmNzI3YzQ2Mg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YTBkZmY4Y2IxNjc0NGM2MzJlNjFjZDY0Y2E4ODBmZWI5NTgzNGFkNGRkNmFk
10
+ YWIyOTU0ZWEzZGRiNzE5ZTFkMWE1ZjA4NDBjOGUzNWMxOWRhYjg5MGUyZWYx
11
+ NmY2ZWZhNzNjZDllOGVlYzAzZmQzNGY4NjQ0ZTkzNjU4NGU3M2E=
12
+ data.tar.gz: !binary |-
13
+ MjgzZGQwMzI2MmQ1MzFjOTBkOTRiOThhNTcwNjNiOWZmODBmNWUyN2MyNTBi
14
+ NWYzZmU0MmYwODNhMDU2YjNkZDg5MjA5NTRlMmE0ODc5NWZlOWVkNTIzOGVi
15
+ ZDZiZTRmNTdhYWM3MzY4ODFiZGQ0ZThjZDk1OTIyYjI3N2UxNGM=
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # Spread2RDF
2
2
 
3
- Spread2RDF is a converter for complex spreadsheets to RDF and a DSL for
4
- specifying the mapping rules for this conversion.
3
+ Spread2RDF is a converter for complex spreadsheets to RDF and a Ruby-internal
4
+ [DSL](http://en.wikipedia.org/wiki/Domain-specific_language)
5
+ for specifying the mapping rules for this conversion.
5
6
 
6
7
  ## Features
7
8
 
@@ -12,6 +13,8 @@ specifying the mapping rules for this conversion.
12
13
  [raise an issue](https://github.com/marcelotto/spread2rdf/issues).)
13
14
  * Supports many RDF serialization formats for the output, thanks to
14
15
  [RDF.rb](https://github.com/ruby-rdf/rdf).
16
+ * Mapping definitions are compilable to executables, which can be run without
17
+ Ruby installed.
15
18
 
16
19
  ## Installation
17
20
 
@@ -20,25 +23,6 @@ in a terminal:
20
23
 
21
24
  $ gem install spread2rdf
22
25
 
23
- ## Command-line interface
24
-
25
- For a description of all available parameters, type the following in a terminal:
26
-
27
- $ spread2rdf --help
28
-
29
- ## Mapping DSL
30
-
31
- Description is following soon.
32
-
33
- ## Contributing
34
-
35
- 1. Fork it
36
- 2. Create your feature branch (`git checkout -b my-new-feature`)
37
- 3. Commit your changes (`git commit -am 'Added some feature'`)
38
- 4. Push to the branch (`git push origin my-new-feature`)
39
- 5. Create new Pull Request
40
-
41
-
42
- ## Authors
26
+ ## Author
43
27
 
44
28
  * Marcel Otto
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.1.0
@@ -17,9 +17,14 @@ module Spread2RDF
17
17
  defaults.each { |attribute, default_value| attr_accessor attribute }
18
18
  @attributes = @attributes.try(:merge, defaults) || defaults
19
19
  end
20
+
21
+ def normalize_attributes(values)
22
+ values
23
+ end
20
24
  end
21
25
 
22
26
  def init_attributes(initial_values)
27
+ initial_values = self.class.normalize_attributes(initial_values)
23
28
  self.class.attributes.each do |attribute, default_value|
24
29
  instance_variable_set("@#{attribute}".to_sym,
25
30
  initial_values.delete(attribute) || default_value)
@@ -28,6 +33,7 @@ module Spread2RDF
28
33
  end
29
34
 
30
35
  def update_attributes(update_values)
36
+ update_values = self.class.normalize_attributes(update_values)
31
37
  update_values.each do |attribute, value|
32
38
  next unless self.class.attributes.include? attribute
33
39
  instance_variable_set("@#{attribute}".to_sym, value)
@@ -101,6 +101,11 @@ module Spread2RDF
101
101
  @options[:output_format] = format.strip.downcase
102
102
  end
103
103
 
104
+ opts.on( '-I', '--include DIR', "Add DIR to the search path for external data" ) do |dir|
105
+ raise "Directory #{dir} doesn't exist" unless File.directory?(dir)
106
+ Spread2RDF::SEARCH_PATH.unshift dir
107
+ end
108
+
104
109
  opts.on( '-d', '--debug', 'Run in debug mode' ) do
105
110
  Spread2RDF.debug_mode = true
106
111
  end
@@ -112,7 +117,8 @@ module Spread2RDF
112
117
  else
113
118
  raise OptionParser::ParseError, 'required schema specification file missing' if @mapping_schema.nil?
114
119
  @input_file = ARGV.first or @input_file or
115
- raise OptionParser::ParseError, 'required file arguments missing'
120
+ raise OptionParser::ParseError, 'required input file missing'
121
+ SEARCH_PATH << File.expand_path(File.dirname(@input_file))
116
122
  end
117
123
  rescue OptionParser::ParseError => e
118
124
  puts e.message
@@ -0,0 +1,10 @@
1
+ class File
2
+ def self.in_path(filename, search_path = Spread2RDF::SEARCH_PATH)
3
+ return filename if File.exist? filename
4
+ search_path.each do |path|
5
+ file = File.join(path, filename)
6
+ return file if File.exist? file
7
+ end
8
+ nil
9
+ end
10
+ end
@@ -46,19 +46,46 @@ module Spread2RDF
46
46
 
47
47
  def resolve_resource_ref
48
48
  source = schema.object[:from]
49
- source = { worksheet: source } if source.is_a? Symbol
50
- raise ArgumentError, "expecting a Hash as source, but got #{source}" unless source.is_a? Hash
51
- source_worksheet = source[:worksheet]
52
- source_worksheet = spreadsheet.worksheet(source_worksheet)
53
- raise "#{self}: couldn't find source worksheet #{source[:worksheet]}" if source_worksheet.nil?
54
- source_predicate = source[:predicate] || RDF::RDFS.label
55
- result = source_worksheet.graph.query([nil, source_predicate, value])
56
- raise "#{self}: couldn't find a resource for #{value} in #{source_worksheet}" if result.empty?
57
- raise "#{self}: found multiple resources for #{value} in #{source_worksheet}: #{result.map(&:subject)}" if result.count > 1
58
- result.first.subject
49
+ if source[:worksheet] && result = resolve_resource_ref_from_worksheet(source[:worksheet])
50
+ return result
51
+ elsif source[:data_source] && result = resolve_resource_ref_from_data_sources(source[:data_source])
52
+ return result
53
+ else
54
+ raise "#{self}: couldn't find a resource for #{value} in any of the defined sources"
55
+ end
59
56
  end
60
57
  private :resolve_resource_ref
61
58
 
59
+ def resolve_resource_ref_from_worksheet(worksheet)
60
+ worksheet = spreadsheet.worksheet(worksheet)
61
+ raise "#{self}: couldn't find source worksheet #{source[:worksheet]}" if worksheet.nil?
62
+ source_predicate = RDF::RDFS.label # TODO: make this configurable via a attribute in the schema definition
63
+ result = worksheet.graph.query([nil, source_predicate, value])
64
+ return nil if result.empty?
65
+ raise "#{self}: found multiple resources for #{value} in #{worksheet}: #{result.map(&:subject)}" if result.count > 1
66
+ result.first.subject
67
+ end
68
+ private :resolve_resource_ref_from_worksheet
69
+
70
+ def resolve_resource_ref_from_data_sources(data_sources)
71
+ raise ArgumentError, "expecting an Array, but got #{data_sources}" unless data_sources.is_a? Array
72
+ data_sources.each do |data_source|
73
+ result = resolve_resource_ref_from_data_source(data_source)
74
+ return result if result
75
+ end
76
+ nil
77
+ end
78
+ private :resolve_resource_ref_from_data_sources
79
+
80
+ def resolve_resource_ref_from_data_source(data_source)
81
+ source_predicate = RDF::RDFS.label # TODO: make this configurable via a attribute in the schema definition
82
+ result = data_source.query([nil, source_predicate, value])
83
+ return nil if result.empty?
84
+ raise "#{self}: found multiple resources for #{value} in data sources: #{result.map(&:subject)}" if result.count > 1
85
+ result.first.subject
86
+ end
87
+ private :resolve_resource_ref_from_data_source
88
+
62
89
  def create_resource_object
63
90
  case
64
91
  when (schema.object.try(:fetch, :uri, nil) || object) == :bnode
@@ -9,6 +9,40 @@ module Spread2RDF
9
9
  statement: nil
10
10
  }
11
11
 
12
+ def self.normalize_attributes(values)
13
+ if object = values[:object]
14
+ case
15
+ when object.is_a?(Proc) then # nothing
16
+ when !(from = object.delete(:from_worksheet) ||
17
+ object.delete(:from_sheet)).nil?
18
+ object[:from] = { worksheet: from.to_sym }
19
+ when !(from = object.delete(:from_data_source)).nil?
20
+ object[:from] = { data_source: resolve_data_sources(from) }
21
+ when !(from = object[:from]).nil?
22
+ case from
23
+ when Symbol then object[:from] = { worksheet: from }
24
+ when String then object[:from] = { data_source: resolve_data_sources(from) }
25
+ when Hash
26
+ from[:data_source] = resolve_data_sources(from[:data_source]) if from.include?(:data_source)
27
+ end
28
+ end
29
+ end
30
+ values
31
+ end
32
+
33
+ def self.resolve_data_sources(data_sources)
34
+ return [data_sources] unless data_sources.is_a? Array
35
+ data_sources.map do |data_source|
36
+ case
37
+ when (uri = data_source).is_a?(RDF::URI) || (uri = RDF::URI.new(data_source)).valid?
38
+ raise NotImplementedError, "resolving of uris is not implemented yet"
39
+ when data_source.is_a?(String) && !(file = File.in_path(data_source)).nil?
40
+ RDF::Graph.load file
41
+ else puts "WARNING: couldn't resolve data source #{data_source}"
42
+ end
43
+ end.compact
44
+ end
45
+
12
46
  attr_reader :coord # this is set by Worksheet#index_columns!
13
47
 
14
48
  alias sheet parent
@@ -25,7 +25,8 @@ module Spread2RDF
25
25
  references = []
26
26
  each_column do |column|
27
27
  if column.object_mapping_mode == :resource_ref
28
- references << spreadsheet.worksheet[column.object[:from]]
28
+ references << spreadsheet.worksheet[
29
+ column.object[:from].try(:fetch, :worksheet)]
29
30
  end
30
31
  end
31
32
  references
data/lib/spread2rdf.rb CHANGED
@@ -16,6 +16,7 @@ require 'spread2rdf/version'
16
16
  require 'spread2rdf/coord'
17
17
  require 'spread2rdf/namespace'
18
18
  require 'spread2rdf/roo_helper'
19
+ require 'spread2rdf/extensions/file'
19
20
 
20
21
  require 'spread2rdf/schema/schema'
21
22
  require 'spread2rdf/schema/statement_mapping_schema'
@@ -40,7 +41,6 @@ require 'spread2rdf/mapping/cell'
40
41
 
41
42
  require 'spread2rdf/mapping/default_cell_mappings'
42
43
 
43
-
44
44
  require 'spread2rdf/cli'
45
45
 
46
46
  module Spread2RDF
@@ -51,5 +51,8 @@ module Spread2RDF
51
51
  ROOT = File.expand_path('../../', __FILE__)
52
52
  ONTOLOGY_DIR = File.join(ROOT, 'ontologies')
53
53
 
54
+ SEARCH_PATH = []
55
+ #SEARCH_PATH << ONTOLOGY_DIR
56
+
54
57
  end
55
58
 
data/spread2rdf.gemspec CHANGED
@@ -26,7 +26,8 @@ Gem::Specification.new do |gem|
26
26
  gem.add_dependency('roo', '~> 1.12.2')
27
27
  gem.add_dependency('rubyzip', '~> 1.0.0') # for the roo-xlsm-fix
28
28
 
29
- gem.add_dependency('linkeddata', '~> 1.0.0')
29
+ gem.add_dependency('linkeddata', '~> 1.1.0')
30
+ gem.add_dependency('equivalent-xml', '~> 0.3.0')
30
31
 
31
32
  gem.add_dependency('ocra', '~> 1.3.1')
32
33
  gem.add_dependency('bundler') # needed for ocra
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spread2rdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Marcel Otto
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-11-13 00:00:00.000000000 Z
11
+ date: 2013-12-12 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activesupport
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: awesome_print
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: roo
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rubyzip
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,23 +69,34 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: linkeddata
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ~>
84
74
  - !ruby/object:Gem::Version
85
- version: 1.0.0
75
+ version: 1.1.0
86
76
  type: :runtime
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ~>
92
81
  - !ruby/object:Gem::Version
93
- version: 1.0.0
82
+ version: 1.1.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: equivalent-xml
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 0.3.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 0.3.0
94
97
  - !ruby/object:Gem::Dependency
95
98
  name: ocra
96
99
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
100
  requirements:
99
101
  - - ~>
100
102
  - !ruby/object:Gem::Version
@@ -102,7 +104,6 @@ dependencies:
102
104
  type: :runtime
103
105
  prerelease: false
104
106
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
107
  requirements:
107
108
  - - ~>
108
109
  - !ruby/object:Gem::Version
@@ -110,7 +111,6 @@ dependencies:
110
111
  - !ruby/object:Gem::Dependency
111
112
  name: bundler
112
113
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
114
  requirements:
115
115
  - - ! '>='
116
116
  - !ruby/object:Gem::Version
@@ -118,7 +118,6 @@ dependencies:
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
121
  requirements:
123
122
  - - ! '>='
124
123
  - !ruby/object:Gem::Version
@@ -126,7 +125,6 @@ dependencies:
126
125
  - !ruby/object:Gem::Dependency
127
126
  name: rake
128
127
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
128
  requirements:
131
129
  - - ! '>='
132
130
  - !ruby/object:Gem::Version
@@ -134,7 +132,6 @@ dependencies:
134
132
  type: :development
135
133
  prerelease: false
136
134
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
135
  requirements:
139
136
  - - ! '>='
140
137
  - !ruby/object:Gem::Version
@@ -142,7 +139,6 @@ dependencies:
142
139
  - !ruby/object:Gem::Dependency
143
140
  name: pry
144
141
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
142
  requirements:
147
143
  - - ~>
148
144
  - !ruby/object:Gem::Version
@@ -150,7 +146,6 @@ dependencies:
150
146
  type: :development
151
147
  prerelease: false
152
148
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
149
  requirements:
155
150
  - - ~>
156
151
  - !ruby/object:Gem::Version
@@ -158,7 +153,6 @@ dependencies:
158
153
  - !ruby/object:Gem::Dependency
159
154
  name: pry-nav
160
155
  requirement: !ruby/object:Gem::Requirement
161
- none: false
162
156
  requirements:
163
157
  - - ~>
164
158
  - !ruby/object:Gem::Version
@@ -166,7 +160,6 @@ dependencies:
166
160
  type: :development
167
161
  prerelease: false
168
162
  version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
163
  requirements:
171
164
  - - ~>
172
165
  - !ruby/object:Gem::Version
@@ -192,6 +185,7 @@ files:
192
185
  - lib/spread2rdf/attributes.rb
193
186
  - lib/spread2rdf/cli.rb
194
187
  - lib/spread2rdf/coord.rb
188
+ - lib/spread2rdf/extensions/file.rb
195
189
  - lib/spread2rdf/extensions/roo_xlsm_fix.rb
196
190
  - lib/spread2rdf/mapping/cell.rb
197
191
  - lib/spread2rdf/mapping/column.rb
@@ -221,27 +215,26 @@ files:
221
215
  homepage: http://github.com/marcelotto/spread2rdf
222
216
  licenses:
223
217
  - MIT
218
+ metadata: {}
224
219
  post_install_message:
225
220
  rdoc_options: []
226
221
  require_paths:
227
222
  - lib
228
223
  required_ruby_version: !ruby/object:Gem::Requirement
229
- none: false
230
224
  requirements:
231
225
  - - ! '>='
232
226
  - !ruby/object:Gem::Version
233
227
  version: 1.9.3
234
228
  required_rubygems_version: !ruby/object:Gem::Requirement
235
- none: false
236
229
  requirements:
237
230
  - - ! '>='
238
231
  - !ruby/object:Gem::Version
239
232
  version: '0'
240
233
  requirements: []
241
234
  rubyforge_project:
242
- rubygems_version: 1.8.24
235
+ rubygems_version: 2.1.9
243
236
  signing_key:
244
- specification_version: 3
237
+ specification_version: 4
245
238
  summary: a DSL-based converter for spreadsheets to RDF
246
239
  test_files: []
247
240
  has_rdoc: