dbd 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/Guardfile +3 -2
  3. data/HISTORY.txt +5 -0
  4. data/dbd.gemspec +1 -1
  5. data/docs/stories/013_read_graph_from_CSV.txt +10 -0
  6. data/lib/dbd.rb +1 -1
  7. data/lib/dbd/fact.rb +23 -1
  8. data/lib/dbd/fact/id.rb +3 -3
  9. data/lib/dbd/fact/subject.rb +3 -3
  10. data/lib/dbd/graph.rb +25 -4
  11. data/lib/dbd/provenance_fact.rb +5 -8
  12. data/lib/dbd/provenance_resource.rb +21 -13
  13. data/lib/dbd/{rdf.rb → rdf_base.rb} +0 -0
  14. data/lib/dbd/resource.rb +25 -23
  15. data/lib/dbd/time_stamp.rb +13 -2
  16. data/lib/dbd/version.rb +1 -1
  17. data/spec/factories/fact.rb +23 -0
  18. data/spec/factories/fact/id.rb +14 -0
  19. data/spec/factories/fact/subject.rb +18 -0
  20. data/spec/factories/graph.rb +23 -0
  21. data/spec/factories/provenance_resource.rb +3 -3
  22. data/spec/factories/time_stamp.rb +12 -0
  23. data/spec/lib/dbd/fact/{collection_spec.rb → collection/collection_spec.rb} +0 -0
  24. data/spec/lib/dbd/fact/factory_spec.rb +82 -0
  25. data/spec/lib/dbd/fact/id/factory_spec.rb +20 -0
  26. data/spec/lib/dbd/fact/id/id_spec.rb +27 -0
  27. data/spec/lib/dbd/fact/methods_spec.rb +117 -0
  28. data/spec/lib/dbd/fact/new_spec.rb +91 -0
  29. data/spec/lib/dbd/fact/subject/factory_spec.rb +33 -0
  30. data/spec/lib/dbd/fact/subject/subject_spec.rb +27 -0
  31. data/spec/lib/dbd/graph/add_to_graph_spec.rb +139 -0
  32. data/spec/lib/dbd/graph/factory_spec.rb +33 -0
  33. data/spec/lib/dbd/graph/from_csv_spec.rb +29 -0
  34. data/spec/lib/dbd/{graph_spec.rb → graph/to_csv_spec.rb} +0 -120
  35. data/spec/lib/dbd/helpers/{ordered_set_collection_spec.rb → ordered_set_collection/ordered_set_collection_spec.rb} +0 -0
  36. data/spec/lib/dbd/helpers/{uuid_spec.rb → uuid/uuid_spec.rb} +0 -0
  37. data/spec/lib/dbd/performance_spec.rb +3 -1
  38. data/spec/lib/dbd/provenance_fact/factory_spec.rb +24 -0
  39. data/spec/lib/dbd/provenance_fact/methods_spec.rb +78 -0
  40. data/spec/lib/dbd/provenance_fact/new_spec.rb +51 -0
  41. data/spec/lib/dbd/{provenance_resource_spec.rb → provenance_resource/provenance_resource_spec.rb} +6 -10
  42. data/spec/lib/dbd/{rdf_base_spec.rb → rdf_base/rdf_base_spec.rb} +0 -0
  43. data/spec/lib/dbd/{resource_spec.rb → resource/collection_spec.rb} +8 -47
  44. data/spec/lib/dbd/resource/factory_spec.rb +14 -0
  45. data/spec/lib/dbd/resource/new_spec.rb +44 -0
  46. data/spec/lib/dbd/time_stamp/comparisons_spec.rb +64 -0
  47. data/spec/lib/dbd/time_stamp/factory_spec.rb +17 -0
  48. data/spec/lib/dbd/time_stamp/methods_spec.rb +37 -0
  49. data/spec/lib/dbd/time_stamp/new_spec.rb +38 -0
  50. metadata +66 -29
  51. data/spec/lib/dbd/fact/id_spec.rb +0 -19
  52. data/spec/lib/dbd/fact/subject_spec.rb +0 -19
  53. data/spec/lib/dbd/fact_spec.rb +0 -216
  54. data/spec/lib/dbd/provenance_fact_spec.rb +0 -120
  55. data/spec/lib/dbd/time_stamp_spec.rb +0 -115
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Dbd
4
- class Fact
5
- describe ID do
6
- it ".new creates an ID" do
7
- subject.should be_a(described_class)
8
- end
9
-
10
- it "#to_s is a UUID string" do
11
- subject.to_s.should match(Helpers::UUID.regexp)
12
- end
13
-
14
- it ".regexp has a regexp for the to_s" do
15
- described_class.regexp.should == Helpers::UUID.regexp
16
- end
17
- end
18
- end
19
- end
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Dbd
4
- class Fact
5
- describe Subject do
6
- it ".new creates a Subject" do
7
- subject.should be_a(described_class)
8
- end
9
-
10
- it "#to_s is a UUID string" do
11
- subject.to_s.should match(Helpers::UUID.regexp)
12
- end
13
-
14
- it ".regexp has a regexp for the to_s" do
15
- described_class.regexp.should == Helpers::UUID.regexp
16
- end
17
- end
18
- end
19
- end
@@ -1,216 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Dbd
4
- describe Fact do
5
- let(:provenance_subject) { ProvenanceFact.new_subject }
6
- let(:subject) { described_class.new_subject }
7
- let(:data_predicate) { "http://example.org/test/name" }
8
- let(:string_object_1) { "Gandhi" }
9
- let(:string_object_2) { "Mandela" }
10
- let(:id_class) { Fact::ID }
11
- let(:subject_class) { Fact::Subject }
12
- let(:fact_1) { Factories::Fact.fact_1(provenance_subject) }
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) }
15
-
16
- describe ".new_subject" do
17
- it "creates a new (random) subject" do
18
- described_class.new_subject.should be_a(subject_class)
19
- end
20
-
21
- it "creating a second one is different" do
22
- subject_1 = described_class.new_subject
23
- subject_2 = described_class.new_subject
24
- subject_1.should_not == subject_2
25
- end
26
- end
27
-
28
- describe "create a fact" do
29
- it "has a unique id (id_class)" do
30
- fact_1.id.should be_a(id_class)
31
- end
32
-
33
- it "two facts have different id" do
34
- fact_1.id.should_not == fact_2_with_subject.id
35
- end
36
-
37
- it "new sets the provenance_subject" do
38
- fact_1.provenance_subject.should == provenance_subject
39
- end
40
-
41
- it "new sets the subject" do
42
- fact_2_with_subject.subject.should be_a(subject_class)
43
- end
44
-
45
- it "a nil predicate raises PredicateError" do
46
- lambda do
47
- described_class.new(
48
- predicate: nil,
49
- object: string_object_1)
50
- end.should raise_error(PredicateError)
51
- end
52
-
53
- it "a nil object raises ObjectError" do
54
- lambda do
55
- described_class.new(
56
- predicate: data_predicate,
57
- object: nil)
58
- end.should raise_error(ObjectError)
59
- end
60
- end
61
-
62
- describe "time_stamp=" do
63
- it "checks the type (too easy to try to give a Time arg" do
64
- lambda{ fact_1.time_stamp = Time.now }.should raise_error(ArgumentError)
65
- end
66
-
67
- describe "set_once" do
68
-
69
- let(:time_stamp_now) { TimeStamp.new }
70
-
71
- it "can be set when nil" do
72
- fact_1.time_stamp = time_stamp_now
73
- fact_1.time_stamp.should == time_stamp_now
74
- end
75
-
76
- describe "setting it two times" do
77
- it "with a different value raises a SetOnceError" do
78
- fact_1.time_stamp = time_stamp_now
79
- lambda{ fact_1.time_stamp = (time_stamp_now+1) }.should raise_error(RubyPeterV::SetOnceError)
80
- end
81
- end
82
- end
83
- end
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
-
98
- describe "errors" do
99
- it "the factory has no errors" do
100
- fact_2_with_subject.errors.should be_empty
101
- end
102
-
103
- describe "without provenance_subject" do
104
-
105
- before(:each) do
106
- fact_2_with_subject.stub(:provenance_subject).and_return(nil)
107
- end
108
-
109
- it "errors returns an array with 1 error message" do
110
- fact_2_with_subject.errors.single.should match(/Provenance subject is missing/)
111
- end
112
- end
113
-
114
- describe "without subject" do
115
-
116
- before(:each) do
117
- fact_2_with_subject.stub(:subject).and_return(nil)
118
- end
119
-
120
- it "errors returns an array with an errorm message" do
121
- fact_2_with_subject.errors.single.should match(/Subject is missing/)
122
- end
123
- end
124
- end
125
-
126
- describe "create fact_1" do
127
- describe "with a string object type" do
128
- it "new sets the predicate" do
129
- fact_1.predicate.should == data_predicate
130
- end
131
-
132
- it "new sets the object" do
133
- fact_1.object.should == string_object_1
134
- end
135
- end
136
- end
137
-
138
- describe "attributes and values" do
139
- it "there are 6 attributes" do
140
- described_class.attributes.size.should == 6
141
- end
142
-
143
- it "first attribute is :id" do
144
- described_class.attributes.first.should == :id
145
- end
146
-
147
- it "there are 6 values" do
148
- fact_1.values.size.should == 6
149
- end
150
- end
151
-
152
- describe "update_used_provenance_subjects" do
153
- it "sets the value for provenance_subject to true for a fact" do
154
- h = {}
155
- fact_1.update_used_provenance_subjects(h)
156
- h[fact_1.provenance_subject].should == true
157
- end
158
- end
159
-
160
- describe "factory works" do
161
- it "with explicit provenance_subject" do
162
- fact_2_with_subject.provenance_subject.should be_a(provenance_subject.class)
163
- fact_2_with_subject.subject.should be_a(subject.class)
164
- fact_2_with_subject.predicate.should be_a(data_predicate.class)
165
- fact_2_with_subject.object.should be_a(string_object_1.class)
166
- end
167
-
168
- it "without explicit provenance_subject" do
169
- Factories::Fact.fact_1.provenance_subject.should be_nil
170
- end
171
-
172
- it "fact_2_with_subject should not raise_error" do
173
- Factories::Fact.fact_2_with_subject
174
- end
175
-
176
- it "fact_3_with_subject should not raise_error" do
177
- Factories::Fact.fact_3_with_subject
178
- end
179
-
180
- describe "data_fact" do
181
- describe "without arguments" do
182
- it "has empty provenance_subject" do
183
- Factories::Fact.data_fact.provenance_subject.should be_nil
184
- end
185
-
186
- it "has empty subject" do
187
- Factories::Fact.data_fact.subject.should be_nil
188
- end
189
- end
190
-
191
- describe "with provenance_subject" do
192
- it "has provenance_subject" do
193
- Factories::Fact.data_fact(provenance_subject).
194
- provenance_subject.should == provenance_subject
195
- end
196
-
197
- it "has empty subject" do
198
- Factories::Fact.data_fact(provenance_subject).subject.should be_nil
199
- end
200
- end
201
-
202
- describe "with provenance_subject and subject" do
203
- it "has provenance_subject" do
204
- Factories::Fact.data_fact(provenance_subject, subject).
205
- provenance_subject.should == provenance_subject
206
- end
207
-
208
- it "has subject" do
209
- Factories::Fact.data_fact(provenance_subject, subject).
210
- subject.should == subject
211
- end
212
- end
213
- end
214
- end
215
- end
216
- end
@@ -1,120 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Dbd
4
- describe ProvenanceFact do
5
-
6
- let(:subject) { described_class.new_subject }
7
- let(:id_class) { described_class.new_id.class }
8
-
9
- let(:provenance_fact_1) do
10
- Factories::ProvenanceFact.context(subject)
11
- end
12
-
13
- let(:provenance_fact_2) do
14
- Factories::ProvenanceFact.created_by(subject)
15
- end
16
-
17
- let(:provenance_fact_created) do
18
- Factories::ProvenanceFact.created(subject)
19
- end
20
-
21
- describe "#new" do
22
- it "has a unique id (new_id.class)" do
23
- provenance_fact_1.id.should be_a(id_class)
24
- end
25
-
26
- it "two provenance_facts have different id" do
27
- provenance_fact_1.id.should_not == provenance_fact_2.id
28
- end
29
-
30
- it "has nil provenance_subject" do
31
- provenance_fact_1.provenance_subject.should be_nil
32
- end
33
-
34
- it "has correct subject" do
35
- provenance_fact_1.subject.should == subject
36
- end
37
-
38
- it "has correct predicate" do
39
- provenance_fact_1.predicate.should == "https://data.vandenabeele.com/ontologies/provenance#context"
40
- end
41
-
42
- it "has correct object" do
43
- provenance_fact_1.object.should == "public"
44
- end
45
-
46
- it "raises an ProvenanceError when provenance_subject is present in options hash" do
47
- lambda { described_class.new(
48
- provenance_subject: described_class.new_subject,
49
- predicate: "test",
50
- object: "test") } .
51
- should raise_error ProvenanceError
52
- end
53
- end
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
-
65
- describe "errors" do
66
-
67
- it "the factory has no errors" do
68
- provenance_fact_1.errors.should be_empty
69
- end
70
-
71
- describe "with a provenance_subject" do
72
-
73
- before(:each) do
74
- provenance_fact_1.stub(:provenance_subject).and_return(subject)
75
- end
76
-
77
- it "errors returns an array with 1 error message" do
78
- provenance_fact_1.errors.single.should match(/Provenance subject should not be present in Provenance Fact/)
79
- end
80
- end
81
-
82
- describe "without subject" do
83
-
84
- before(:each) do
85
- provenance_fact_1.stub(:subject).and_return(nil)
86
- end
87
-
88
- it "errors returns an array with an error message" do
89
- provenance_fact_1.errors.single.should match(/Subject is missing/)
90
- end
91
- end
92
- end
93
-
94
- describe "update_used_provenance_subjects" do
95
- it "does nothing for a provenance_fact" do
96
- h = {}
97
- provenance_fact_1.update_used_provenance_subjects(h)
98
- h.should be_empty
99
- end
100
- end
101
-
102
- describe "Factories do not fail" do
103
- it "Factories::ProvenanceFact.context is OK" do
104
- Factories::ProvenanceFact.context.should_not be_nil
105
- end
106
-
107
- it "Factories::ProvenanceFact.created_by is OK" do
108
- Factories::ProvenanceFact.created_by.should_not be_nil
109
- end
110
-
111
- it "Factories::ProvenanceFact.original_source is OK" do
112
- Factories::ProvenanceFact.original_source.should_not be_nil
113
- end
114
-
115
- it "Factories::ProvenanceFact.new_subject is OK" do
116
- Factories::ProvenanceFact.new_subject.should be_a(ProvenanceFact.new_subject.class)
117
- end
118
- end
119
- end
120
- end
@@ -1,115 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Dbd
4
- describe TimeStamp do
5
- describe ".new" do
6
-
7
- let(:time) { Time.now.utc }
8
-
9
- before(:each) do
10
- time
11
- Time.stub(:now).and_return(time)
12
- end
13
-
14
- it "creates a new (random) time_stamp" do
15
- subject # should_not raise_error
16
- end
17
-
18
- it "with :time option, sets that to time" do
19
- near_future = time + 100
20
- time_stamp = described_class.new(time: near_future)
21
- time_stamp.time.should == near_future
22
- end
23
-
24
- it "with :larger_than, sets a time that is strictly and slightly larger than this" do
25
- larger_than = described_class.new(time: time + Rational('500/1000_000')) # 0.5 ms
26
- time_stamp = described_class.new(larger_than: larger_than)
27
- time_stamp.time.should > larger_than.time
28
- (time_stamp.time - larger_than.time).should < Rational('1/1000_000') # 1 us
29
- end
30
-
31
- it "without :larger_than adds some random time to the generated time" do
32
- time_stamp = described_class.new
33
- time_stamp.time.should > time
34
- (time_stamp.time - time).should < Rational('1/1000_000') # 1 us
35
- end
36
- end
37
-
38
- describe ".time_format_regexp" do
39
- it "matches an example string" do
40
- a_time_stamp = "2013-05-16 23:52:38.123456789 UTC"
41
- a_time_stamp.should match(described_class.to_s_regexp)
42
- end
43
- end
44
-
45
- describe "#time to allow comparison" do
46
- it "responds with a time" do
47
- described_class.new.time.should be_a(Time)
48
- end
49
- end
50
-
51
- describe "#to_s" do
52
- it "returns a Time format string" do
53
- subject.to_s.should match(described_class.to_s_regexp)
54
- end
55
- end
56
-
57
- let(:time_stamp_0) { described_class.new(time: Time.new(2013,5,18,12,0,0)) }
58
- let(:time_stamp_1) { described_class.new(time: Time.new(2013,5,18,12,0,0)) }
59
- let(:time_stamp_2) { described_class.new(time: Time.new(2013,5,18,12,0,1)) }
60
-
61
- describe "==" do
62
- it "should be ==" do
63
- time_stamp_0.should == time_stamp_1
64
- end
65
-
66
- it "hash should also be equal" do
67
- time_stamp_0.hash.should == time_stamp_1.hash
68
- end
69
- end
70
-
71
- describe ">" do
72
- it "is true if time_stamp is really larger" do
73
- time_stamp_2.should > time_stamp_1
74
- end
75
- end
76
-
77
- describe "<" do
78
- it "is true if time_stamp is really smaller" do
79
- time_stamp_1.should < time_stamp_2
80
- end
81
- end
82
-
83
- describe ">=" do
84
- it "is true if time_stamp_2 is really larger" do
85
- time_stamp_2.should >= time_stamp_1
86
- end
87
- end
88
-
89
- describe "<=" do
90
- it "is true if time_stamp_1 is really smaller" do
91
- time_stamp_1.should <= time_stamp_2
92
- end
93
- end
94
-
95
- describe "+" do
96
- it "returns a larger time_stamp" do
97
- (subject + 1).should > subject
98
- end
99
-
100
- it "sees a difference of 1 nanosecond" do
101
- (subject + Rational('1/1000_000_000')).should > subject
102
- end
103
- end
104
-
105
- describe "-" do
106
- it "returns the time difference" do
107
- ((subject + 1) - subject).should == 1
108
- end
109
-
110
- it "sees a difference of 1 nanosecond" do
111
- ((subject + Rational('1/1000_000_000')) - subject).should == Rational('1/1_000_000_000')
112
- end
113
- end
114
- end
115
- end