dbd 0.0.2 → 0.0.3

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: 6c1d692a3ce886178a32b2dd624c2a69b4f380ed
4
- data.tar.gz: 2ec48ccfd39bb4bab04e626eabc002b0b7c18105
3
+ metadata.gz: 3ca38e9fee78b3e02ca2a44da8dbef3e97a85df7
4
+ data.tar.gz: c55cee49db550fd26638ed9663e5e5efd3375351
5
5
  SHA512:
6
- metadata.gz: 1fc7a48c2f7243febf3d8f8e34a6acb658dfc321ee81bae513fbed3635c9a07289f2b3a93a6f2f2c8fa745e367b6581f2afc965d96a3613b901dcb46096c13d9
7
- data.tar.gz: 0130fe663c07bf96352c36ab6e90a6d2bae8cd0731625c71ff2bb49f96c9870ec5daf9dea680aac4946f9044669e0a792e1f452955a49e4f4dd31ef6aed74d3e
6
+ metadata.gz: 14542a1f13ab977fed503fbc3ca4b96b3c67c75262399aea0eb38d18e763d35273f8cd2ed21f6973076fc8304d8444b83454778aa5987eaa00a8dfbfd822001d
7
+ data.tar.gz: 5576b4725d7829b107aee1b025df605e847144938227373bb437d52c2f8e3325ea5d7023f6831bdef6afc4769a0e7d849b09472963c6de36e0f73ea4a798e1ac
data/Guardfile CHANGED
@@ -4,4 +4,5 @@ guard 'rspec' do
4
4
  watch(%r{^lib/dbd/helpers}) { "spec" }
5
5
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
6
6
  watch('spec/spec_helper.rb') { "spec" }
7
+ watch('lib/dbd.rb') { "spec" }
7
8
  end
data/HISTORY.txt CHANGED
@@ -11,3 +11,9 @@
11
11
  * Adding a (Provenance)Resource directly to a Graph with <<
12
12
  * Simplification and cleaner implementations
13
13
  * Adding Fact to a Resource now sets (provenance_)subject
14
+
15
+ 0.0.3 (26 May 2013)
16
+ =====
17
+
18
+ * relax performance spec (on JRuby on Travis can be a bit slower)
19
+ * add (Provenance)Fact#short for easer viewing of fact stream
data/README.md CHANGED
@@ -46,50 +46,54 @@ Open Source [MIT]
46
46
 
47
47
  ## Examples
48
48
 
49
- require 'dbd'
50
-
51
- provenance = Dbd::ProvenanceResource.new
52
-
53
- # PREFIX provenance: <https://data.vandenabeele.com/ontologies/provenance#>
54
- # PREFIX dcterms: <http://purl.org/dc/terms/>
55
- fact_context_public = Dbd::ProvenanceFact.new(predicate: "provenance:context", object: "public")
56
- fact_creator_peter_v = Dbd::ProvenanceFact.new(predicate: "dcterms:creator", object: "@peter_v")
57
- fact_created_at_now = Dbd::ProvenanceFact.new(predicate: "provenance:created_at", object: Time.now.utc)
58
- provenance << fact_context_public
59
- provenance << fact_creator_peter_v
60
- provenance << fact_created_at_now
61
-
62
- nobel_peace_2012 = Dbd::Resource.new(provenance_subject: provenance.subject)
63
-
64
- # PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
65
- # PREFIX base: <https://data.vandenabeele.com/ontologies/base#>
66
- fact_nobel_peace_2012 = Dbd::Fact.new(predicate: "base:nobelPeacePriceWinner", object: "2012")
67
- fact_EU_label = Dbd::Fact.new(predicate: "rdfs:label", object: "EU") # this will use some RDF predicates in future
68
- fact_EU_comment = Dbd::Fact.new(predicate: "rdfs:comment", object: "European Union")
69
- fact_EU_story = Dbd::Fact.new(predicate: "base:story", object: "A long period of peace,\n that is a \"bliss\".")
70
- nobel_peace_2012 << fact_nobel_peace_2012
71
- nobel_peace_2012 << fact_EU_label
72
- nobel_peace_2012 << fact_EU_comment
73
- nobel_peace_2012 << fact_EU_story
74
-
75
- graph = Dbd::Graph.new
76
-
77
- graph << provenance
78
- graph << nobel_peace_2012
79
-
80
- puts graph.to_CSV
81
-
82
- results in
83
-
84
- $ ruby test.rb
85
- "aaf11676-d016-4e74-a502-2db042ea8c67","2013-05-22 21:30:08.830374243 UTC","","3fe37986-0c00-45fb-a574-ed2d0374b3fc","provenance:context","public"
86
- "1fd25f59-b838-4872-a290-4857e783a12c","2013-05-22 21:30:08.830416859 UTC","","3fe37986-0c00-45fb-a574-ed2d0374b3fc","dcterms:creator","@peter_v"
87
- "f118e66a-aa96-4523-ae47-4f9ceff11916","2013-05-22 21:30:08.830434360 UTC","","3fe37986-0c00-45fb-a574-ed2d0374b3fc","provenance:created_at","2013-05-22 21:30:08 UTC"
88
- "c2d29b70-7135-4434-829b-f0640475aeb5","2013-05-22 21:30:08.830450090 UTC","3fe37986-0c00-45fb-a574-ed2d0374b3fc","f628f608-27c3-4eb6-a687-cb121f793a4d","base:nobelPeacePriceWinner","2012"
89
- "9c8048a5-b9e3-459c-9e82-6ae195ce22e6","2013-05-22 21:30:08.830465012 UTC","3fe37986-0c00-45fb-a574-ed2d0374b3fc","f628f608-27c3-4eb6-a687-cb121f793a4d","rdfs:label","EU"
90
- "5e06472d-2146-4933-a31c-90873fa9ed26","2013-05-22 21:30:08.830478065 UTC","3fe37986-0c00-45fb-a574-ed2d0374b3fc","f628f608-27c3-4eb6-a687-cb121f793a4d","rdfs:comment","European Union"
91
- "d984e5c3-8acd-4c50-b40f-4cacf9f8f5c7","2013-05-22 21:30:08.830489061 UTC","3fe37986-0c00-45fb-a574-ed2d0374b3fc","f628f608-27c3-4eb6-a687-cb121f793a4d","base:story","A long period of peace,
92
- that is a ""bliss""."
49
+ ```
50
+ require 'dbd'
51
+
52
+ provenance = Dbd::ProvenanceResource.new
53
+
54
+ # PREFIX prov: <https://data.vandenabeele.com/ontologies/provenance#>
55
+ # PREFIX dcterms: <http://purl.org/dc/terms/>
56
+ fact_context_public = Dbd::ProvenanceFact.new(predicate: "prov:context", object: "public")
57
+ fact_source_dbd = Dbd::ProvenanceFact.new(predicate: "prov:source", object: "http://github.com/petervandenabeele/dbd")
58
+ fact_creator_peter_v = Dbd::ProvenanceFact.new(predicate: "dcterms:creator", object: "@peter_v")
59
+ fact_created_now = Dbd::ProvenanceFact.new(predicate: "dcterms:created", object: Time.now.utc)
60
+ provenance << fact_context_public
61
+ provenance << fact_source_dbd
62
+ provenance << fact_creator_peter_v
63
+ provenance << fact_created_now
64
+
65
+ nobel_peace_2012 = Dbd::Resource.new(provenance_subject: provenance.subject)
66
+
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")
70
+ fact_EU_label = Dbd::Fact.new(predicate: "rdfs:label", object: "EU") # this will use some RDF predicates in future
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\".")
73
+ nobel_peace_2012 << fact_nobel_peace_2012
74
+ nobel_peace_2012 << fact_EU_label
75
+ nobel_peace_2012 << fact_EU_comment
76
+ nobel_peace_2012 << fact_EU_story
77
+
78
+ graph = Dbd::Graph.new
79
+
80
+ graph << provenance
81
+ graph << nobel_peace_2012
82
+
83
+ puts "facts in short representation:"
84
+ 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".
93
+
94
+ puts "facts in full detail in CSV:"
95
+ puts graph.to_CSV
96
+ ```
93
97
 
94
98
  [RDF]: http://www.w3.org/RDF/
95
99
  [Rationale]: http://github.com/petervandenabeele/dbd/blob/master/docs/rationale.md
@@ -3,8 +3,8 @@
3
3
  As a client
4
4
  I can read the predicates for a provenance_fact from provenance ontology
5
5
 
6
- * make an ontology in a separate gem
6
+ * make an ontology in a separate gem (dbd_onto)
7
7
  * import that gem
8
8
  * use this ontology to build a validated Provenance Resource
9
- * use this validate Provenance Resource instance to better buildi
9
+ * use this validate Provenance Resource instance to better build
10
10
  a ProvenanceResource
data/docs/test.rb CHANGED
@@ -2,14 +2,16 @@ require 'dbd'
2
2
 
3
3
  provenance = Dbd::ProvenanceResource.new
4
4
 
5
- # PREFIX provenance: <https://data.vandenabeele.com/ontologies/provenance#>
5
+ # PREFIX prov: <https://data.vandenabeele.com/ontologies/provenance#>
6
6
  # PREFIX dcterms: <http://purl.org/dc/terms/>
7
- fact_context_public = Dbd::ProvenanceFact.new(predicate: "provenance:context", object: "public")
7
+ fact_context_public = Dbd::ProvenanceFact.new(predicate: "prov:context", object: "public")
8
+ fact_source_dbd = Dbd::ProvenanceFact.new(predicate: "prov:source", object: "http://github.com/petervandenabeele/dbd")
8
9
  fact_creator_peter_v = Dbd::ProvenanceFact.new(predicate: "dcterms:creator", object: "@peter_v")
9
- fact_created_at_now = Dbd::ProvenanceFact.new(predicate: "provenance:created_at", object: Time.now.utc)
10
+ fact_created_now = Dbd::ProvenanceFact.new(predicate: "dcterms:created", object: Time.now.utc)
10
11
  provenance << fact_context_public
12
+ provenance << fact_source_dbd
11
13
  provenance << fact_creator_peter_v
12
- provenance << fact_created_at_now
14
+ provenance << fact_created_now
13
15
 
14
16
  nobel_peace_2012 = Dbd::Resource.new(provenance_subject: provenance.subject)
15
17
 
@@ -29,14 +31,25 @@ graph = Dbd::Graph.new
29
31
  graph << provenance
30
32
  graph << nobel_peace_2012
31
33
 
34
+ puts "facts in short representation:"
35
+ 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".
44
+
45
+ puts "facts in full detail in CSV:"
32
46
  puts graph.to_CSV
33
-
34
- # "9f868d99-af27-4d83-86ae-ea5f4a1fa654","2013-05-22 21:25:48.136527770 UTC","","a6e028dd-a340-49ce-b3f8-2f158e257a87","provenance:context","public"
35
- # "28496b40-1891-4bd0-9ee1-0c6c2a878cc1","2013-05-22 21:25:48.136596276 UTC","","a6e028dd-a340-49ce-b3f8-2f158e257a87","dcterms:creator","@peter_v"
36
- # "98b9dd72-3473-4500-814d-d955eec2c5ee","2013-05-22 21:25:48.136621174 UTC","","a6e028dd-a340-49ce-b3f8-2f158e257a87","provenance:created_at","2013-05-22 21:25:40 UTC"
37
- # "a0482b46-414d-40df-b436-41142728fda6","2013-05-22 21:25:55.367834295 UTC","a6e028dd-a340-49ce-b3f8-2f158e257a87","cd66aece-0b21-4e3e-8286-4191efb3aea1","base:nobelPeacePriceWinner","2012"
38
- # "c1af381d-800f-4279-a2cc-ccccf31f5134","2013-05-22 21:25:55.367891996 UTC","a6e028dd-a340-49ce-b3f8-2f158e257a87","cd66aece-0b21-4e3e-8286-4191efb3aea1","rdfs:label","EU"
39
- # "ac08843a-baae-49ea-a725-81b7e199e8f9","2013-05-22 21:25:55.367910018 UTC","a6e028dd-a340-49ce-b3f8-2f158e257a87","cd66aece-0b21-4e3e-8286-4191efb3aea1","rdfs:comment","European Union"
40
- # "6e91fa40-daa8-45d1-916e-f9b243d01f2c","2013-05-22 21:25:55.367928936 UTC","a6e028dd-a340-49ce-b3f8-2f158e257a87","cd66aece-0b21-4e3e-8286-4191efb3aea1","base:story","A long period of peace,
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,
41
55
  # that is a ""bliss""."
42
-
data/lib/dbd/fact.rb CHANGED
@@ -139,6 +139,15 @@ module Dbd
139
139
  self.class.attributes.map{ |attribute| self.send(attribute) }
140
140
  end
141
141
 
142
+ ##
143
+ # @return [String] a short string representation of a Fact
144
+ def short
145
+ "#{provenance_subject_short} : " \
146
+ "#{subject.to_s[0...8]} : " \
147
+ "#{predicate.to_s.ljust(24, ' ')[0...24]} : " \
148
+ "#{object.to_s[0..60].gsub(/\n/, '_')}"
149
+ end
150
+
142
151
  ##
143
152
  # Executes the required update in used_provenance_subjects.
144
153
  #
@@ -181,5 +190,11 @@ module Dbd
181
190
  "Provenance subject is missing" unless provenance_subject
182
191
  end
183
192
 
193
+ private
194
+
195
+ def provenance_subject_short
196
+ "#{provenance_subject.to_s[0...8]}"
197
+ end
198
+
184
199
  end
185
200
  end
@@ -72,5 +72,9 @@ module Dbd
72
72
  raise ProvenanceError if options[:provenance_subject]
73
73
  end
74
74
 
75
+ def provenance_subject_short
76
+ "[ prov ]"
77
+ end
78
+
75
79
  end
76
80
  end
data/lib/dbd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dbd
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -48,6 +48,14 @@ module Factories
48
48
  object: "European Union")
49
49
  end
50
50
 
51
+ def self.fact_with_newline(provenance_subject = nil, subject = nil)
52
+ factory_for.new(
53
+ provenance_subject: provenance_subject,
54
+ subject: subject,
55
+ predicate: "http://example.org/test/comment",
56
+ object: "A long story\nreally.")
57
+ end
58
+
51
59
  module Collection
52
60
 
53
61
  def self.factory_for_instance
@@ -20,7 +20,7 @@ module Factories
20
20
  factory_for.new(
21
21
  subject: subject,
22
22
  predicate: "https://data.vandenabeele.com/ontologies/provenance#created_by",
23
- object:"peter_v")
23
+ object: "peter_v")
24
24
  end
25
25
 
26
26
  def self.original_source(subject = nil)
@@ -30,5 +30,12 @@ module Factories
30
30
  object: "this has a comma , a newline \n and a double quote \"")
31
31
  end
32
32
 
33
+ def self.created(subject = nil)
34
+ factory_for.new(
35
+ subject: subject,
36
+ predicate: "dcterms:created",
37
+ object: Time.now.utc)
38
+ end
39
+
33
40
  end
34
41
  end
@@ -11,6 +11,7 @@ module Dbd
11
11
  let(:subject_class) { Fact::Subject }
12
12
  let(:fact_1) { Factories::Fact.fact_1(provenance_subject) }
13
13
  let(:fact_2_with_subject) { Factories::Fact.fact_2_with_subject(provenance_subject) }
14
+ let(:fact_with_newline) { Factories::Fact.fact_with_newline(provenance_subject) }
14
15
 
15
16
  describe ".new_subject" do
16
17
  it "creates a new (random) subject" do
@@ -59,7 +60,6 @@ module Dbd
59
60
  end
60
61
 
61
62
  describe "time_stamp=" do
62
-
63
63
  it "checks the type (too easy to try to give a Time arg" do
64
64
  lambda { fact_1.time_stamp = Time.now } . should raise_error(ArgumentError)
65
65
  end
@@ -82,6 +82,19 @@ module Dbd
82
82
  end
83
83
  end
84
84
 
85
+ describe "short" do
86
+ it "for a base fact shows provenance, subj, predicate, object" do
87
+ fact_1.subject = subject
88
+ fact_1.time_stamp = TimeStamp.new
89
+ fact_1.short.should match(/^[0-9a-f]{8} : [0-9a-f]{8} : http:\/\/example\.org\/test\/ : Gandhi$/)
90
+ end
91
+
92
+ it "for a fact with a newline replaces it with a underscore" do
93
+ fact_with_newline.subject = subject
94
+ fact_with_newline.short.should match(/^[0-9a-f]{8} : [0-9a-f]{8} : http:\/\/example\.org\/test\/ : A long story_really.$/)
95
+ end
96
+ end
97
+
85
98
  describe "errors" do
86
99
  it "the factory has no errors" do
87
100
  fact_2_with_subject.errors.should be_empty
@@ -14,6 +14,10 @@ module Dbd
14
14
  Factories::ProvenanceFact.created_by(subject)
15
15
  end
16
16
 
17
+ let(:provenance_fact_created) do
18
+ Factories::ProvenanceFact.created(subject)
19
+ end
20
+
17
21
  describe "#new" do
18
22
  it "has a unique id (new_id.class)" do
19
23
  provenance_fact_1.id.should be_a(id_class)
@@ -48,6 +52,16 @@ module Dbd
48
52
  end
49
53
  end
50
54
 
55
+ describe "short" do
56
+ it "for a provenance fact shows [ prov ], subj, predicate, object" do
57
+ provenance_fact_1.short.should match(/^\[ prov \] : [0-9a-f]{8} : https:\/\/data\.vandenabeel : public$/)
58
+ end
59
+
60
+ it "for a provenance fact with non string object also works" do
61
+ provenance_fact_created.short.should match(/^\[ prov \] : [0-9a-f]{8} : dcterms:created : \d{4}/)
62
+ end
63
+ end
64
+
51
65
  describe "errors" do
52
66
 
53
67
  it "the factory has no errors" 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.2
4
+ version: 0.0.3
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-22 00:00:00.000000000 Z
11
+ date: 2013-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler