dbd 0.0.20 → 0.1.0

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: dee663a858909394b98fac3db46fc8555a2abdcf
4
- data.tar.gz: 0dda169214ad947ac23e4d04f62b60cc0c9dc723
3
+ metadata.gz: 8607ede1e1aa2141008690009048e01e87313607
4
+ data.tar.gz: 44a0801f6e8669750994a76a68792d2dbb6bd050
5
5
  SHA512:
6
- metadata.gz: 79597df1ed60147831542ffaa689123a9706bab7047d07622b772b988fb59e16893dc5c0d2b97b32cfa1ab3656fcb9d13ecb80f2992b2db76e9f0bc5f5cbb8c3
7
- data.tar.gz: 534fe8b6fa1157cd8bcce028a2636518ee4c02f8a5dccc02c213e0b6a653584e0e050f8e137ec23956b503d01d3d1f350d52268ab4f8447f45d0bbb76ed593e6
6
+ metadata.gz: d3dc525ec006473250435416e275e52811e7a12c97fa12e5b2ff13cc012849e8724db670e46714639a6128f996fb1b36e091ee20df71371d4c046cbd1dfc2b3e
7
+ data.tar.gz: dc80a12708710a593fc05990a99dbfc3c6dccd52d1def98f4652b3b7d164f8cc2d0292ae39d5c2531a1bb2ba209da00a85c9eb9351be97be9ff5c313e3ef70bb
@@ -122,3 +122,12 @@
122
122
  ======
123
123
 
124
124
  * Resource can have facts with different context_subjects
125
+
126
+ 0.1.0 (23 Oct 2013)
127
+ =====
128
+
129
+ * Not backwards compatible !
130
+ * Fact now has 7 attributes, added an object_type (required; can be 's','b','r')
131
+ * Graph#subjects method removed
132
+ * Graph#resource_subjects and Graph#Fact::Context.context_subjects added
133
+ * Graph#resources and Graph#contexts added
data/README.md CHANGED
@@ -64,66 +64,68 @@ require 'dbd'
64
64
 
65
65
  context = Dbd::Context.new
66
66
 
67
- context << Dbd::ContextFact.new(predicate: "prov:visibility", object: "public")
68
- context << Dbd::ContextFact.new(predicate: "prov:source", object: "http://github.com/petervandenabeele/dbd")
69
- context << Dbd::ContextFact.new(predicate: "dcterms:creator", object: "@peter_v")
70
- context << Dbd::ContextFact.new(predicate: "dcterms:created", object: Time.now.utc)
71
- context << Dbd::ContextFact.new(predicate: "prov:license", object: "MIT")
67
+ context << Dbd::ContextFact.new(predicate: 'prov:visibility', object_type: 's', object: 'public')
68
+ context << Dbd::ContextFact.new(predicate: 'prov:source', object_type: 's', object: 'http://github.com/petervandenabeele/dbd')
69
+ context << Dbd::ContextFact.new(predicate: 'dcterms:creator', object_type: 's', object: '@peter_v')
70
+ context << Dbd::ContextFact.new(predicate: 'dcterms:created', object_type: 's', object: Time.now.utc)
71
+ context << Dbd::ContextFact.new(predicate: 'prov:license', object_type: 's', object: 'MIT')
72
72
 
73
73
  nobel_peace_2012 = Dbd::Resource.new(context_subject: context.subject)
74
74
 
75
- nobel_peace_2012 << Dbd::Fact.new(predicate: "todo:nobelPeacePriceWinner", object: "2012")
76
- nobel_peace_2012 << Dbd::Fact.new(predicate: "rdfs:label", object: "EU") # this will use some RDF predicates in future
77
- nobel_peace_2012 << Dbd::Fact.new(predicate: "rdfs:comment", object: "European Union")
78
- nobel_peace_2012 << Dbd::Fact.new(predicate: "todo:story", object: "A long period of peace,\n that is a \"bliss\".")
75
+ nobel_peace_2012 << Dbd::Fact.new(predicate: 'todo:nobelPeacePriceWinner', object_type: 's', object: '2012')
76
+ nobel_peace_2012 << Dbd::Fact.new(predicate: 'rdfs:label', object_type: 's', object: 'EU') # this will use some RDF predicates in future
77
+ nobel_peace_2012 << Dbd::Fact.new(predicate: 'rdfs:comment', object_type: 's', object: 'European Union')
78
+ nobel_peace_2012 << Dbd::Fact.new(predicate: 'todo:story', object_type: 's', object: "A long period of peace,\n that is a \"bliss\".")
79
79
 
80
80
  graph = Dbd::Graph.new
81
81
 
82
82
  graph << context << nobel_peace_2012
83
83
 
84
- puts "facts in short representation:"
84
+ puts 'facts in short representation:'
85
85
  puts graph.map(&:short)
86
86
 
87
87
  # facts in short representation:
88
- # [ cont ] : d5ad0ca1 : prov:visibility : public
89
- # [ cont ] : d5ad0ca1 : prov:source : http://github.com/petervandenabeele/dbd
90
- # [ cont ] : d5ad0ca1 : dcterms:creator : @peter_v
91
- # [ cont ] : d5ad0ca1 : dcterms:created : 2013-08-09 20:15:24 UTC
92
- # [ cont ] : d5ad0ca1 : prov:license : MIT
93
- # d5ad0ca1 : dede3cf8 : todo:nobelPeacePriceWinn : 2012
94
- # d5ad0ca1 : dede3cf8 : rdfs:label : EU
95
- # d5ad0ca1 : dede3cf8 : rdfs:comment : European Union
96
- # d5ad0ca1 : dede3cf8 : todo:story : A long period of peace,_ that is a "bliss".
88
+ # [ cont ] : f53e7ac0 : prov:visibility : public
89
+ # [ cont ] : f53e7ac0 : prov:source
90
+ # : http://github.com/petervandenabeele/dbd
91
+ # [ cont ] : f53e7ac0 : dcterms:creator : @peter_v
92
+ # [ cont ] : f53e7ac0 : dcterms:created : 2013-10-22 19:59:20 UTC
93
+ # [ cont ] : f53e7ac0 : prov:license : MIT
94
+ # f53e7ac0 : 3da097f5 : todo:nobelPeacePriceWinn : 2012
95
+ # f53e7ac0 : 3da097f5 : rdfs:label : EU
96
+ # f53e7ac0 : 3da097f5 : rdfs:comment : European Union
97
+ # f53e7ac0 : 3da097f5 : todo:story : A long period of peace,_ that is a "bliss".
97
98
 
98
99
  csv = graph.to_CSV
99
100
 
100
- puts "facts in full detail in CSV:"
101
+ puts 'facts in full detail in CSV:'
101
102
  puts csv
102
103
 
103
104
  # facts in full detail in CSV:
104
- # "2013-08-09 20:15:24.022368550 UTC","9cc48236-cb12-40e8-8641-08407b9a03fb","","d5ad0ca1-645f-41a8-8384-7f411a1f94e2","prov:visibility","public"
105
- # "2013-08-09 20:15:24.022416066 UTC","86afeade-0802-4fe7-b0d7-9a09d5441dbf","","d5ad0ca1-645f-41a8-8384-7f411a1f94e2","prov:source","http://github.com/petervandenabeele/dbd"
106
- # "2013-08-09 20:15:24.022435168 UTC","97d7fd9f-77e1-45e9-bdaa-9a283345c8ec","","d5ad0ca1-645f-41a8-8384-7f411a1f94e2","dcterms:creator","@peter_v"
107
- # "2013-08-09 20:15:24.022449630 UTC","aa0897ce-d5ea-497a-8c4b-3a9339f6cc52","","d5ad0ca1-645f-41a8-8384-7f411a1f94e2","dcterms:created","2013-08-09 20:15:24 UTC"
108
- # "2013-08-09 20:15:24.022463761 UTC","154d2b46-99df-4eaf-8a75-9e3b7d5df2a7","","d5ad0ca1-645f-41a8-8384-7f411a1f94e2","prov:license","MIT"
109
- # "2013-08-09 20:15:24.022480963 UTC","0590f53a-346a-4ece-b510-fc1179e76e05","d5ad0ca1-645f-41a8-8384-7f411a1f94e2","dede3cf8-2d3f-4170-8ce5-3fe7c0db5529","todo:nobelPeacePriceWinner","2012"
110
- # "2013-08-09 20:15:24.022497483 UTC","b28dc6fb-1779-47d3-9109-882075b28d08","d5ad0ca1-645f-41a8-8384-7f411a1f94e2","dede3cf8-2d3f-4170-8ce5-3fe7c0db5529","rdfs:label","EU"
111
- # "2013-08-09 20:15:24.022512505 UTC","5474dbc0-ee47-4e7a-aa0a-cd60f8467d84","d5ad0ca1-645f-41a8-8384-7f411a1f94e2","dede3cf8-2d3f-4170-8ce5-3fe7c0db5529","rdfs:comment","European Union"
112
- # "2013-08-09 20:15:24.022526505 UTC","a8c0a137-8c45-49bf-9a87-5915a24725b9","d5ad0ca1-645f-41a8-8384-7f411a1f94e2","dede3cf8-2d3f-4170-8ce5-3fe7c0db5529","todo:story","A long period of peace,\n that is a ""bliss""."
105
+ # "2013-10-22 19:59:20.797321024 UTC","10909776-cce4-4723-b6ce-1860a4322447","","f53e7ac0-c7b8-4f27-a90d-464faea98c98","prov:visibility","s","public"
106
+ # "2013-10-22 19:59:20.797374506 UTC","c31e582e-2f12-4c75-8593-3ae39b7292a3","","f53e7ac0-c7b8-4f27-a90d-464faea98c98","prov:source","s","http://github.com/petervandenabeele/dbd"
107
+ # "2013-10-22 19:59:20.797406087 UTC","f1822dd9-4863-4f8c-96f0-c3a2bd46f301","","f53e7ac0-c7b8-4f27-a90d-464faea98c98","dcterms:creator","s","@peter_v"
108
+ # "2013-10-22 19:59:20.797422478 UTC","494fc3d8-0968-4b86-a4f9-a4b1d3359d14","","f53e7ac0-c7b8-4f27-a90d-464faea98c98","dcterms:created","s","2013-10-22 19:59:20 UTC"
109
+ # "2013-10-22 19:59:20.797438736 UTC","9f8034b9-4d18-475a-b111-4ab9535e03ac","","f53e7ac0-c7b8-4f27-a90d-464faea98c98","prov:license","s","MIT"
110
+ # "2013-10-22 19:59:20.797456038 UTC","27819476-fbb3-4386-a4a8-dfe9af02ac7a","f53e7ac0-c7b8-4f27-a90d-464faea98c98","3da097f5-2792-4825-8148-286d102b65cc","todo:nobelPeacePriceWinner","s","2012"
111
+ # "2013-10-22 19:59:20.797484871 UTC","9e8c25a2-4a50-4020-81b8-ea1713c87885","f53e7ac0-c7b8-4f27-a90d-464faea98c98","3da097f5-2792-4825-8148-286d102b65cc","rdfs:label","s","EU"
112
+ # "2013-10-22 19:59:20.797499339 UTC","1f048c70-772c-429c-ad9f-6b6633205876","f53e7ac0-c7b8-4f27-a90d-464faea98c98","3da097f5-2792-4825-8148-286d102b65cc","rdfs:comment","s","European # Union"
113
+ # "2013-10-22 19:59:20.797514292 UTC","2c9c5e3c-d8d4-49b4-b133-384cf4a49e83","f53e7ac0-c7b8-4f27-a90d-464faea98c98","3da097f5-2792-4825-8148-286d102b65cc","todo:story","s","A long period of peace,\n that is a ""bliss""."
113
114
 
114
115
  imported_graph = Dbd::Graph.new.from_CSV(csv)
115
116
 
116
117
  puts imported_graph.map(&:short)
117
118
 
118
- # [ cont ] : d5ad0ca1 : prov:visibility : public
119
- # [ cont ] : d5ad0ca1 : prov:source : http://github.com/petervandenabeele/dbd
120
- # [ cont ] : d5ad0ca1 : dcterms:creator : @peter_v
121
- # [ cont ] : d5ad0ca1 : dcterms:created : 2013-08-09 20:15:24 UTC
122
- # [ cont ] : d5ad0ca1 : prov:license : MIT
123
- # d5ad0ca1 : dede3cf8 : todo:nobelPeacePriceWinn : 2012
124
- # d5ad0ca1 : dede3cf8 : rdfs:label : EU
125
- # d5ad0ca1 : dede3cf8 : rdfs:comment : European Union
126
- # d5ad0ca1 : dede3cf8 : todo:story : A long period of peace,_ that is a "bliss".
119
+ # [ cont ] : f53e7ac0 : prov:visibility : public
120
+ # [ cont ] : f53e7ac0 : prov:source
121
+ # : http://github.com/petervandenabeele/dbd
122
+ # [ cont ] : f53e7ac0 : dcterms:creator : @peter_v
123
+ # [ cont ] : f53e7ac0 : dcterms:created : 2013-10-22 19:59:20 UTC
124
+ # [ cont ] : f53e7ac0 : prov:license : MIT
125
+ # f53e7ac0 : 3da097f5 : todo:nobelPeacePriceWinn : 2012
126
+ # f53e7ac0 : 3da097f5 : rdfs:label : EU
127
+ # f53e7ac0 : 3da097f5 : rdfs:comment : European Union
128
+ # f53e7ac0 : 3da097f5 : todo:story : A long period of peace,_ that is a "bliss".
127
129
  ```
128
130
 
129
131
  ## Performance tests on 10 M facts
@@ -32,13 +32,13 @@ FACTS_PER_RESOURCE = 1000
32
32
 
33
33
  count = ARGV[0].to_i
34
34
  unless count > 0
35
- puts "Give a 'count' as first argument."
35
+ puts 'Give a "count" as first argument.'
36
36
  exit(1)
37
37
  end
38
38
 
39
39
  filename = ARGV[1]
40
40
  unless filename
41
- puts "Give a 'filename' as second argument."
41
+ puts 'Give a "filename" as second argument.'
42
42
  exit(1)
43
43
  end
44
44
 
@@ -50,11 +50,17 @@ graph = Dbd::Graph.new
50
50
 
51
51
  (0...count).each do |i|
52
52
  context = Dbd::Context.new
53
- context << Dbd::ContextFact.new(predicate: "prov:test" , object: "A" * 10)
53
+ context << Dbd::ContextFact.new(
54
+ predicate: 'prov:test',
55
+ object_type: 's',
56
+ object: 'A' * 10)
54
57
 
55
58
  resource = Dbd::Resource.new(context_subject: context.subject)
56
59
  (0...FACTS_PER_RESOURCE).each do |j|
57
- resource << Dbd::Fact.new(predicate: "test", object: "#{'B' * 75} #{i * FACTS_PER_RESOURCE + j} \n CD")
60
+ resource << Dbd::Fact.new(
61
+ predicate: 'test',
62
+ object_type: 's',
63
+ object: "#{'B' * 75} #{i * FACTS_PER_RESOURCE + j} \n CD")
58
64
  end
59
65
 
60
66
  graph << context << resource
@@ -2,63 +2,65 @@ require 'dbd'
2
2
 
3
3
  context = Dbd::Context.new
4
4
 
5
- context << Dbd::ContextFact.new(predicate: "prov:visibility", object: "public")
6
- context << Dbd::ContextFact.new(predicate: "prov:source", object: "http://github.com/petervandenabeele/dbd")
7
- context << Dbd::ContextFact.new(predicate: "dcterms:creator", object: "@peter_v")
8
- context << Dbd::ContextFact.new(predicate: "dcterms:created", object: Time.now.utc)
9
- context << Dbd::ContextFact.new(predicate: "prov:license", object: "MIT")
5
+ context << Dbd::ContextFact.new(predicate: 'prov:visibility', object_type: 's', object: 'public')
6
+ context << Dbd::ContextFact.new(predicate: 'prov:source', object_type: 's', object: 'http://github.com/petervandenabeele/dbd')
7
+ context << Dbd::ContextFact.new(predicate: 'dcterms:creator', object_type: 's', object: '@peter_v')
8
+ context << Dbd::ContextFact.new(predicate: 'dcterms:created', object_type: 's', object: Time.now.utc)
9
+ context << Dbd::ContextFact.new(predicate: 'prov:license', object_type: 's', object: 'MIT')
10
10
 
11
11
  nobel_peace_2012 = Dbd::Resource.new(context_subject: context.subject)
12
12
 
13
- nobel_peace_2012 << Dbd::Fact.new(predicate: "todo:nobelPeacePriceWinner", object: "2012")
14
- nobel_peace_2012 << Dbd::Fact.new(predicate: "rdfs:label", object: "EU") # this will use some RDF predicates in future
15
- nobel_peace_2012 << Dbd::Fact.new(predicate: "rdfs:comment", object: "European Union")
16
- nobel_peace_2012 << Dbd::Fact.new(predicate: "todo:story", object: "A long period of peace,\n that is a \"bliss\".")
13
+ nobel_peace_2012 << Dbd::Fact.new(predicate: 'todo:nobelPeacePriceWinner', object_type: 's', object: '2012')
14
+ nobel_peace_2012 << Dbd::Fact.new(predicate: 'rdfs:label', object_type: 's', object: 'EU') # this will use some RDF predicates in future
15
+ nobel_peace_2012 << Dbd::Fact.new(predicate: 'rdfs:comment', object_type: 's', object: 'European Union')
16
+ nobel_peace_2012 << Dbd::Fact.new(predicate: 'todo:story', object_type: 's', object: "A long period of peace,\n that is a \"bliss\".")
17
17
 
18
18
  graph = Dbd::Graph.new
19
19
 
20
20
  graph << context << nobel_peace_2012
21
21
 
22
- puts "facts in short representation:"
22
+ puts 'facts in short representation:'
23
23
  puts graph.map(&:short)
24
24
 
25
25
  # facts in short representation:
26
- # [ cont ] : d5ad0ca1 : prov:visibility : public
27
- # [ cont ] : d5ad0ca1 : prov:source : http://github.com/petervandenabeele/dbd
28
- # [ cont ] : d5ad0ca1 : dcterms:creator : @peter_v
29
- # [ cont ] : d5ad0ca1 : dcterms:created : 2013-08-09 20:15:24 UTC
30
- # [ cont ] : d5ad0ca1 : prov:license : MIT
31
- # d5ad0ca1 : dede3cf8 : todo:nobelPeacePriceWinn : 2012
32
- # d5ad0ca1 : dede3cf8 : rdfs:label : EU
33
- # d5ad0ca1 : dede3cf8 : rdfs:comment : European Union
34
- # d5ad0ca1 : dede3cf8 : todo:story : A long period of peace,_ that is a "bliss".
26
+ # [ cont ] : f53e7ac0 : prov:visibility : public
27
+ # [ cont ] : f53e7ac0 : prov:source
28
+ # : http://github.com/petervandenabeele/dbd
29
+ # [ cont ] : f53e7ac0 : dcterms:creator : @peter_v
30
+ # [ cont ] : f53e7ac0 : dcterms:created : 2013-10-22 19:59:20 UTC
31
+ # [ cont ] : f53e7ac0 : prov:license : MIT
32
+ # f53e7ac0 : 3da097f5 : todo:nobelPeacePriceWinn : 2012
33
+ # f53e7ac0 : 3da097f5 : rdfs:label : EU
34
+ # f53e7ac0 : 3da097f5 : rdfs:comment : European Union
35
+ # f53e7ac0 : 3da097f5 : todo:story : A long period of peace,_ that is a "bliss".
35
36
 
36
37
  csv = graph.to_CSV
37
38
 
38
- puts "facts in full detail in CSV:"
39
+ puts 'facts in full detail in CSV:'
39
40
  puts csv
40
41
 
41
42
  # facts in full detail in CSV:
42
- # "2013-08-09 20:15:24.022368550 UTC","9cc48236-cb12-40e8-8641-08407b9a03fb","","d5ad0ca1-645f-41a8-8384-7f411a1f94e2","prov:visibility","public"
43
- # "2013-08-09 20:15:24.022416066 UTC","86afeade-0802-4fe7-b0d7-9a09d5441dbf","","d5ad0ca1-645f-41a8-8384-7f411a1f94e2","prov:source","http://github.com/petervandenabeele/dbd"
44
- # "2013-08-09 20:15:24.022435168 UTC","97d7fd9f-77e1-45e9-bdaa-9a283345c8ec","","d5ad0ca1-645f-41a8-8384-7f411a1f94e2","dcterms:creator","@peter_v"
45
- # "2013-08-09 20:15:24.022449630 UTC","aa0897ce-d5ea-497a-8c4b-3a9339f6cc52","","d5ad0ca1-645f-41a8-8384-7f411a1f94e2","dcterms:created","2013-08-09 20:15:24 UTC"
46
- # "2013-08-09 20:15:24.022463761 UTC","154d2b46-99df-4eaf-8a75-9e3b7d5df2a7","","d5ad0ca1-645f-41a8-8384-7f411a1f94e2","prov:license","MIT"
47
- # "2013-08-09 20:15:24.022480963 UTC","0590f53a-346a-4ece-b510-fc1179e76e05","d5ad0ca1-645f-41a8-8384-7f411a1f94e2","dede3cf8-2d3f-4170-8ce5-3fe7c0db5529","todo:nobelPeacePriceWinner","2012"
48
- # "2013-08-09 20:15:24.022497483 UTC","b28dc6fb-1779-47d3-9109-882075b28d08","d5ad0ca1-645f-41a8-8384-7f411a1f94e2","dede3cf8-2d3f-4170-8ce5-3fe7c0db5529","rdfs:label","EU"
49
- # "2013-08-09 20:15:24.022512505 UTC","5474dbc0-ee47-4e7a-aa0a-cd60f8467d84","d5ad0ca1-645f-41a8-8384-7f411a1f94e2","dede3cf8-2d3f-4170-8ce5-3fe7c0db5529","rdfs:comment","European Union"
50
- # "2013-08-09 20:15:24.022526505 UTC","a8c0a137-8c45-49bf-9a87-5915a24725b9","d5ad0ca1-645f-41a8-8384-7f411a1f94e2","dede3cf8-2d3f-4170-8ce5-3fe7c0db5529","todo:story","A long period of peace,\n that is a ""bliss""."
43
+ # "2013-10-22 19:59:20.797321024 UTC","10909776-cce4-4723-b6ce-1860a4322447","","f53e7ac0-c7b8-4f27-a90d-464faea98c98","prov:visibility","s","public"
44
+ # "2013-10-22 19:59:20.797374506 UTC","c31e582e-2f12-4c75-8593-3ae39b7292a3","","f53e7ac0-c7b8-4f27-a90d-464faea98c98","prov:source","s","http://github.com/petervandenabeele/dbd"
45
+ # "2013-10-22 19:59:20.797406087 UTC","f1822dd9-4863-4f8c-96f0-c3a2bd46f301","","f53e7ac0-c7b8-4f27-a90d-464faea98c98","dcterms:creator","s","@peter_v"
46
+ # "2013-10-22 19:59:20.797422478 UTC","494fc3d8-0968-4b86-a4f9-a4b1d3359d14","","f53e7ac0-c7b8-4f27-a90d-464faea98c98","dcterms:created","s","2013-10-22 19:59:20 UTC"
47
+ # "2013-10-22 19:59:20.797438736 UTC","9f8034b9-4d18-475a-b111-4ab9535e03ac","","f53e7ac0-c7b8-4f27-a90d-464faea98c98","prov:license","s","MIT"
48
+ # "2013-10-22 19:59:20.797456038 UTC","27819476-fbb3-4386-a4a8-dfe9af02ac7a","f53e7ac0-c7b8-4f27-a90d-464faea98c98","3da097f5-2792-4825-8148-286d102b65cc","todo:nobelPeacePriceWinner","s","2012"
49
+ # "2013-10-22 19:59:20.797484871 UTC","9e8c25a2-4a50-4020-81b8-ea1713c87885","f53e7ac0-c7b8-4f27-a90d-464faea98c98","3da097f5-2792-4825-8148-286d102b65cc","rdfs:label","s","EU"
50
+ # "2013-10-22 19:59:20.797499339 UTC","1f048c70-772c-429c-ad9f-6b6633205876","f53e7ac0-c7b8-4f27-a90d-464faea98c98","3da097f5-2792-4825-8148-286d102b65cc","rdfs:comment","s","European # Union"
51
+ # "2013-10-22 19:59:20.797514292 UTC","2c9c5e3c-d8d4-49b4-b133-384cf4a49e83","f53e7ac0-c7b8-4f27-a90d-464faea98c98","3da097f5-2792-4825-8148-286d102b65cc","todo:story","s","A long period of peace,\n that is a ""bliss""."
51
52
 
52
53
  imported_graph = Dbd::Graph.new.from_CSV(csv)
53
54
 
54
55
  puts imported_graph.map(&:short)
55
56
 
56
- # [ cont ] : d5ad0ca1 : prov:visibility : public
57
- # [ cont ] : d5ad0ca1 : prov:source : http://github.com/petervandenabeele/dbd
58
- # [ cont ] : d5ad0ca1 : dcterms:creator : @peter_v
59
- # [ cont ] : d5ad0ca1 : dcterms:created : 2013-08-09 20:15:24 UTC
60
- # [ cont ] : d5ad0ca1 : prov:license : MIT
61
- # d5ad0ca1 : dede3cf8 : todo:nobelPeacePriceWinn : 2012
62
- # d5ad0ca1 : dede3cf8 : rdfs:label : EU
63
- # d5ad0ca1 : dede3cf8 : rdfs:comment : European Union
64
- # d5ad0ca1 : dede3cf8 : todo:story : A long period of peace,_ that is a "bliss".
57
+ # [ cont ] : f53e7ac0 : prov:visibility : public
58
+ # [ cont ] : f53e7ac0 : prov:source
59
+ # : http://github.com/petervandenabeele/dbd
60
+ # [ cont ] : f53e7ac0 : dcterms:creator : @peter_v
61
+ # [ cont ] : f53e7ac0 : dcterms:created : 2013-10-22 19:59:20 UTC
62
+ # [ cont ] : f53e7ac0 : prov:license : MIT
63
+ # f53e7ac0 : 3da097f5 : todo:nobelPeacePriceWinn : 2012
64
+ # f53e7ac0 : 3da097f5 : rdfs:label : EU
65
+ # f53e7ac0 : 3da097f5 : rdfs:comment : European Union
66
+ # f53e7ac0 : 3da097f5 : todo:story : A long period of peace,_ that is a "bliss".
@@ -6,6 +6,7 @@ module Dbd
6
6
  class ContextError < StandardError ; end
7
7
  class SubjectError < StandardError ; end
8
8
  class PredicateError < StandardError ; end
9
+ class ObjectTypeError < StandardError ; end
9
10
  class ObjectError < StandardError ; end
10
11
 
11
12
  end
@@ -22,20 +22,20 @@ module Dbd
22
22
  # creation of the fact, but it has to increase in strictly monotic
23
23
  # order in a fact stream.
24
24
  #
25
- # * a unique and invariant *id* (a uuid)
25
+ # * a *id* (unique and invariant)
26
26
  #
27
27
  # To allow referencing back to it (e.g. to invalidate it later in a fact stream).
28
+ # The id is implemented as a uuid. In the CSV serialization the 32+4 character
29
+ # representation is used.
28
30
  #
29
31
  # * a *context_subject* (a uuid)
30
32
  #
31
- # The subject of the Context (a set of Contexts with
32
- # the same subject) about this fact. Each Fact, points *back* to a
33
- # Context (the Context must have been fully
34
- # defined, earlier in a fact stream).
33
+ # The subject of the Context (a set of ContextFacts with the same subject)
34
+ # about this fact. Each Fact, points *back* to a Context.
35
35
  #
36
36
  # * a *subject* (a uuid)
37
37
  #
38
- # "About which Resource is this fact?".
38
+ # "About which Resource is this fact?"
39
39
  #
40
40
  # Similar to the subject of an RDF triple, except that this subject is not
41
41
  # a URI, but an abstract uuid (that is world-wide unique and invariant).
@@ -45,17 +45,39 @@ module Dbd
45
45
  #
46
46
  # * a *predicate* (a string)
47
47
  #
48
- # "Which property of the resource are we describing?".
48
+ # "Which property of the resource are we describing?"
49
49
  #
50
50
  # Currently this is a string, but I suggest modeling this similar to predicate
51
51
  # in RDF. Probably more detailed modeling using RDF predicate will follow.
52
52
  #
53
- # * an *object* (a string)
53
+ # * an *object_type* (a short string)
54
+ #
55
+ # "What is the type of the object?"
56
+ #
57
+ # A short string that encodes the type of the object. Based loosely on
58
+ # thrift and RDF (xsd), following types are suggested:
59
+ #
60
+ # data types:
61
+ # * s : String (like xsd:string and thrift string)
62
+ # * b : Boolean (like xsd:boolean and thrift bool) ("true" or "false")
63
+ # * d : Decimal (like xsd:decimal ; not present in thrift)
64
+ # * f : Float (like xsd:double and thrift double)
65
+ # * l : Long Int (like thrift i64 signed 64 bit integer)
66
+ # * t : Time (like xsd:dateTime and Ruby Time (date + time combined))
67
+ #
68
+ # references:
69
+ # * i : ID (currently a UUID, with its 32+4 char representation)
70
+ # * r : Resource (currently a UUID, with its 32+4 char representation)
71
+ # * c : Context (currently a UUID, with its 32+4 char representation)
72
+ # * u : URI (like RDF URI's)
73
+ #
74
+ # In this version, only String, Boolean and Resource are implemented.
75
+ #
76
+ # * an *object* (a value, of type object_type)
54
77
  #
55
78
  # "What is the value of the property of the resource we are describing?".
56
79
  #
57
- # Currently this is a string, but I suggest modeling this similar to object
58
- # in RDF. Probably more detailed modeling using RDF object will follow.
80
+ # Serialized to a string, but can be of any of the object_types.
59
81
  class Fact
60
82
 
61
83
  ##
@@ -65,13 +87,14 @@ module Dbd
65
87
  end
66
88
 
67
89
  ##
68
- # @return [Array] The 6 attributes of a Fact.
90
+ # @return [Array] The 7 attributes of a Fact.
69
91
  def self.attributes
70
92
  [:time_stamp,
71
93
  :id,
72
94
  :context_subject,
73
95
  :subject,
74
96
  :predicate,
97
+ :object_type,
75
98
  :object]
76
99
  end
77
100
 
@@ -115,6 +138,7 @@ module Dbd
115
138
  #
116
139
  # @param [Hash{Symbol => Object}] options
117
140
  # @option options [#to_s] :object Required : the object for this Fact (required)
141
+ # @option options [#to_s] :object_type Required : the object_type for this Fact (required)
118
142
  # @option options [#to_s] :predicate Required : the predicate for this Fact
119
143
  # @option options [String (uuid)] :subject Optional : the subject for this Fact
120
144
  # @option options [String (uuid)] :context_subject Optional : the subject of the Context
@@ -126,23 +150,25 @@ module Dbd
126
150
  @context_subject = options[:context_subject]
127
151
  @subject = options[:subject]
128
152
  @predicate = options[:predicate]
153
+ @object_type = options[:object_type]
129
154
  @object = options[:object]
130
155
  validate_time_stamp_class(@time_stamp)
131
- raise PredicateError, "predicate cannot be nil" if predicate.nil?
132
- raise ObjectError, "object cannot be nil" if object.nil?
156
+ raise PredicateError, "predicate cannot be nil" if @predicate.nil?
157
+ raise ObjectTypeError, "object_type cannot be nil" if @object_type !~ /^(s|b|r)$/
158
+ raise ObjectError, "object cannot be nil" if @object.nil?
133
159
  end
134
160
 
135
161
  ##
136
- # @return [Array] The 6 values of a Fact.
162
+ # @return [Array] The 7 values of a Fact.
137
163
  def values
138
164
  self.class.attributes.map{ |attribute| self.send(attribute) }
139
165
  end
140
166
 
141
167
  ##
142
- # @return [Array] The 6 values of a Fact converted to a string.
168
+ # @return [Array] The 7 values of a Fact converted to a string.
143
169
  # The individual strings are escaped:
144
170
  # * newlines are escaped to '\n'
145
- # This is used for the 6 entries in the to_CSV mapping.
171
+ # This is used for the 7 entries in the to_CSV mapping.
146
172
  #
147
173
  def string_values
148
174
  values.map{ |value| escaped_string(value.to_s) }
@@ -8,7 +8,8 @@ module Dbd
8
8
 
9
9
  def initialize
10
10
  super
11
- @hash_by_subject = Hash.new { |h, k| h[k] = [] }
11
+ @resource_indices_by_subject = {}
12
+ @context_indices_by_subject = {}
12
13
  end
13
14
 
14
15
  def newest_time_stamp
@@ -38,27 +39,71 @@ module Dbd
38
39
  def <<(fact)
39
40
  raise FactError, "#{fact.errors.join(', ')}." unless fact.errors.empty?
40
41
  validate_time_stamp(fact)
41
- index = Helpers::OrderedSetCollection.add_and_return_index(fact, @internal_collection)
42
- @hash_by_subject[fact.subject] << index
42
+ add_to_collection(fact)
43
43
  self
44
44
  end
45
45
 
46
+ ##
47
+ # This method works on resource and context subjects.
48
+ #
49
+ # Should be less relevant, now that resources and contexts
50
+ # are available as methods to get proper access.
46
51
  def by_subject(fact_subject)
47
- @hash_by_subject[fact_subject].map{ |index| @internal_collection[index]}
52
+ hash_entry_from_indices(fact_subject).map do |index|
53
+ @internal_collection[index]
54
+ end
55
+ end
56
+
57
+ ##
58
+ # Use this to get all resource subjects. But if the resources
59
+ # themselves are needed, there is a direct Graph#resources method.
60
+ def resource_subjects
61
+ @resource_indices_by_subject.keys
48
62
  end
49
63
 
50
- def subjects
51
- @hash_by_subject.keys
64
+ ##
65
+ # Use this to get all contexte subjects. But if the contexts
66
+ # themselves are needed, there is a direct Graph#contexts method.
67
+ def context_subjects
68
+ @context_indices_by_subject.keys
52
69
  end
53
70
 
54
71
  private
55
72
 
73
+ ##
74
+ # Because the subject are either in the resource or the context index,
75
+ # we need to search both. A subject should never be in both, but we
76
+ # do currently not defend against that error.
77
+ def hash_entry_from_indices(fact_subject)
78
+ @resource_indices_by_subject[fact_subject] || @context_indices_by_subject[fact_subject]
79
+ end
80
+
56
81
  def validate_time_stamp(fact)
57
82
  if (newest_time_stamp && fact.time_stamp <= newest_time_stamp)
58
- raise OutOfOrderError, "time_stamp of fact was too old : #{fact.time_stamp}"
83
+ raise OutOfOrderError, "time_stamp of fact was too old : #{fact.time_stamp}"
59
84
  end
60
85
  end
61
86
 
87
+ def add_to_collection(fact)
88
+ index = Helpers::OrderedSetCollection.add_and_return_index(fact, @internal_collection)
89
+ add_to_index_hash(fact, index)
90
+ end
91
+
92
+ def add_to_index_hash(fact, index)
93
+ if fact.context_fact?
94
+ add_to_index_hash_with_default_array(@context_indices_by_subject, fact.subject, index)
95
+ else
96
+ add_to_index_hash_with_default_array(@resource_indices_by_subject, fact.subject, index)
97
+ end
98
+ end
99
+
100
+ def add_to_index_hash_with_default_array(index_hash, subject, index)
101
+ if (array = index_hash[subject])
102
+ array << index
103
+ else
104
+ index_hash[subject] = [index]
105
+ end
106
+ end
62
107
  end
63
108
  end
64
109
  end
@@ -34,15 +34,15 @@ module Dbd
34
34
  fact_from_values_hash(values_hash(string_hash))
35
35
  end
36
36
 
37
+ ##
38
+ # Formats for checking CSV fields
39
+ # the predicate, object_type and object are tested in the initializer
37
40
  def attribute_formats
38
- # TODO clean this up
39
41
  {
40
42
  id: [true, Fact::ID.valid_regexp],
41
43
  time_stamp: [true, TimeStamp.valid_regexp],
42
44
  context_subject: [false, Fact::Subject.valid_regexp],
43
- subject: [true, Fact::Subject.valid_regexp],
44
- predicate: [true, /./],
45
- object: [true, /./]
45
+ subject: [true, Fact::Subject.valid_regexp]
46
46
  }
47
47
  end
48
48
 
@@ -64,7 +64,7 @@ module Dbd
64
64
  unescaped_values = unescaped_string_values(string_values)
65
65
  attributes_strings_array = [top_class.attributes, unescaped_values].transpose
66
66
  # Remove empty values (e.g. the context_subject for a ContextFact).
67
- attributes_strings_array.delete_if{ |a, v| v == '' }
67
+ attributes_strings_array.delete_if{ |_, v| v == '' }
68
68
  Hash[attributes_strings_array]
69
69
  end
70
70
 
@@ -86,16 +86,21 @@ module Dbd
86
86
  attribute_formats.each do |attr, validation|
87
87
  string = string_hash[attr]
88
88
  mandatory, format = validation
89
- validate_string(mandatory, string, format)
89
+ validate_string_by_regexp(mandatory, string, format)
90
90
  end
91
+
91
92
  end
92
93
 
93
- def validate_string(mandatory, string, format)
94
+ def validate_string_by_regexp(mandatory, string, format)
94
95
  if (mandatory || string) && (string !~ format)
95
- raise FactError, "invalid entry found : #{string}"
96
+ report_invalid_entry(string)
96
97
  end
97
98
  end
98
99
 
100
+ def report_invalid_entry(string)
101
+ raise FactError, "invalid entry found : #{string}"
102
+ end
103
+
99
104
  end
100
105
  end
101
106
  end
@@ -90,23 +90,23 @@ module Dbd
90
90
  #
91
91
  # @return [Array] array with all resources
92
92
  def resources
93
- subjects.map do |subject|
94
- facts = by_subject(subject)
95
- resource_from_facts(subject, facts)
96
- end.compact
93
+ @resource_indices_by_subject.map do |subject, fact_indices|
94
+ Resource.new(subject: subject) << facts_from_indices(fact_indices)
95
+ end
97
96
  end
98
97
 
99
- private
100
-
101
- # FIXME : the context_subject argument must not be given here
102
- def resource_from_facts(subject, facts)
103
- unless facts.first.is_a?(ContextFact)
104
- context_subject = facts.first.context_subject
105
- resource = Resource.new(subject: subject, context_subject: context_subject)
106
- resource << facts
98
+ ##
99
+ # Return an array of contexts for graph
100
+ #
101
+ # @return [Array] array with all contexts
102
+ def contexts
103
+ @context_indices_by_subject.map do |subject, fact_indices|
104
+ Context.new(subject: subject) << facts_from_indices(fact_indices)
107
105
  end
108
106
  end
109
107
 
108
+ private
109
+
110
110
  ##
111
111
  # Setting a strictly monotonically increasing time_stamp (if not yet set).
112
112
  # The time_stamp also has some randomness (1 .. 999 ns) to reduce the
@@ -115,17 +115,34 @@ module Dbd
115
115
  fact.time_stamp = TimeStamp.new(larger_than: newest_time_stamp) unless fact.time_stamp
116
116
  end
117
117
 
118
+ ##
119
+ # Reach deep into the @internal_collection for the facts.
120
+ # In later implementations with external stores, this
121
+ # will probably change.
122
+ def facts_from_indices(fact_indices)
123
+ fact_indices.map do |index|
124
+ @internal_collection[index]
125
+ end
126
+ end
127
+
118
128
  def csv_defaults
119
- {force_quotes: true,
120
- encoding: 'utf-8'}
129
+ { force_quotes: true,
130
+ encoding: 'utf-8' }
121
131
  end
122
132
 
133
+ ##
134
+ # Reach deep into the @internal_collection for the facts.
135
+ # In later implementations with external stores, this
136
+ # will probably change.
123
137
  def push_facts(target)
124
138
  @internal_collection.each do |fact|
125
139
  target << fact.string_values
126
140
  end
127
141
  end
128
142
 
143
+ ##
144
+ # It seems that sometimes temp files are not properly
145
+ # cleaned up.
129
146
  def on_sorted_file(filename)
130
147
  Tempfile.open('foo', 'data/') do |sorted_file|
131
148
  create_sorted_file(filename, sorted_file)
@@ -1,3 +1,3 @@
1
1
  module Dbd
2
- VERSION = "0.0.20"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -53,12 +53,12 @@ module Dbd
53
53
  end
54
54
 
55
55
  describe 'attributes and values' do
56
- it 'there are 6 attributes' do
57
- described_class.attributes.size.should == 6
56
+ it 'there are 7 attributes' do
57
+ described_class.attributes.size.should == 7
58
58
  end
59
59
 
60
- it 'there are 6 values' do
61
- context_fact_1.values.size.should == 6
60
+ it 'there are 7 values' do
61
+ context_fact_1.values.size.should == 7
62
62
  end
63
63
  end
64
64
 
@@ -62,10 +62,6 @@ module Dbd
62
62
  subject << fact_2_with_subject
63
63
  lambda { subject[0] } . should raise_exception NoMethodError
64
64
  end
65
-
66
- it '#<< returns self, so chaining is possible' do
67
- (subject << fact_2_with_subject).should == subject
68
- end
69
65
  end
70
66
 
71
67
  describe 'adding a fact with a ref to a context_fact' do
@@ -147,7 +143,7 @@ module Dbd
147
143
 
148
144
  it 'raises FactError with message when fact.errors has errors' do
149
145
  context_fact_visibility.stub(:errors).and_return(['Error 1', 'Error 2'])
150
- lambda { subject << context_fact_visibility } . should raise_error(
146
+ lambda { subject << context_fact_visibility }.should raise_error(
151
147
  FactError,
152
148
  'Error 1, Error 2.')
153
149
  end
@@ -158,24 +154,36 @@ module Dbd
158
154
  subject << context_fact_visibility
159
155
  subject << context_fact_created_by
160
156
  subject << context_fact_original_source
157
+ subject << fact_2_with_subject
161
158
  context_fact_visibility.subject.should == context_subject_1 # assert test set-up
162
159
  context_fact_created_by.subject.should == context_subject_1 # assert test set-up
163
160
  context_fact_original_source.subject.should == context_subject_2 # assert test set-up
164
161
  subject.by_subject(context_subject_1).first.should == context_fact_visibility
165
162
  subject.by_subject(context_subject_1).last.should == context_fact_created_by
166
163
  subject.by_subject(context_subject_2).single.should == context_fact_original_source
164
+ subject.by_subject(fact_2_with_subject.subject).single.should == fact_2_with_subject
165
+ end
166
+ end
167
+
168
+ describe 'resource_subjects : ' do
169
+ it 'finds all and only subjects of resources' do
170
+ subject << context_fact_visibility
171
+ subject << context_fact_created_by # same subject as previous line
172
+ subject << fact_2_with_subject
173
+ subject << fact_3_with_subject
174
+ subject.resource_subjects.first.should == fact_2_with_subject.subject
175
+ subject.resource_subjects.last.should == fact_3_with_subject.subject
176
+ subject.resource_subjects.size.should == 2
167
177
  end
168
178
  end
169
179
 
170
- describe 'subjects : ' do
171
- it 'finds all subjects' do
180
+ describe 'context_subjects : ' do
181
+ it 'finds all and only subjects of contexts' do
172
182
  subject << context_fact_visibility
173
183
  subject << context_fact_created_by # same subject as previous line
174
184
  subject << fact_2_with_subject
175
185
  subject << fact_3_with_subject
176
- subject.subjects.first.should == context_fact_visibility.subject
177
- subject.subjects.last.should == fact_3_with_subject.subject
178
- subject.subjects.size.should == 3
186
+ subject.context_subjects.single.should == context_fact_visibility.subject
179
187
  end
180
188
  end
181
189
 
@@ -78,34 +78,53 @@ module Dbd
78
78
  end
79
79
 
80
80
  describe 'does raise exception' do
81
+
82
+ def should_raise_fact_error
83
+ lambda{ with_validation(string_values) }.should raise_error(FactError)
84
+ end
85
+
86
+ def should_raise_object_type_error
87
+ lambda{ with_validation(string_values) }.should raise_error(ObjectTypeError)
88
+ end
89
+
81
90
  it 'for invalid id' do
82
91
  string_values[0] = 'foo'
83
- lambda{ with_validation(string_values) }.should raise_error(FactError)
92
+ should_raise_fact_error
84
93
  end
85
94
 
86
95
  it 'for invalid time_stamp' do
87
96
  string_values[1] = 'foo'
88
- lambda{ with_validation(string_values) }.should raise_error(FactError)
97
+ should_raise_fact_error
89
98
  end
90
99
 
91
100
  it 'for invalid context_subject' do
92
101
  string_values[2] = 'foo'
93
- lambda{ with_validation(string_values) }.should raise_error(FactError)
102
+ should_raise_fact_error
94
103
  end
95
104
 
96
105
  it 'for invalid subject' do
97
106
  string_values[3] = 'foo'
98
- lambda{ with_validation(string_values) }.should raise_error(FactError)
107
+ should_raise_fact_error
99
108
  end
100
109
 
101
110
  it 'for invalid predicate' do
102
111
  string_values[4] = ''
103
- lambda{ with_validation(string_values) }.should raise_error(FactError)
112
+ lambda{ with_validation(string_values) }.should raise_error(PredicateError)
113
+ end
114
+
115
+ it 'for invalid object_type' do
116
+ string_values[5] = 'sb'
117
+ should_raise_object_type_error
118
+ end
119
+
120
+ it 'for other invalid object_type' do
121
+ string_values[5] = 'int'
122
+ should_raise_object_type_error
104
123
  end
105
124
 
106
125
  it 'for invalid object' do
107
- string_values[5] = ''
108
- lambda{ with_validation(string_values) }.should raise_error(FactError)
126
+ string_values[6] = ''
127
+ lambda{ with_validation(string_values) }.should raise_error(ObjectError)
109
128
  end
110
129
  end
111
130
  end
@@ -111,7 +111,7 @@ module Dbd
111
111
 
112
112
  describe 'attributes' do
113
113
  it 'there are 6 attributes' do
114
- described_class.attributes.size.should == 6
114
+ described_class.attributes.size.should == 7
115
115
  end
116
116
 
117
117
  it 'first attribute is :time_stamp' do
@@ -124,8 +124,8 @@ module Dbd
124
124
  end
125
125
 
126
126
  describe 'values' do
127
- it 'there are 6 values' do
128
- full_fact.values.size.should == 6
127
+ it 'there are 7 values' do
128
+ full_fact.values.size.should == 7
129
129
  end
130
130
 
131
131
  it 'the first element (time_stamp) is a TimeStamp' do
@@ -134,8 +134,8 @@ module Dbd
134
134
  end
135
135
 
136
136
  describe 'string_values' do
137
- it 'there are 6 string_values' do
138
- full_fact.string_values.size.should == 6
137
+ it 'there are 7 string_values' do
138
+ full_fact.string_values.size.should == 7
139
139
  end
140
140
 
141
141
  it 'the first element (time_stamp) is a String' do
@@ -168,13 +168,21 @@ module Dbd
168
168
  end
169
169
 
170
170
  it 'is false for each of the entries largely different' do
171
- (0...string_values.size).each do |index|
171
+ ((0...string_values.size).to_a - [5]).each do |index|
172
172
  string_values_1_modified = string_values.dup.tap { |_string_values|
173
173
  _string_values[index][3] = '4' # different and valid for all cases
174
174
  }
175
- other = factory.from_string_values(string_values_1_modified)
176
- other.should_not be_equivalent(ref)
175
+ should_not_be_equivalent(string_values_1_modified, ref)
177
176
  end
177
+
178
+ string_values_1_modified = string_values.dup
179
+ string_values_1_modified[5] = 'r'
180
+ should_not_be_equivalent(string_values_1_modified, ref)
181
+ end
182
+
183
+ def should_not_be_equivalent(modified, ref)
184
+ other = factory.from_string_values(modified)
185
+ other.should_not be_equivalent(ref)
178
186
  end
179
187
 
180
188
  it 'is true when the time_stamp is 500 ns larger' do
@@ -50,6 +50,7 @@ module Dbd
50
50
  lambda do
51
51
  described_class.new(
52
52
  predicate: nil,
53
+ object_type: 's',
53
54
  object: string_object_1)
54
55
  end.should raise_error(PredicateError)
55
56
  end
@@ -58,9 +59,18 @@ module Dbd
58
59
  lambda do
59
60
  described_class.new(
60
61
  predicate: data_predicate,
62
+ object_type: 's',
61
63
  object: nil)
62
64
  end.should raise_error(ObjectError)
63
65
  end
66
+
67
+ it 'an nil object_type raises ObjectError' do
68
+ lambda do
69
+ described_class.new(
70
+ predicate: data_predicate,
71
+ object: 'foo')
72
+ end.should raise_error(ObjectTypeError)
73
+ end
64
74
  end
65
75
 
66
76
  describe 'create fact_1' do
@@ -8,6 +8,8 @@ module TestFactories
8
8
  let(:string_object_1) { 'Gandhi' }
9
9
  let(:fact_2_with_subject) { described_class.fact_2_with_subject(context_subject) }
10
10
  let(:full_fact) { described_class.full_fact }
11
+ let(:fact_with_boolean_object) { described_class.fact_with_boolean_object }
12
+ let(:fact_with_resource_object) { described_class.fact_with_resource_object }
11
13
 
12
14
  describe 'factory works' do
13
15
  it 'with explicit context_subject' do
@@ -64,6 +66,20 @@ module TestFactories
64
66
  end
65
67
  end
66
68
 
69
+ describe 'fact_with_boolean_object' do
70
+ it 'has "b" as object_type' do
71
+ described_class.fact_with_boolean_object(context_subject, subject).
72
+ object_type.should == 'b'
73
+ end
74
+ end
75
+
76
+ describe 'fact_with_resource_object' do
77
+ it 'has "r" as object_type' do
78
+ described_class.fact_with_resource_object(context_subject, subject).
79
+ object_type.should == 'r'
80
+ end
81
+ end
82
+
67
83
  describe 'full_fact' do
68
84
  it 'does not fail' do
69
85
  full_fact
@@ -15,12 +15,12 @@ module Dbd
15
15
  end
16
16
  end
17
17
 
18
- it 'the resource has the facts' do
18
+ it 'the resources has the facts' do
19
19
  facts = full_graph.reject(&:context_fact?)
20
20
  full_graph.resources.single.should include(*facts)
21
21
  end
22
22
 
23
- it 'the resource does not have has the context_facts' do
23
+ it 'the resources does not have context_facts' do
24
24
  context_facts = full_graph.select(&:context_fact?)
25
25
  full_graph.resources.single.should_not include(*context_facts)
26
26
  end
@@ -29,5 +29,31 @@ module Dbd
29
29
  full_graph.resources.should_not be_empty
30
30
  end
31
31
  end
32
+
33
+ context 'contexts' do
34
+ it 'is an array' do
35
+ full_graph.contexts.should be_a(Array)
36
+ end
37
+
38
+ it 'is an array of contexts' do
39
+ full_graph.contexts.each do |context|
40
+ context.should be_a(Context)
41
+ end
42
+ end
43
+
44
+ it 'the contexts has the context_facts' do
45
+ context_facts = full_graph.select(&:context_fact?)
46
+ full_graph.contexts.single.should include(*context_facts)
47
+ end
48
+
49
+ it 'the contexts does not have facts' do
50
+ facts = full_graph.reject(&:context_fact?)
51
+ full_graph.contexts.single.should_not include(*facts)
52
+ end
53
+
54
+ it 'has at least one entry' do
55
+ full_graph.contexts.should_not be_empty
56
+ end
57
+ end
32
58
  end
33
- end
59
+ end
@@ -72,8 +72,12 @@ module Dbd
72
72
  first_line.split(',')[4].should == '"context:visibility"'
73
73
  end
74
74
 
75
- it 'has object as 6th value' do
76
- first_line.split(',')[5].should == '"public"'
75
+ it 'has object_type as 6th value' do
76
+ first_line.split(',')[5].should == '"s"'
77
+ end
78
+
79
+ it 'has object as 7th value' do
80
+ first_line.split(',')[6].should == '"public"'
77
81
  end
78
82
  end
79
83
 
@@ -139,8 +143,12 @@ module Dbd
139
143
  first_line.split(',')[4].should == '"http://example.org/test/name"'
140
144
  end
141
145
 
142
- it 'has object as 6th value' do
143
- first_line.split(',')[5].should == '"Mandela"'
146
+ it 'has object_type as 6th value' do
147
+ first_line.split(',')[5].should == '"s"'
148
+ end
149
+
150
+ it 'has object as 7th value' do
151
+ first_line.split(',')[6].should == '"Mandela"'
144
152
  end
145
153
  end
146
154
  end
@@ -13,6 +13,7 @@ module TestFactories
13
13
  factory_for.new(
14
14
  subject: subject,
15
15
  predicate: 'context:visibility',
16
+ object_type: 's',
16
17
  object: 'public')
17
18
  end
18
19
 
@@ -20,6 +21,7 @@ module TestFactories
20
21
  factory_for.new(
21
22
  subject: subject,
22
23
  predicate: 'dcterms:creator',
24
+ object_type: 's',
23
25
  object: 'peter_v')
24
26
  end
25
27
 
@@ -27,6 +29,7 @@ module TestFactories
27
29
  factory_for.new(
28
30
  subject: subject,
29
31
  predicate: 'prov:source',
32
+ object_type: 's',
30
33
  object: "this has a comma , a newline \n and a double quote \"")
31
34
  end
32
35
 
@@ -34,6 +37,7 @@ module TestFactories
34
37
  factory_for.new(
35
38
  subject: subject,
36
39
  predicate: 'dcterms:created',
40
+ object_type: 's',
37
41
  object: Time.now.utc)
38
42
  end
39
43
  end
@@ -15,13 +15,16 @@ module TestFactories
15
15
  '40fab407-9b04-4a51-9a52-d978abfcbb1f',
16
16
  '2e9fbc87-2e94-47e9-a8fd-121cc4bc3e8f',
17
17
  'http://example.org/test/name',
18
+ 's',
18
19
  "Gandhi\\nKing\\\\n"]
19
20
  end
20
21
 
22
+
21
23
  def self.fact_1(context_subject = nil)
22
24
  factory_for.new(
23
25
  context_subject: context_subject,
24
26
  predicate: 'http://example.org/test/name',
27
+ object_type: 's',
25
28
  object: 'Gandhi')
26
29
  end
27
30
 
@@ -29,6 +32,7 @@ module TestFactories
29
32
  factory_for.new(
30
33
  id: forced_id,
31
34
  predicate: 'http://example.org/test/name',
35
+ object_type: 's',
32
36
  object: "Gandhi\nKing\\n") # newline and \n
33
37
  end
34
38
 
@@ -37,6 +41,7 @@ module TestFactories
37
41
  context_subject: context_subject,
38
42
  subject: subject,
39
43
  predicate: 'http://example.org/test/comment',
44
+ object_type: 's',
40
45
  object: "A long story with a newline\nreally with a comma, a double quote \" and a non-ASCII char éà Über.")
41
46
  end
42
47
 
@@ -44,6 +49,7 @@ module TestFactories
44
49
  factory_for.new(
45
50
  time_stamp: time_stamp,
46
51
  predicate: 'http://example.org/test/name',
52
+ object_type: 's',
47
53
  object: 'Gandhi')
48
54
  end
49
55
 
@@ -52,6 +58,7 @@ module TestFactories
52
58
  context_subject: context_subject,
53
59
  subject: new_subject,
54
60
  predicate: 'http://example.org/test/name',
61
+ object_type: 's',
55
62
  object: 'Mandela')
56
63
  end
57
64
 
@@ -60,6 +67,7 @@ module TestFactories
60
67
  context_subject: context_subject,
61
68
  subject: new_subject,
62
69
  predicate: 'http://example.org/test/name',
70
+ object_type: 's',
63
71
  object: 'King')
64
72
  end
65
73
 
@@ -68,6 +76,7 @@ module TestFactories
68
76
  context_subject: context_subject,
69
77
  subject: subject,
70
78
  predicate: 'http://example.org/test/name',
79
+ object_type: 's',
71
80
  object: 'Aung San Suu Kyi')
72
81
  end
73
82
 
@@ -76,6 +85,7 @@ module TestFactories
76
85
  context_subject: context_subject,
77
86
  subject: subject,
78
87
  predicate: 'http://example.org/test/name',
88
+ object_type: 's',
79
89
  object: "\\n\n\\n\n\\\n\\\\\n\\\\\\\nEuropean\nUnion\\n")
80
90
  end
81
91
 
@@ -88,6 +98,24 @@ module TestFactories
88
98
  end
89
99
  end
90
100
 
101
+ def self.fact_with_boolean_object(context_subject = nil, subject = nil)
102
+ factory_for.new(
103
+ context_subject: context_subject,
104
+ subject: subject,
105
+ predicate: 'meta:predicate_used',
106
+ object_type: 'b',
107
+ object: 'true')
108
+ end
109
+
110
+ def self.fact_with_resource_object(context_subject = nil, subject = nil)
111
+ factory_for.new(
112
+ context_subject: context_subject,
113
+ subject: subject,
114
+ predicate: 'schema:attendee',
115
+ object_type: 'r',
116
+ object: '10db9097-8a59-497d-97d3-621fd1921e9f') # the subject for a resource
117
+ end
118
+
91
119
  module Collection
92
120
  def self.factory_for_instance
93
121
  o = Object.new
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.20
4
+ version: 0.1.0
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-06 00:00:00.000000000 Z
11
+ date: 2013-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler