dbd_onto 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.txt +6 -0
- data/data/meta.md +6 -5
- data/data/{used_predicates_data.csv → used_schema_predicates_data.csv} +0 -0
- data/data/{used_predicates_list.csv → used_schema_predicates_list.csv} +0 -0
- data/lib/dbd_onto.rb +1 -0
- data/lib/dbd_onto/meta_context.rb +16 -0
- data/lib/dbd_onto/rdf.rb +27 -0
- data/lib/dbd_onto/schema.rb +14 -15
- data/lib/dbd_onto/version.rb +1 -1
- data/spec/lib/dbd_onto/rdf_spec.rb +63 -0
- data/spec/support/meta_context.rb +9 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93ac0ee5f794eb6e4ee9149fd2a2eaa959da5981
|
4
|
+
data.tar.gz: b453f34b146d01ef8a119ec4bfb7a6e3e68e0f21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3faf6a76c3f351c55c747811e6c453959b0931e70ac62f9d10ed592ee4fe494b92e9a75373a34a8d59a7e4ccf7ff980f51c3f8e1e4cf19cb6e120214f0ed09a4
|
7
|
+
data.tar.gz: ec7148d1ac253e12f5c51a114df49c2d79d03bb4d24ee8770eaca6aeb0be53de23b1e0e5b775d62818497c8dca30af7a614e7db6b458bd7c2788ec57601785aa
|
data/HISTORY.txt
CHANGED
data/data/meta.md
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
# Meta ontology
|
2
2
|
|
3
|
-
A first meta ontology is constructed with
|
3
|
+
A first meta ontology is constructed with a few resources as a bootstrap to start defining the rest.
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
It defines this predicate:
|
5
|
+
It defines these predicates:
|
8
6
|
|
9
7
|
* meta:defines_predicate
|
10
8
|
|
9
|
+
As a bootstrap, this ontology defines itself (the predicate is equal to the object).
|
10
|
+
|
11
|
+
* meta:predicate_used
|
12
|
+
|
11
13
|
This predicate determines if a predicate is used in the UI for new resources (Schema.org
|
12
14
|
has a lot of predicate (600 +) and I prefer not to start using them all at once in a first
|
13
15
|
simplistic implementation).
|
14
16
|
|
15
|
-
* meta:predicate_used
|
File without changes
|
File without changes
|
data/lib/dbd_onto.rb
CHANGED
@@ -9,6 +9,10 @@ module DbdOnto
|
|
9
9
|
fixed_context(fixed_schema_context_csv)
|
10
10
|
end
|
11
11
|
|
12
|
+
def rdf_context
|
13
|
+
fixed_context(fixed_rdf_context_csv)
|
14
|
+
end
|
15
|
+
|
12
16
|
private
|
13
17
|
|
14
18
|
def fixed_context(csv_string)
|
@@ -38,5 +42,17 @@ EOS
|
|
38
42
|
"2013-10-14 21:43:42.473845509 UTC","9424e4bc-5922-463b-8fc6-521ca5585c23","","37c0b50f-834e-45f5-a911-e3f2b47fe4b9","dcterms:created","s","2013-10-15 21:56:00 UTC"
|
39
43
|
EOS
|
40
44
|
end
|
45
|
+
|
46
|
+
def fixed_rdf_context_csv
|
47
|
+
<<EOS
|
48
|
+
"2014-04-17 19:23:43.473735776 UTC","b71d95c4-a9a1-4ef2-a257-1cc5a3949c30","","38c0b50f-834e-45f5-a911-e3f2b47fe4b9","context:visibility","s","public"
|
49
|
+
"2014-04-17 19:23:43.473775562 UTC","b71d95c4-a9a1-4ef2-a257-1cc5a3949c31","","38c0b50f-834e-45f5-a911-e3f2b47fe4b9","context:encryption","s","clear"
|
50
|
+
"2014-04-17 19:23:43.473796239 UTC","b71d95c4-a9a1-4ef2-a257-1cc5a3949c32","","38c0b50f-834e-45f5-a911-e3f2b47fe4b9","context:license","s","Copyright 2014 Peter Vandenabeele"
|
51
|
+
"2014-04-17 19:23:43.473812175 UTC","b71d95c4-a9a1-4ef2-a257-1cc5a3949c33","","38c0b50f-834e-45f5-a911-e3f2b47fe4b9","dc:source","s","http://www.w3.org/TR/rdf-schema/"
|
52
|
+
"2014-04-17 19:23:43.473828787 UTC","b71d95c4-a9a1-4ef2-a257-1cc5a3949c34","","38c0b50f-834e-45f5-a911-e3f2b47fe4b9","dc:creator","s","Peter Vandenabeele (@peter_v)"
|
53
|
+
"2014-04-17 19:23:43.473845509 UTC","b71d95c4-a9a1-4ef2-a257-1cc5a3949c35","","38c0b50f-834e-45f5-a911-e3f2b47fe4b9","dcterms:created","s","2014-04-17 19:43:00 UTC"
|
54
|
+
EOS
|
55
|
+
end
|
56
|
+
|
41
57
|
end
|
42
58
|
end
|
data/lib/dbd_onto/rdf.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module DbdOnto
|
2
|
+
class Rdf < Base
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
super
|
6
|
+
self << rdf_context
|
7
|
+
self << rdf_resource
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def rdf_resource
|
13
|
+
::Dbd::Graph.new.from_CSV(rdf_resource_csv)
|
14
|
+
end
|
15
|
+
|
16
|
+
def rdf_resource_csv
|
17
|
+
<<EOS
|
18
|
+
"2014-04-17 19:30:36.627034414 UTC","74eae2a4-06c6-41c1-94b9-298905dcbd00","38c0b50f-834e-45f5-a911-e3f2b47fe4b9","619e69d4-6dad-4b14-bfce-8fd67d8e126c","meta:defines_predicate","s","rdf:type"
|
19
|
+
"2014-04-17 19:30:36.627066056 UTC","74eae2a4-06c6-41c1-94b9-298905dcbd01","38c0b50f-834e-45f5-a911-e3f2b47fe4b9","619e69d4-6dad-4b14-bfce-8fd67d8e126c","rdfs:label","s","RDF type"
|
20
|
+
"2014-04-17 19:30:36.627067056 UTC","74eae2a4-06c6-41c1-94b9-298905dcbd02","38c0b50f-834e-45f5-a911-e3f2b47fe4b9","619e69d4-6dad-4b14-bfce-8fd67d8e126c","dbd:rdf_uri","s","http://www.w3.org/TR/rdf-schema/#ch_type"
|
21
|
+
"2014-04-17 19:30:36.627068056 UTC","74eae2a4-06c6-41c1-94b9-298905dcbd03","38c0b50f-834e-45f5-a911-e3f2b47fe4b9","619e69d4-6dad-4b14-bfce-8fd67d8e126c","rdfs:comment","s","Is used to state that a resource is an instance of a class."
|
22
|
+
"2014-04-17 19:30:36.627069056 UTC","74eae2a4-06c6-41c1-94b9-298905dcbd04","38c0b50f-834e-45f5-a911-e3f2b47fe4b9","619e69d4-6dad-4b14-bfce-8fd67d8e126c","meta:predicate_used","s","true"
|
23
|
+
EOS
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/lib/dbd_onto/schema.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
require 'dbd'
|
2
|
-
|
3
1
|
module DbdOnto
|
4
2
|
class Schema < Base
|
5
3
|
|
6
4
|
def initialize
|
7
5
|
super
|
8
6
|
self << schema_context
|
9
|
-
self << self.class.
|
7
|
+
self << self.class.schema
|
10
8
|
self << self.class.used_predicates
|
11
9
|
self.freeze
|
12
10
|
end
|
@@ -18,21 +16,21 @@ module DbdOnto
|
|
18
16
|
end
|
19
17
|
|
20
18
|
def self.used_predicates_filename
|
21
|
-
File.expand_path('../../../data/
|
19
|
+
File.expand_path('../../../data/used_schema_predicates_data.csv', __FILE__)
|
22
20
|
end
|
23
21
|
|
24
22
|
# performance optimization (a bit ugly, but it works ...)
|
25
|
-
# use a class instance variable to cache the
|
23
|
+
# use a class instance variable to cache the schema
|
26
24
|
# at _load_ time! Also tried "memoization" increases reported
|
27
25
|
# RSpec test time from 0.20 to 0.67 seconds (which could be
|
28
26
|
# relevant, since we really want to minimize the _run-time_
|
29
27
|
# cost after loading the Ruby/Rails app (e.g. in Passenger))
|
30
28
|
|
31
|
-
@
|
29
|
+
@schema = Dbd::Graph.new.from_CSV(File.open(schema_filename))
|
32
30
|
@used_predicates = Dbd::Graph.new.from_CSV(File.open(used_predicates_filename))
|
33
31
|
|
34
|
-
def self.
|
35
|
-
@
|
32
|
+
def self.schema
|
33
|
+
@schema
|
36
34
|
end
|
37
35
|
|
38
36
|
def self.used_predicates
|
@@ -42,13 +40,14 @@ module DbdOnto
|
|
42
40
|
# This code is reused on 2013-10-15 with permission from the ruby-rdf/rdf project
|
43
41
|
# from the file https://github.com/ruby-rdf/rdf/blob/master/lib/rdf/vocab/schema.rb
|
44
42
|
# It was licensed as "public domain" (https://github.com/ruby-rdf/rdf/blob/master/UNLICENSE)
|
45
|
-
def self.
|
43
|
+
def self.generate_schema
|
46
44
|
require 'addressable/uri'
|
47
45
|
require 'rdf/rdfa'
|
48
46
|
v = RDF::Graph.load("http://schema.org/docs/schema_org_rdfa.html", format: :rdfa)
|
49
47
|
|
50
48
|
schema_hash = {}
|
51
49
|
|
50
|
+
# NOTE: it is unclear if this now generates rdf:uri or dbd:rdf_uri as predicates
|
52
51
|
# build the list of schema:predicates
|
53
52
|
v.query(property: RDF.type, object: RDF.Property) do |c|
|
54
53
|
uri = c.subject.to_s
|
@@ -72,8 +71,8 @@ module DbdOnto
|
|
72
71
|
|
73
72
|
# create a graoh with 1 resource per schema:<predicate>
|
74
73
|
# we now save the schema:<predicate>, rdf:uri, rdfs:label and rdfs:comment
|
75
|
-
|
76
|
-
schema_context =
|
74
|
+
schema = Base.new
|
75
|
+
schema_context = schema.schema_context
|
77
76
|
|
78
77
|
schema_hash.each do |schema_predicate, properties_hash|
|
79
78
|
resource = Dbd::Resource.new(context_subject: schema_context.subject)
|
@@ -83,14 +82,14 @@ module DbdOnto
|
|
83
82
|
object_type: 's', # should 'u' for the uri
|
84
83
|
object: object)
|
85
84
|
end
|
86
|
-
|
85
|
+
schema << resource
|
87
86
|
end
|
88
87
|
|
89
|
-
|
88
|
+
schema.to_CSV
|
90
89
|
end
|
91
90
|
|
92
91
|
def self.used_predicates_list_filename
|
93
|
-
File.expand_path('../../../data/
|
92
|
+
File.expand_path('../../../data/used_schema_predicates_list.csv', __FILE__)
|
94
93
|
end
|
95
94
|
|
96
95
|
def self.generate_used_predicates_data
|
@@ -121,7 +120,7 @@ module DbdOnto
|
|
121
120
|
end
|
122
121
|
|
123
122
|
csv_data = used_predicates_graph.to_CSV
|
124
|
-
filename = '/Users/peter_v/Documents/data/github/petervandenabeele/dbd_onto/data/
|
123
|
+
filename = '/Users/peter_v/Documents/data/github/petervandenabeele/dbd_onto/data/used_schema_predicates_data.csv'
|
125
124
|
File.open(filename, 'w') do |file|
|
126
125
|
file << csv_data
|
127
126
|
end
|
data/lib/dbd_onto/version.rb
CHANGED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DbdOnto::Rdf 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
|
+
it 'all facts in the rdf ontology have the rdf_context' do
|
12
|
+
subject.all? do |fact|
|
13
|
+
fact.is_a?(Dbd::ContextFact) ||
|
14
|
+
check_rdf_context?(subject.by_subject(fact.context_subject))
|
15
|
+
end.should be_true
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'properties include' do
|
19
|
+
|
20
|
+
let(:rdf_type_subject) do
|
21
|
+
subject.detect do |fact|
|
22
|
+
fact.predicate == 'meta:defines_predicate' &&
|
23
|
+
fact.object == 'rdf:type'
|
24
|
+
end.subject
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'rdf_type' do
|
28
|
+
|
29
|
+
let(:rdf_type_facts) { subject.by_subject(rdf_type_subject) }
|
30
|
+
|
31
|
+
it 'defines the predicate rdf_type' do
|
32
|
+
rdf_type_subject.should_not be_nil
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'has label "RDF type"' do
|
36
|
+
rdf_type_facts.detect do |fact|
|
37
|
+
begin
|
38
|
+
fact.predicate == 'rdfs:label' &&
|
39
|
+
fact.object == 'RDF type'
|
40
|
+
end
|
41
|
+
end.should_not be_nil
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'has a URI' do
|
45
|
+
rdf_type_facts.detect do |fact|
|
46
|
+
fact.predicate == 'dbd:rdf_uri'
|
47
|
+
end.should_not be_nil
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'has a comment' do
|
51
|
+
rdf_type_facts.detect do |fact|
|
52
|
+
fact.predicate == 'rdfs:comment'
|
53
|
+
end.should_not be_nil
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'is used' do
|
57
|
+
rdf_type_facts.detect do |fact|
|
58
|
+
fact.predicate == 'meta:predicate_used'
|
59
|
+
end.should_not be_nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -19,5 +19,14 @@ module Spec
|
|
19
19
|
meta_context.detect {|p| p.predicate == 'dcterms:created'}
|
20
20
|
end
|
21
21
|
|
22
|
+
def check_rdf_context?(meta_context)
|
23
|
+
meta_context.detect {|p| p.predicate == 'context:visibility' && p.object == 'public'} &&
|
24
|
+
meta_context.detect {|p| p.predicate == 'context:encryption' && p.object == 'clear'} &&
|
25
|
+
meta_context.detect {|p| p.predicate == 'context:license'} &&
|
26
|
+
meta_context.detect {|p| p.predicate == 'dc:source' && p.object == 'http://www.w3.org/TR/rdf-schema/'} &&
|
27
|
+
meta_context.detect {|p| p.predicate == 'dc:creator' && p.object == 'Peter Vandenabeele (@peter_v)'} &&
|
28
|
+
meta_context.detect {|p| p.predicate == 'dcterms:created'}
|
29
|
+
end
|
30
|
+
|
22
31
|
end
|
23
32
|
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.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Vandenabeele
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -172,8 +172,8 @@ files:
|
|
172
172
|
- data/meta.md
|
173
173
|
- data/schema_data.csv
|
174
174
|
- data/schema_predicates_list.csv
|
175
|
-
- data/
|
176
|
-
- data/
|
175
|
+
- data/used_schema_predicates_data.csv
|
176
|
+
- data/used_schema_predicates_list.csv
|
177
177
|
- dbd_onto.gemspec
|
178
178
|
- lib/dbd_onto.rb
|
179
179
|
- lib/dbd_onto/base.rb
|
@@ -181,6 +181,7 @@ files:
|
|
181
181
|
- lib/dbd_onto/dbd.rb
|
182
182
|
- lib/dbd_onto/meta.rb
|
183
183
|
- lib/dbd_onto/meta_context.rb
|
184
|
+
- lib/dbd_onto/rdf.rb
|
184
185
|
- lib/dbd_onto/schema.rb
|
185
186
|
- lib/dbd_onto/version.rb
|
186
187
|
- spec/lib/dbd_onto/base_spec.rb
|
@@ -188,6 +189,7 @@ files:
|
|
188
189
|
- spec/lib/dbd_onto/dbd_spec.rb
|
189
190
|
- spec/lib/dbd_onto/meta_context_spec.rb
|
190
191
|
- spec/lib/dbd_onto/meta_spec.rb
|
192
|
+
- spec/lib/dbd_onto/rdf_spec.rb
|
191
193
|
- spec/lib/dbd_onto/schema_spec.rb
|
192
194
|
- spec/spec_helper.rb
|
193
195
|
- spec/support/meta_context.rb
|
@@ -221,6 +223,7 @@ test_files:
|
|
221
223
|
- spec/lib/dbd_onto/dbd_spec.rb
|
222
224
|
- spec/lib/dbd_onto/meta_context_spec.rb
|
223
225
|
- spec/lib/dbd_onto/meta_spec.rb
|
226
|
+
- spec/lib/dbd_onto/rdf_spec.rb
|
224
227
|
- spec/lib/dbd_onto/schema_spec.rb
|
225
228
|
- spec/spec_helper.rb
|
226
229
|
- spec/support/meta_context.rb
|