dbd_onto 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/HISTORY.txt +5 -0
- data/data/schema_data.csv +2508 -0
- data/dbd_onto.gemspec +4 -1
- data/lib/dbd_onto/meta_context.rb +18 -3
- data/lib/dbd_onto/schema.rb +78 -0
- data/lib/dbd_onto/version.rb +1 -1
- data/lib/dbd_onto.rb +1 -0
- data/spec/lib/dbd_onto/schema_spec.rb +56 -0
- data/spec/spec_helper.rb +5 -1
- data/spec/support/meta_context.rb +23 -0
- metadata +38 -6
- data/spec/support/meta_provenance.rb +0 -14
data/dbd_onto.gemspec
CHANGED
@@ -23,7 +23,10 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency 'guard-rspec'
|
24
24
|
spec.add_development_dependency 'terminal-notifier-guard'
|
25
25
|
spec.add_development_dependency 'yard'
|
26
|
-
spec.add_runtime_dependency 'rdf'
|
26
|
+
spec.add_runtime_dependency 'rdf', '>= 1.0.9'
|
27
27
|
spec.add_runtime_dependency 'ruby_peter_v', '>= 0.0.11'
|
28
28
|
spec.add_runtime_dependency 'dbd', '>= 0.0.19'
|
29
|
+
# only needed for DbdOnto::Schema.generate
|
30
|
+
spec.add_runtime_dependency 'rdf-rdfa', '>= 1.0.2'
|
31
|
+
spec.add_runtime_dependency 'equivalent-xml'
|
29
32
|
end
|
@@ -2,13 +2,17 @@ module DbdOnto
|
|
2
2
|
module MetaContext
|
3
3
|
|
4
4
|
def meta_context
|
5
|
-
|
5
|
+
fixed_context(fixed_meta_context_csv)
|
6
|
+
end
|
7
|
+
|
8
|
+
def schema_context
|
9
|
+
fixed_context(fixed_schema_context_csv)
|
6
10
|
end
|
7
11
|
|
8
12
|
private
|
9
13
|
|
10
|
-
def
|
11
|
-
graph = Dbd::Graph.new.from_CSV(
|
14
|
+
def fixed_context(csv_string)
|
15
|
+
graph = Dbd::Graph.new.from_CSV(csv_string)
|
12
16
|
subject = graph.subjects.single
|
13
17
|
Dbd::Context.new(subject: subject) << graph
|
14
18
|
end
|
@@ -21,6 +25,17 @@ module DbdOnto
|
|
21
25
|
"2013-09-03 20:54:42.473812175 UTC","c73715de-4cb3-4022-93c6-fb9ec95851be","","36c0b50f-834e-45f5-a911-e3f2b47fe4b9","dc:source","https://github.com/petervandenabeele/dbd/blob/d37360070e7f8e61a19c2bca210c881a151ded75/docs/rationale.md"
|
22
26
|
"2013-09-03 20:54:42.473828787 UTC","3aaa9125-6278-4a70-9a40-7f2baf32ad99","","36c0b50f-834e-45f5-a911-e3f2b47fe4b9","dc:creator","Peter Vandenabeele (@peter_v)"
|
23
27
|
"2013-09-03 20:54:42.473845509 UTC","9324e4bc-5922-463b-8fc6-521ca5585c22","","36c0b50f-834e-45f5-a911-e3f2b47fe4b9","dcterms:created","2013-08-09 21:45:00 UTC"
|
28
|
+
EOS
|
29
|
+
end
|
30
|
+
|
31
|
+
def fixed_schema_context_csv
|
32
|
+
<<EOS
|
33
|
+
"2013-10-14 21:43:42.473735776 UTC","d780b54c-5aad-44a7-9e9e-c8d7a7084276","","37c0b50f-834e-45f5-a911-e3f2b47fe4b9","context:visibility","public"
|
34
|
+
"2013-10-14 21:43:42.473775562 UTC","bf5b97ec-d026-4a73-b8fb-a13995966ec1","","37c0b50f-834e-45f5-a911-e3f2b47fe4b9","context:encryption","clear"
|
35
|
+
"2013-10-14 21:43:42.473796239 UTC","1351e568-f7e6-44bf-b5b0-54c15cefe5e0","","37c0b50f-834e-45f5-a911-e3f2b47fe4b9","context:license","Copyright the sponsors of Schema.org: Google, Inc., Yahoo, Inc., and Microsoft Corporation. Licensed under Creative Commons Attribution-ShareAlike License (version 3.0) (see http://schema.org/docs/terms.html)"
|
36
|
+
"2013-10-14 21:43:42.473812175 UTC","c83715de-4cb3-4022-93c6-fb9ec95851bf","","37c0b50f-834e-45f5-a911-e3f2b47fe4b9","dc:source","http://schema.org"
|
37
|
+
"2013-10-14 21:43:42.473828787 UTC","3baa9125-6278-4a70-9a40-7f2baf32ae00","","37c0b50f-834e-45f5-a911-e3f2b47fe4b9","dc:creator","Peter Vandenabeele (@peter_v)"
|
38
|
+
"2013-10-14 21:43:42.473845509 UTC","9424e4bc-5922-463b-8fc6-521ca5585c23","","37c0b50f-834e-45f5-a911-e3f2b47fe4b9","dcterms:created","2013-10-15 21:56:00 UTC"
|
24
39
|
EOS
|
25
40
|
end
|
26
41
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module DbdOnto
|
2
|
+
class Schema < Base
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
super
|
6
|
+
self << schema_context
|
7
|
+
self << self.class.schema_resource
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def self.filename
|
13
|
+
File.expand_path('../../../data/schema_data.csv', __FILE__)
|
14
|
+
end
|
15
|
+
|
16
|
+
# performance optimization (a bit ugly, but it works ...)
|
17
|
+
# use a class instance variable to cache the schema_resource
|
18
|
+
# at _load_ time! Also tried "memoization" increases reported
|
19
|
+
# RSpec test time from 0.20 to 0.67 seconds (which could be
|
20
|
+
# relevant, since we really want to minimize the _run-time_
|
21
|
+
# cost after loading the Ruby/Rails app (e.g. in Passenger))
|
22
|
+
|
23
|
+
@schema_resource = Dbd::Graph.new.from_CSV(File.open(filename))
|
24
|
+
|
25
|
+
def self.schema_resource
|
26
|
+
@schema_resource
|
27
|
+
end
|
28
|
+
|
29
|
+
# This code is reused on 2013-10-15 with permission from the ruby-rdf/rdf project
|
30
|
+
# from the file https://github.com/ruby-rdf/rdf/blob/master/lib/rdf/vocab/schema.rb
|
31
|
+
# It was licensed as "public domain" (https://github.com/ruby-rdf/rdf/blob/master/UNLICENSE)
|
32
|
+
def self.generate
|
33
|
+
require 'addressable/uri'
|
34
|
+
require 'rdf/rdfa'
|
35
|
+
v = RDF::Graph.load("http://schema.org/docs/schema_org_rdfa.html", format: :rdfa)
|
36
|
+
|
37
|
+
schema_hash = {}
|
38
|
+
|
39
|
+
# build the list of schema:predicates
|
40
|
+
v.query(property: RDF.type, object: RDF.Property) do |c|
|
41
|
+
uri = c.subject.to_s
|
42
|
+
schema_predicate = "schema:#{uri.split('/').last}"
|
43
|
+
schema_hash[schema_predicate] = {
|
44
|
+
'meta:defines_predicate' => schema_predicate,
|
45
|
+
'rdf:uri' => uri}
|
46
|
+
end
|
47
|
+
|
48
|
+
# fill the required properties from the RDF::Graph
|
49
|
+
schema_hash.each do |schema_predicate, properties_hash|
|
50
|
+
v.query(subject: RDF::URI(properties_hash['rdf:uri'])) do |c|
|
51
|
+
case c.predicate
|
52
|
+
when RDF::RDFS.label
|
53
|
+
properties_hash['rdfs:label'] = c.object.to_s
|
54
|
+
when RDF::RDFS.comment
|
55
|
+
properties_hash['rdfs:comment'] = c.object.to_s
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# create a graoh with 1 resource per schema:<predicate>
|
61
|
+
# we now save the schema:<predicate>, rdf:uri, rdfs:label and rdfs:comment
|
62
|
+
schema_resource = Base.new
|
63
|
+
schema_context = schema_resource.schema_context
|
64
|
+
|
65
|
+
schema_hash.each do |schema_predicate, properties_hash|
|
66
|
+
resource = Dbd::Resource.new(context_subject: schema_context.subject)
|
67
|
+
properties_hash.each do |predicate, object|
|
68
|
+
resource << Dbd::Fact.new(
|
69
|
+
predicate: predicate,
|
70
|
+
object: object)
|
71
|
+
end
|
72
|
+
schema_resource << resource
|
73
|
+
end
|
74
|
+
|
75
|
+
schema_resource.to_CSV
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/dbd_onto/version.rb
CHANGED
data/lib/dbd_onto.rb
CHANGED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DbdOnto::Schema do
|
4
|
+
|
5
|
+
include Spec::Context
|
6
|
+
|
7
|
+
it 'is a Dbd::Graph' do
|
8
|
+
subject.should be_a(Dbd::Graph)
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'performance optimalisation: loads from file only once per class load' do
|
12
|
+
it "when calling new twice it does not receive the file load at all" do
|
13
|
+
described_class.should_not_receive(:filename)
|
14
|
+
described_class.new
|
15
|
+
described_class.new
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'all facts in the Schema ontology have the schema_context as context' do
|
20
|
+
subject.all? do |fact|
|
21
|
+
fact.is_a?(Dbd::ContextFact) ||
|
22
|
+
check_schema_context?(subject.by_subject(fact.context_subject))
|
23
|
+
end.should be_true
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'properties include' do
|
27
|
+
|
28
|
+
it 'defines predicate schema:about' do
|
29
|
+
subject.detect do |fact|
|
30
|
+
fact.predicate == 'meta:defines_predicate' &&
|
31
|
+
fact.object == 'schema:about'
|
32
|
+
end.should_not be_nil
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'defines predicate rdf:uri' do
|
36
|
+
subject.detect do |fact|
|
37
|
+
fact.predicate == 'rdf:uri' &&
|
38
|
+
fact.object == 'http://schema.org/unitCode'
|
39
|
+
end.should_not be_nil
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'defines predicate rdfs:label' do
|
43
|
+
subject.detect do |fact|
|
44
|
+
fact.predicate == 'rdfs:label' &&
|
45
|
+
fact.object == 'tickerSymbol'
|
46
|
+
end.should_not be_nil
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'defines predicate rdfs:comment' do
|
50
|
+
subject.detect do |fact|
|
51
|
+
fact.predicate == 'rdfs:comment' &&
|
52
|
+
fact.object == 'The type of tissue sample required for the test.'
|
53
|
+
end.should_not be_nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,8 +2,12 @@ require 'dbd_onto'
|
|
2
2
|
|
3
3
|
# load all support files
|
4
4
|
root = File.expand_path('../', __FILE__)
|
5
|
-
Dir[root + '/support/**/*.rb'].each {|f| require f}
|
5
|
+
Dir[root + '/support/**/*.rb'].each { |f| require f }
|
6
6
|
|
7
7
|
RSpec.configure do |config|
|
8
8
|
config.order = 'random'
|
9
|
+
|
10
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
|
+
config.filter_run focus: true
|
12
|
+
config.run_all_when_everything_filtered = true
|
9
13
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Spec
|
2
|
+
module Context
|
3
|
+
|
4
|
+
def check_context?(meta_context)
|
5
|
+
meta_context.detect {|p| p.predicate == 'context:visibility' && p.object == 'public'} &&
|
6
|
+
meta_context.detect {|p| p.predicate == 'context:encryption' && p.object == 'clear'} &&
|
7
|
+
meta_context.detect {|p| p.predicate == 'context:license'} &&
|
8
|
+
meta_context.detect {|p| p.predicate == 'dc:source'} &&
|
9
|
+
meta_context.detect {|p| p.predicate == 'dc:creator' && p.object == 'Peter Vandenabeele (@peter_v)'} &&
|
10
|
+
meta_context.detect {|p| p.predicate == 'dcterms:created'}
|
11
|
+
end
|
12
|
+
|
13
|
+
def check_schema_context?(meta_context)
|
14
|
+
meta_context.detect {|p| p.predicate == 'context:visibility' && p.object == 'public'} &&
|
15
|
+
meta_context.detect {|p| p.predicate == 'context:encryption' && p.object == 'clear'} &&
|
16
|
+
meta_context.detect {|p| p.predicate == 'context:license'} &&
|
17
|
+
meta_context.detect {|p| p.predicate == 'dc:source' && p.object == 'http://schema.org'} &&
|
18
|
+
meta_context.detect {|p| p.predicate == 'dc:creator' && p.object == 'Peter Vandenabeele (@peter_v)'} &&
|
19
|
+
meta_context.detect {|p| p.predicate == 'dcterms:created'}
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbd_onto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Vandenabeele
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 1.0.9
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 1.0.9
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: ruby_peter_v
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +122,34 @@ dependencies:
|
|
122
122
|
- - '>='
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: 0.0.19
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rdf-rdfa
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 1.0.2
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.0.2
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: equivalent-xml
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
125
153
|
description: Ontologies for Dbd
|
126
154
|
email:
|
127
155
|
- peter@vandenabeele.com
|
@@ -139,19 +167,22 @@ files:
|
|
139
167
|
- LICENSE.txt
|
140
168
|
- README.md
|
141
169
|
- Rakefile
|
170
|
+
- data/schema_data.csv
|
142
171
|
- dbd_onto.gemspec
|
143
172
|
- lib/dbd_onto.rb
|
144
173
|
- lib/dbd_onto/base.rb
|
145
174
|
- lib/dbd_onto/context.rb
|
146
175
|
- lib/dbd_onto/meta.rb
|
147
176
|
- lib/dbd_onto/meta_context.rb
|
177
|
+
- lib/dbd_onto/schema.rb
|
148
178
|
- lib/dbd_onto/version.rb
|
149
179
|
- spec/lib/dbd_onto/base_spec.rb
|
150
180
|
- spec/lib/dbd_onto/context_spec.rb
|
151
181
|
- spec/lib/dbd_onto/meta_context_spec.rb
|
152
182
|
- spec/lib/dbd_onto/meta_spec.rb
|
183
|
+
- spec/lib/dbd_onto/schema_spec.rb
|
153
184
|
- spec/spec_helper.rb
|
154
|
-
- spec/support/
|
185
|
+
- spec/support/meta_context.rb
|
155
186
|
homepage: ''
|
156
187
|
licenses:
|
157
188
|
- MIT
|
@@ -181,6 +212,7 @@ test_files:
|
|
181
212
|
- spec/lib/dbd_onto/context_spec.rb
|
182
213
|
- spec/lib/dbd_onto/meta_context_spec.rb
|
183
214
|
- spec/lib/dbd_onto/meta_spec.rb
|
215
|
+
- spec/lib/dbd_onto/schema_spec.rb
|
184
216
|
- spec/spec_helper.rb
|
185
|
-
- spec/support/
|
217
|
+
- spec/support/meta_context.rb
|
186
218
|
has_rdoc:
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Spec
|
2
|
-
module Context
|
3
|
-
|
4
|
-
def check_context?(meta_context)
|
5
|
-
meta_context.detect {|p| p.predicate == 'context:visibility' && p.object == 'public'} &&
|
6
|
-
meta_context.detect {|p| p.predicate == 'context:encryption' && p.object == 'clear'} &&
|
7
|
-
meta_context.detect {|p| p.predicate == 'context:license'} &&
|
8
|
-
meta_context.detect {|p| p.predicate == 'dc:source'} &&
|
9
|
-
meta_context.detect {|p| p.predicate == 'dc:creator'} &&
|
10
|
-
meta_context.detect {|p| p.predicate == 'dcterms:created'}
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|