spread2rdf 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/VERSION +1 -1
- data/lib/spread2rdf/mapping/cell.rb +4 -12
- data/lib/spread2rdf/mapping/default_cell_mappings.rb +3 -1
- data/lib/spread2rdf/mapping/resource.rb +4 -21
- data/lib/spread2rdf/mapping/resource_creation.rb +29 -0
- data/lib/spread2rdf/mapping/statement.rb +6 -1
- data/lib/spread2rdf/schema/column.rb +6 -1
- data/lib/spread2rdf/schema/resource_creation_schema.rb +27 -0
- data/lib/spread2rdf/schema/sheet.rb +5 -17
- data/lib/spread2rdf/schema/statement_mapping_schema.rb +5 -2
- data/lib/spread2rdf.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NGJiMTM4NmY0YzNmY2IwZDkyMWFmZTRjMDY2MDk5ZmE1NWEyMTdjOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MGJkOWUyOTI2MTA4YjgwOTdlNDZmOTY4MDZhOTcxMjA0ZWI3MmEwMg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzE5Y2M3ZGZhMjc2NzFhYTg4Yzk1ZGFmMDExNTQ4YmYzNzQyOWIyZGNhNzgy
|
10
|
+
MDA5NzZmNDI5MGNmMDE4OTVjOWI0ODc5NWEzNGY4OTY3MDI3YTkyYjk5NGNm
|
11
|
+
NzBkOTYzYTUyYWUzOTU1NzJhNTQ0NDg1ODhkMzBkMTAzNGViN2U=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzY0ZWQ0MjBmNGViZDQzYTAwYzM2ZDc0MDY0YzBkNmU1ZGQ4MDBlODg1MGMy
|
14
|
+
YWU0MmRhY2UwNWI5YzMwNDU2Zjc1ZGVlZjg2ZjM5NjM3MmQwYTU1ZjZjOWVk
|
15
|
+
ZTdiYzg5ZmRkOWUzN2JhNjFlMzQ5MGE4MTQwNzhiNWRmM2E1ODg=
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Spread2RDF
|
2
2
|
module Mapping
|
3
3
|
class Cell < Element
|
4
|
+
include ResourceCreation
|
4
5
|
|
5
6
|
attr_reader :row
|
6
7
|
|
@@ -24,6 +25,7 @@ module Spread2RDF
|
|
24
25
|
def value
|
25
26
|
@value ||= worksheet.cell_value(coord)
|
26
27
|
end
|
28
|
+
alias resource_creation_value value
|
27
29
|
|
28
30
|
def object
|
29
31
|
@object ||= value && map_to_object(value)
|
@@ -37,9 +39,9 @@ module Spread2RDF
|
|
37
39
|
case schema.object_mapping_mode
|
38
40
|
when :to_string then map_to_literal(value)
|
39
41
|
when :resource_ref then resolve_resource_ref
|
40
|
-
when :new_resource then
|
42
|
+
when :new_resource then create_resource
|
41
43
|
when :custom then exec(&schema.cell_mapping)
|
42
|
-
else raise 'internal error: unknown column mapping
|
44
|
+
else raise 'internal error: unknown column mapping mode'
|
43
45
|
end
|
44
46
|
end
|
45
47
|
private :map_to_object
|
@@ -97,16 +99,6 @@ module Spread2RDF
|
|
97
99
|
result.first.subject
|
98
100
|
end
|
99
101
|
|
100
|
-
def create_resource_object
|
101
|
-
case
|
102
|
-
when (schema.object.try(:fetch, :uri, nil) || object) == :bnode
|
103
|
-
RDF::Node.new
|
104
|
-
else
|
105
|
-
raise NotImplementedError
|
106
|
-
end
|
107
|
-
end
|
108
|
-
private :create_resource_object
|
109
|
-
|
110
102
|
##########################################################################
|
111
103
|
# for the DSL for column statement blocks
|
112
104
|
|
@@ -24,29 +24,11 @@ module Spread2RDF
|
|
24
24
|
##########################################################################
|
25
25
|
# subject mapping
|
26
26
|
|
27
|
-
|
28
|
-
@subject ||=
|
29
|
-
case schema.subject_mapping_mode
|
30
|
-
when :bnode then RDF::Node.new
|
31
|
-
when :from_column_with_suffix then subject_resource_from_column_with_suffix
|
32
|
-
when :from_column then subject_resource_from_column
|
33
|
-
else raise 'unknown subject mapping type'
|
34
|
-
end
|
35
|
-
end
|
36
|
-
alias subject_resource subject
|
27
|
+
include ResourceCreation
|
37
28
|
|
38
|
-
def
|
39
|
-
|
40
|
-
end
|
41
|
-
private :subject_resource_from_column
|
42
|
-
|
43
|
-
def subject_resource_from_column_with_suffix
|
44
|
-
namespace = schema.subject_namespace
|
45
|
-
subject_suffix = Mapping::Cell::Default.uri_normalization(subject_value)
|
46
|
-
#puts "subject resource for #{sheet} in #{range}: " + RDF::URI.new("#{namespace}#{subject_suffix}" )
|
47
|
-
RDF::URI.new("#{namespace}#{subject_suffix}")
|
29
|
+
def subject
|
30
|
+
@subject ||= create_resource
|
48
31
|
end
|
49
|
-
private :subject_resource_from_column_with_suffix
|
50
32
|
|
51
33
|
def subject_value
|
52
34
|
cells = row_range.map do |row|
|
@@ -56,6 +38,7 @@ module Spread2RDF
|
|
56
38
|
raise "multiple subjects found for Resource in #{row_range} of #{sheet}: #{cells.inspect}" if cells.count > 1
|
57
39
|
cells.first
|
58
40
|
end
|
41
|
+
alias resource_creation_value subject_value
|
59
42
|
private :subject_value
|
60
43
|
|
61
44
|
def subject_description
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Spread2RDF
|
2
|
+
module Mapping
|
3
|
+
module ResourceCreation
|
4
|
+
|
5
|
+
def create_resource
|
6
|
+
case schema.resource_creation_mode
|
7
|
+
when :bnode then RDF::Node.new
|
8
|
+
when :from_column_with_suffix then resource_from_suffix
|
9
|
+
when :from_column then resource_from_full_uri
|
10
|
+
else raise 'unknown resource creation mode'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def resource_from_full_uri
|
15
|
+
RDF::URI.new(resource_creation_value, validate: true)
|
16
|
+
end
|
17
|
+
private :resource_from_full_uri
|
18
|
+
|
19
|
+
def resource_from_suffix
|
20
|
+
namespace = schema.resource_creation_namespace
|
21
|
+
suffix = Mapping::Cell::Default.uri_normalization(resource_creation_value)
|
22
|
+
#puts "creating resource " + RDF::URI.new("#{namespace}#{suffix}" )
|
23
|
+
RDF::URI.new("#{namespace}#{suffix}")
|
24
|
+
end
|
25
|
+
private :resource_from_suffix
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -5,8 +5,13 @@ module Spread2RDF
|
|
5
5
|
def statements_to_object(object)
|
6
6
|
case schema.statement_mapping_mode
|
7
7
|
when :default
|
8
|
-
|
8
|
+
if schema.inverse_mode
|
9
|
+
statement(object, predicate, subject)
|
10
|
+
else
|
11
|
+
statement(subject, predicate, object)
|
12
|
+
end
|
9
13
|
when :restriction
|
14
|
+
raise NotImplementedError if schema.inverse_mode
|
10
15
|
restriction_class = RDF::Node.new
|
11
16
|
statements(
|
12
17
|
[ subject, RDF::RDFS.subClassOf, restriction_class ],
|
@@ -2,6 +2,7 @@ module Spread2RDF
|
|
2
2
|
module Schema
|
3
3
|
class Column < Element
|
4
4
|
include StatementMapping
|
5
|
+
include ResourceCreation
|
5
6
|
|
6
7
|
self.attributes = {
|
7
8
|
predicate: nil,
|
@@ -31,7 +32,7 @@ module Spread2RDF
|
|
31
32
|
end
|
32
33
|
|
33
34
|
def self.resolve_data_sources(data_sources)
|
34
|
-
|
35
|
+
data_sources = [data_sources] unless data_sources.is_a? Array
|
35
36
|
data_sources.map do |data_source|
|
36
37
|
case
|
37
38
|
when (uri = data_source).is_a?(RDF::URI) || (uri = RDF::URI.new(data_source)).valid?
|
@@ -63,6 +64,10 @@ module Spread2RDF
|
|
63
64
|
end
|
64
65
|
end
|
65
66
|
|
67
|
+
def resource_creation_attributes
|
68
|
+
object
|
69
|
+
end
|
70
|
+
|
66
71
|
def cell_mapping
|
67
72
|
object if object.is_a?(Proc)
|
68
73
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Spread2RDF
|
2
|
+
module Schema
|
3
|
+
module ResourceCreation
|
4
|
+
|
5
|
+
def resource_creation_mode
|
6
|
+
attr = self.resource_creation_attributes
|
7
|
+
case
|
8
|
+
when ( attr.try(:fetch, :uri, nil) || attr ) == :bnode
|
9
|
+
:bnode
|
10
|
+
when !( attr.try(:fetch, :uri, nil).try(:fetch, :namespace, nil) ).nil?
|
11
|
+
:from_column_with_suffix
|
12
|
+
else
|
13
|
+
:from_column
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def resource_creation_namespace
|
18
|
+
namespace_name =
|
19
|
+
self.resource_creation_attributes.try(:fetch, :uri, nil).try(:fetch, :namespace, nil)
|
20
|
+
return warn("No namespace for resource creation found") if namespace_name.nil?
|
21
|
+
Namespace.resolve_to_namespace(namespace_name)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Spread2RDF
|
2
2
|
module Schema
|
3
3
|
class Sheet < Element
|
4
|
+
include ResourceCreation
|
4
5
|
|
5
6
|
self.attributes = {
|
6
7
|
start: :A2,
|
@@ -14,6 +15,10 @@ module Spread2RDF
|
|
14
15
|
@column_index = {}
|
15
16
|
end
|
16
17
|
|
18
|
+
def resource_creation_attributes
|
19
|
+
subject
|
20
|
+
end
|
21
|
+
|
17
22
|
def start_coord
|
18
23
|
Coord[start]
|
19
24
|
end
|
@@ -64,23 +69,6 @@ module Spread2RDF
|
|
64
69
|
row_count_per_resource or ( !subject_column && 1 ) or nil
|
65
70
|
end
|
66
71
|
|
67
|
-
def subject_mapping_mode
|
68
|
-
case
|
69
|
-
when ( subject.try(:fetch, :uri, nil) || subject ) == :bnode
|
70
|
-
:bnode
|
71
|
-
when !( subject.try(:fetch, :uri, nil).try(:fetch, :namespace, nil) ).nil?
|
72
|
-
:from_column_with_suffix
|
73
|
-
else
|
74
|
-
:from_column
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def subject_namespace
|
79
|
-
subject_namespace_name =
|
80
|
-
subject.try(:fetch, :uri, nil).try(:fetch, :namespace, nil)
|
81
|
-
Namespace.resolve_to_namespace(subject_namespace_name)
|
82
|
-
end
|
83
|
-
|
84
72
|
def subject_resource_type
|
85
73
|
subject.try(:fetch, :type, nil) or
|
86
74
|
(subject.try(:fetch, :sub_class_of, nil) && RDF::RDFS.Class) or
|
@@ -4,7 +4,6 @@ module Spread2RDF
|
|
4
4
|
|
5
5
|
def statement_mapping_mode
|
6
6
|
case
|
7
|
-
when statement == :none then :ignore
|
8
7
|
when statement == :none then :ignore
|
9
8
|
when predicate.nil? then :ignore
|
10
9
|
when restriction_mode then :restriction
|
@@ -15,11 +14,15 @@ module Spread2RDF
|
|
15
14
|
def restriction_mode
|
16
15
|
case statement
|
17
16
|
when :restriction then RDF::OWL.hasValue
|
18
|
-
when Hash then
|
17
|
+
when Hash then statement[:restriction]
|
19
18
|
else false
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
22
|
+
def inverse_mode
|
23
|
+
statement == :inverse ||
|
24
|
+
( statement.is_a?(Hash) && statement.try(:fetch, :inverse, false) )
|
25
|
+
end
|
23
26
|
|
24
27
|
end
|
25
28
|
end
|
data/lib/spread2rdf.rb
CHANGED
@@ -20,6 +20,7 @@ require 'spread2rdf/extensions/file'
|
|
20
20
|
|
21
21
|
require 'spread2rdf/schema/schema'
|
22
22
|
require 'spread2rdf/schema/statement_mapping_schema'
|
23
|
+
require 'spread2rdf/schema/resource_creation_schema'
|
23
24
|
require 'spread2rdf/schema/element'
|
24
25
|
require 'spread2rdf/schema/spreadsheet'
|
25
26
|
require 'spread2rdf/schema/sheet'
|
@@ -30,6 +31,7 @@ require 'spread2rdf/schema/sheet_dsl'
|
|
30
31
|
require 'spread2rdf/schema/spreadsheet_dsl'
|
31
32
|
|
32
33
|
require 'spread2rdf/mapping/element'
|
34
|
+
require 'spread2rdf/mapping/resource_creation'
|
33
35
|
require 'spread2rdf/mapping/statement'
|
34
36
|
require 'spread2rdf/mapping/sheet'
|
35
37
|
require 'spread2rdf/mapping/spreadsheet'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spread2rdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcel Otto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -193,6 +193,7 @@ files:
|
|
193
193
|
- lib/spread2rdf/mapping/default_cell_mappings.rb
|
194
194
|
- lib/spread2rdf/mapping/element.rb
|
195
195
|
- lib/spread2rdf/mapping/resource.rb
|
196
|
+
- lib/spread2rdf/mapping/resource_creation.rb
|
196
197
|
- lib/spread2rdf/mapping/sheet.rb
|
197
198
|
- lib/spread2rdf/mapping/spreadsheet.rb
|
198
199
|
- lib/spread2rdf/mapping/statement.rb
|
@@ -202,6 +203,7 @@ files:
|
|
202
203
|
- lib/spread2rdf/schema/column.rb
|
203
204
|
- lib/spread2rdf/schema/column_block.rb
|
204
205
|
- lib/spread2rdf/schema/element.rb
|
206
|
+
- lib/spread2rdf/schema/resource_creation_schema.rb
|
205
207
|
- lib/spread2rdf/schema/schema.rb
|
206
208
|
- lib/spread2rdf/schema/sheet.rb
|
207
209
|
- lib/spread2rdf/schema/sheet_dsl.rb
|