dbd 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ca38e9fee78b3e02ca2a44da8dbef3e97a85df7
4
- data.tar.gz: c55cee49db550fd26638ed9663e5e5efd3375351
3
+ metadata.gz: 52008013920900a7e6910513c2dd0cde838b386b
4
+ data.tar.gz: 0eae581b08f64c6dc3a7f459d6c39d58dff670c5
5
5
  SHA512:
6
- metadata.gz: 14542a1f13ab977fed503fbc3ca4b96b3c67c75262399aea0eb38d18e763d35273f8cd2ed21f6973076fc8304d8444b83454778aa5987eaa00a8dfbfd822001d
7
- data.tar.gz: 5576b4725d7829b107aee1b025df605e847144938227373bb437d52c2f8e3325ea5d7023f6831bdef6afc4769a0e7d849b09472963c6de36e0f73ea4a798e1ac
6
+ metadata.gz: c61721ceb5d4161f317d8e2fa1f2a15cfef35ffac18d0a9c5e536a2929bdb1e744be061619f599bb26045067ccb2bd93bd1e1d0023f394005e628b6261497d71
7
+ data.tar.gz: 16ce5f0c1be7867338e9c0e37a808d260ed9beef25a7d299f6ea575bcf542fb87b79352987e9c90166102167cd1fce353c9ac8057f6f82b5637613697a288a04
data/HISTORY.txt CHANGED
@@ -17,3 +17,8 @@
17
17
 
18
18
  * relax performance spec (on JRuby on Travis can be a bit slower)
19
19
  * add (Provenance)Fact#short for easer viewing of fact stream
20
+
21
+ 0.0.4 (29 May 2013)
22
+ =====
23
+
24
+ * Graph#<< takes recursive collections of Facts
data/README.md CHANGED
@@ -46,30 +46,30 @@ Open Source [MIT]
46
46
 
47
47
  ## Examples
48
48
 
49
+ Also see the file `docs/test.rb`.
50
+
49
51
  ```
50
52
  require 'dbd'
51
53
 
52
54
  provenance = Dbd::ProvenanceResource.new
53
55
 
54
- # PREFIX prov: <https://data.vandenabeele.com/ontologies/provenance#>
55
- # PREFIX dcterms: <http://purl.org/dc/terms/>
56
56
  fact_context_public = Dbd::ProvenanceFact.new(predicate: "prov:context", object: "public")
57
57
  fact_source_dbd = Dbd::ProvenanceFact.new(predicate: "prov:source", object: "http://github.com/petervandenabeele/dbd")
58
58
  fact_creator_peter_v = Dbd::ProvenanceFact.new(predicate: "dcterms:creator", object: "@peter_v")
59
59
  fact_created_now = Dbd::ProvenanceFact.new(predicate: "dcterms:created", object: Time.now.utc)
60
+ fact_license_MIT = Dbd::ProvenanceFact.new(predicate: "prov:license", object: "MIT")
60
61
  provenance << fact_context_public
61
62
  provenance << fact_source_dbd
62
63
  provenance << fact_creator_peter_v
63
64
  provenance << fact_created_now
65
+ provenance << fact_license_MIT
64
66
 
65
67
  nobel_peace_2012 = Dbd::Resource.new(provenance_subject: provenance.subject)
66
68
 
67
- # PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
68
- # PREFIX base: <https://data.vandenabeele.com/ontologies/base#>
69
- fact_nobel_peace_2012 = Dbd::Fact.new(predicate: "base:nobelPeacePriceWinner", object: "2012")
69
+ fact_nobel_peace_2012 = Dbd::Fact.new(predicate: "todo:nobelPeacePriceWinner", object: "2012")
70
70
  fact_EU_label = Dbd::Fact.new(predicate: "rdfs:label", object: "EU") # this will use some RDF predicates in future
71
71
  fact_EU_comment = Dbd::Fact.new(predicate: "rdfs:comment", object: "European Union")
72
- fact_EU_story = Dbd::Fact.new(predicate: "base:story", object: "A long period of peace,\n that is a \"bliss\".")
72
+ fact_EU_story = Dbd::Fact.new(predicate: "todo:story", object: "A long period of peace,\n that is a \"bliss\".")
73
73
  nobel_peace_2012 << fact_nobel_peace_2012
74
74
  nobel_peace_2012 << fact_EU_label
75
75
  nobel_peace_2012 << fact_EU_comment
@@ -77,22 +77,34 @@ nobel_peace_2012 << fact_EU_story
77
77
 
78
78
  graph = Dbd::Graph.new
79
79
 
80
- graph << provenance
81
- graph << nobel_peace_2012
80
+ graph << [provenance, nobel_peace_2012]
82
81
 
83
82
  puts "facts in short representation:"
84
83
  puts graph.map(&:short)
85
- # [ prov ] : bbc2248e : prov:context : public
86
- # [ prov ] : bbc2248e : prov:source : http://github.com/petervandenabeele/dbd
87
- # [ prov ] : bbc2248e : dcterms:creator : @peter_v
88
- # [ prov ] : bbc2248e : dcterms:created : 2013-05-26 22:01:50 UTC
89
- # bbc2248e : 78edb900 : base:nobelPeacePriceWinn : 2012
90
- # bbc2248e : 78edb900 : rdfs:label : EU
91
- # bbc2248e : 78edb900 : rdfs:comment : European Union
92
- # bbc2248e : 78edb900 : base:story : A long period of peace,_ that is a "bliss".
84
+ # facts in short representation:
85
+ # [ prov ] : 78b0d99b : prov:context : public
86
+ # [ prov ] : 78b0d99b : prov:source : http://github.com/petervandenabeele/dbd
87
+ # [ prov ] : 78b0d99b : dcterms:creator : @peter_v
88
+ # [ prov ] : 78b0d99b : dcterms:created : 2013-05-29 22:10:14 UTC
89
+ # [ prov ] : 78b0d99b : prov:license : MIT
90
+ # 78b0d99b : 0db0caee : todo:nobelPeacePriceWinn : 2012
91
+ # 78b0d99b : 0db0caee : rdfs:label : EU
92
+ # 78b0d99b : 0db0caee : rdfs:comment : European Union
93
+ # 78b0d99b : 0db0caee : todo:story : A long period of peace,_ that is a "bliss".
93
94
 
94
95
  puts "facts in full detail in CSV:"
95
96
  puts graph.to_CSV
97
+ # facts in full detail in CSV:
98
+ # "58c33e41-87c7-4403-b058-60e4ebf063ed","2013-05-29 22:10:14.811038737 UTC","","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","prov:context","public"
99
+ # "44f72707-f0af-4e1e-8674-8009aedda826","2013-05-29 22:10:14.811075014 UTC","","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","prov:source","http://github.com/petervandenabeele/dbd"
100
+ # "dd409d99-cdb5-4a99-a3c1-cfb64b1eaa62","2013-05-29 22:10:14.811092335 UTC","","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","dcterms:creator","@peter_v"
101
+ # "a135916e-b055-4da5-805f-6adba927c935","2013-05-29 22:10:14.811105102 UTC","","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","dcterms:created","2013-05-29 22:10:14 UTC"
102
+ # "345d455d-3f2d-4b9e-9084-d866c767feba","2013-05-29 22:10:14.811116493 UTC","","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","prov:license","MIT"
103
+ # "1d49db69-9b7a-49b7-be87-7ca7e88a20f6","2013-05-29 22:10:14.811135641 UTC","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","0db0caee-cc05-4f02-b90e-1ad4e72050a5","todo:nobelPeacePriceWinner","2012"
104
+ # "ce620335-a661-4a72-a932-1fe904f3db8a","2013-05-29 22:10:14.811151313 UTC","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","0db0caee-cc05-4f02-b90e-1ad4e72050a5","rdfs:label","EU"
105
+ # "a694f74b-219d-4e23-936a-5f10b77fe321","2013-05-29 22:10:14.811164540 UTC","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","0db0caee-cc05-4f02-b90e-1ad4e72050a5","rdfs:comment","European Union"
106
+ # "85732e38-79d9-48d0-8611-0bed25883bd3","2013-05-29 22:10:14.811176113 UTC","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","0db0caee-cc05-4f02-b90e-1ad4e72050a5","todo:story","A long period of peace,
107
+ # that is a ""bliss""."
96
108
  ```
97
109
 
98
110
  [RDF]: http://www.w3.org/RDF/
@@ -1,4 +1,4 @@
1
- 011_provenance_fact_predicates_from_provenance_ontology
1
+ 012_provenance_fact_predicates_from_provenance_ontology
2
2
 
3
3
  As a client
4
4
  I can read the predicates for a provenance_fact from provenance ontology
data/docs/test.rb CHANGED
@@ -2,25 +2,23 @@ require 'dbd'
2
2
 
3
3
  provenance = Dbd::ProvenanceResource.new
4
4
 
5
- # PREFIX prov: <https://data.vandenabeele.com/ontologies/provenance#>
6
- # PREFIX dcterms: <http://purl.org/dc/terms/>
7
5
  fact_context_public = Dbd::ProvenanceFact.new(predicate: "prov:context", object: "public")
8
6
  fact_source_dbd = Dbd::ProvenanceFact.new(predicate: "prov:source", object: "http://github.com/petervandenabeele/dbd")
9
7
  fact_creator_peter_v = Dbd::ProvenanceFact.new(predicate: "dcterms:creator", object: "@peter_v")
10
8
  fact_created_now = Dbd::ProvenanceFact.new(predicate: "dcterms:created", object: Time.now.utc)
9
+ fact_license_MIT = Dbd::ProvenanceFact.new(predicate: "prov:license", object: "MIT")
11
10
  provenance << fact_context_public
12
11
  provenance << fact_source_dbd
13
12
  provenance << fact_creator_peter_v
14
13
  provenance << fact_created_now
14
+ provenance << fact_license_MIT
15
15
 
16
16
  nobel_peace_2012 = Dbd::Resource.new(provenance_subject: provenance.subject)
17
17
 
18
- # PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
19
- # PREFIX base: <https://data.vandenabeele.com/ontologies/base#>
20
- fact_nobel_peace_2012 = Dbd::Fact.new(predicate: "base:nobelPeacePriceWinner", object: "2012")
18
+ fact_nobel_peace_2012 = Dbd::Fact.new(predicate: "todo:nobelPeacePriceWinner", object: "2012")
21
19
  fact_EU_label = Dbd::Fact.new(predicate: "rdfs:label", object: "EU") # this will use some RDF predicates in future
22
20
  fact_EU_comment = Dbd::Fact.new(predicate: "rdfs:comment", object: "European Union")
23
- fact_EU_story = Dbd::Fact.new(predicate: "base:story", object: "A long period of peace,\n that is a \"bliss\".")
21
+ fact_EU_story = Dbd::Fact.new(predicate: "todo:story", object: "A long period of peace,\n that is a \"bliss\".")
24
22
  nobel_peace_2012 << fact_nobel_peace_2012
25
23
  nobel_peace_2012 << fact_EU_label
26
24
  nobel_peace_2012 << fact_EU_comment
@@ -28,28 +26,31 @@ nobel_peace_2012 << fact_EU_story
28
26
 
29
27
  graph = Dbd::Graph.new
30
28
 
31
- graph << provenance
32
- graph << nobel_peace_2012
29
+ graph << [provenance, nobel_peace_2012]
33
30
 
34
31
  puts "facts in short representation:"
35
32
  puts graph.map(&:short)
36
- # [ prov ] : bbc2248e : prov:context : public
37
- # [ prov ] : bbc2248e : prov:source : http://github.com/petervandenabeele/dbd
38
- # [ prov ] : bbc2248e : dcterms:creator : @peter_v
39
- # [ prov ] : bbc2248e : dcterms:created : 2013-05-26 22:01:50 UTC
40
- # bbc2248e : 78edb900 : base:nobelPeacePriceWinn : 2012
41
- # bbc2248e : 78edb900 : rdfs:label : EU
42
- # bbc2248e : 78edb900 : rdfs:comment : European Union
43
- # bbc2248e : 78edb900 : base:story : A long period of peace,_ that is a "bliss".
33
+ # facts in short representation:
34
+ # [ prov ] : 78b0d99b : prov:context : public
35
+ # [ prov ] : 78b0d99b : prov:source : http://github.com/petervandenabeele/dbd
36
+ # [ prov ] : 78b0d99b : dcterms:creator : @peter_v
37
+ # [ prov ] : 78b0d99b : dcterms:created : 2013-05-29 22:10:14 UTC
38
+ # [ prov ] : 78b0d99b : prov:license : MIT
39
+ # 78b0d99b : 0db0caee : todo:nobelPeacePriceWinn : 2012
40
+ # 78b0d99b : 0db0caee : rdfs:label : EU
41
+ # 78b0d99b : 0db0caee : rdfs:comment : European Union
42
+ # 78b0d99b : 0db0caee : todo:story : A long period of peace,_ that is a "bliss".
44
43
 
45
44
  puts "facts in full detail in CSV:"
46
45
  puts graph.to_CSV
47
- # "4c825f73-eda9-4b7f-a925-352f079857fb","2013-05-26 22:01:50.446202656 UTC","","bbc2248e-89f0-4480-853d-1dba51f1801d","prov:context","public"
48
- # "09fc0e21-4749-44ab-858b-254dc24ee5a4","2013-05-26 22:01:50.446241720 UTC","","bbc2248e-89f0-4480-853d-1dba51f1801d","prov:source","http://github.com/petervandenabeele/dbd"
49
- # "8db7f62a-d94b-43b1-b3de-827fd0e8b324","2013-05-26 22:01:50.446259428 UTC","","bbc2248e-89f0-4480-853d-1dba51f1801d","dcterms:creator","@peter_v"
50
- # "0a76e215-cca5-44c7-9f58-f093e3ef0da7","2013-05-26 22:01:50.446272919 UTC","","bbc2248e-89f0-4480-853d-1dba51f1801d","dcterms:created","2013-05-26 22:01:50 UTC"
51
- # "fe7c7b67-5344-4e64-a690-49c5e054b862","2013-05-26 22:01:50.446288352 UTC","bbc2248e-89f0-4480-853d-1dba51f1801d","78edb900-0ab7-4dc3-9e00-272de6d47c03","base:nobelPeacePriceWinner","2012"
52
- # "f22bc359-e2e1-4ef1-bd8a-7f6b01d1b703","2013-05-26 22:01:50.446307209 UTC","bbc2248e-89f0-4480-853d-1dba51f1801d","78edb900-0ab7-4dc3-9e00-272de6d47c03","rdfs:label","EU"
53
- # "7ddc9674-fcff-40bf-9fc9-d5ccdf80cfad","2013-05-26 22:01:50.446321315 UTC","bbc2248e-89f0-4480-853d-1dba51f1801d","78edb900-0ab7-4dc3-9e00-272de6d47c03","rdfs:comment","European Union"
54
- # "dc664aee-44cd-4fc8-a6f0-fdcf4242e9c5","2013-05-26 22:01:50.446333480 UTC","bbc2248e-89f0-4480-853d-1dba51f1801d","78edb900-0ab7-4dc3-9e00-272de6d47c03","base:story","A long period of peace,
46
+ # facts in full detail in CSV:
47
+ # "58c33e41-87c7-4403-b058-60e4ebf063ed","2013-05-29 22:10:14.811038737 UTC","","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","prov:context","public"
48
+ # "44f72707-f0af-4e1e-8674-8009aedda826","2013-05-29 22:10:14.811075014 UTC","","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","prov:source","http://github.com/petervandenabeele/dbd"
49
+ # "dd409d99-cdb5-4a99-a3c1-cfb64b1eaa62","2013-05-29 22:10:14.811092335 UTC","","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","dcterms:creator","@peter_v"
50
+ # "a135916e-b055-4da5-805f-6adba927c935","2013-05-29 22:10:14.811105102 UTC","","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","dcterms:created","2013-05-29 22:10:14 UTC"
51
+ # "345d455d-3f2d-4b9e-9084-d866c767feba","2013-05-29 22:10:14.811116493 UTC","","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","prov:license","MIT"
52
+ # "1d49db69-9b7a-49b7-be87-7ca7e88a20f6","2013-05-29 22:10:14.811135641 UTC","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","0db0caee-cc05-4f02-b90e-1ad4e72050a5","todo:nobelPeacePriceWinner","2012"
53
+ # "ce620335-a661-4a72-a932-1fe904f3db8a","2013-05-29 22:10:14.811151313 UTC","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","0db0caee-cc05-4f02-b90e-1ad4e72050a5","rdfs:label","EU"
54
+ # "a694f74b-219d-4e23-936a-5f10b77fe321","2013-05-29 22:10:14.811164540 UTC","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","0db0caee-cc05-4f02-b90e-1ad4e72050a5","rdfs:comment","European Union"
55
+ # "85732e38-79d9-48d0-8611-0bed25883bd3","2013-05-29 22:10:14.811176113 UTC","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","0db0caee-cc05-4f02-b90e-1ad4e72050a5","todo:story","A long period of peace,
55
56
  # that is a ""bliss""."
data/lib/dbd/graph.rb CHANGED
@@ -10,11 +10,11 @@ module Dbd
10
10
  include Fact::Collection
11
11
 
12
12
  ##
13
- # Add a Fact or Resource to the Graph.
13
+ # Add a Fact or Resource or any set recursively.
14
14
  #
15
15
  # This will add a time_stamp to the Facts.
16
- def <<(fact_or_resource)
17
- Array(fact_or_resource).each do |fact|
16
+ def <<(recursive_fact_collection)
17
+ loop_recursively(recursive_fact_collection) do |fact|
18
18
  enforce_strictly_monotonic_time(fact)
19
19
  super(fact)
20
20
  end
@@ -42,5 +42,19 @@ module Dbd
42
42
  fact.time_stamp = TimeStamp.new(larger_than: newest_time_stamp) unless fact.time_stamp
43
43
  end
44
44
 
45
+ def loop_recursively(recursive_collection, &block)
46
+ Array(recursive_collection).each do |fact_or_collection|
47
+ further_recursion_or_stop(fact_or_collection, &block)
48
+ end
49
+ end
50
+
51
+ def further_recursion_or_stop(fact_or_collection, &block)
52
+ if fact_or_collection.respond_to?(:each)
53
+ loop_recursively(fact_or_collection, &block)
54
+ else
55
+ yield(fact_or_collection)
56
+ end
57
+ end
58
+
45
59
  end
46
60
  end
data/lib/dbd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dbd
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -18,6 +18,10 @@ module Dbd
18
18
  let(:subject_regexp) { Fact::Subject.regexp }
19
19
  let(:id_regexp) { Fact::ID.regexp }
20
20
 
21
+ let(:provenance_resource) { Factories::ProvenanceResource.provenance_resource }
22
+ let(:resource) { Factories::Resource.facts_resource(provenance_resource.subject) }
23
+ let(:resource_array) { [provenance_resource, resource]}
24
+
21
25
  describe "create a graph" do
22
26
  it "does not fail" do
23
27
  described_class.new # should_not raise_error
@@ -88,9 +92,6 @@ module Dbd
88
92
 
89
93
  describe "a ProvenanceResource and a Resource" do
90
94
 
91
- let(:provenance_resource) { Factories::ProvenanceResource.provenance_resource }
92
- let(:resource) { Factories::Resource.facts_resource(provenance_resource.subject) }
93
-
94
95
  it "does not fail" do
95
96
  subject << provenance_resource
96
97
  end
@@ -108,6 +109,29 @@ module Dbd
108
109
  subject.last.class.should == Fact
109
110
  end
110
111
  end
112
+
113
+ describe "an array of Resources" do
114
+ it "does not fail" do
115
+ subject << resource_array
116
+ end
117
+
118
+ it "Adds the facts from the provenance_resource and the resource to the graph" do
119
+ subject << resource_array
120
+ subject.first.class.should == ProvenanceFact
121
+ subject.last.class.should == Fact
122
+ subject.size.should == 4
123
+ end
124
+
125
+ it "goes 3 levels over collection deep" do
126
+ subject << [resource_array]
127
+ subject.size.should == 4
128
+ end
129
+
130
+ it "works with different levels deep in 1 collection" do
131
+ subject << [provenance_resource, [[resource]]]
132
+ subject.size.should == 4
133
+ end
134
+ end
111
135
  end
112
136
 
113
137
  describe "#to_CSV with only provenance_facts" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
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-05-26 00:00:00.000000000 Z
11
+ date: 2013-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler