slender_t 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ a,implies,b
2
+ a,implies,d
3
+ c,implies,d
4
+ d,implies,e
5
+ f,implies,a
6
+ e,implies,a
7
+ b,implies,c
8
+ a,does_not_imply,c
@@ -0,0 +1,201 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe SlenderT do
4
+
5
+ it "should initialize with three triple indexes" do
6
+ st = SlenderT.new
7
+ st.spo.should be_is_a(Hash)
8
+ st.pos.should be_is_a(Hash)
9
+ st.osp.should be_is_a(Hash)
10
+ end
11
+
12
+ context "add and remove" do
13
+ before do
14
+ @st = SlenderT.new
15
+ end
16
+
17
+ it "should be able to add a triple" do
18
+ @st.add(:foo, :bar, :baz)
19
+ @st.spo[:foo].should be_is_a(Hash)
20
+ @st.spo[:foo][:bar].should eql([:baz])
21
+ @st.pos[:bar].should be_is_a(Hash)
22
+ @st.pos[:bar][:baz].should eql([:foo])
23
+ @st.osp[:baz].should be_is_a(Hash)
24
+ @st.osp[:baz][:foo].should eql([:bar])
25
+ end
26
+
27
+ it "should not add a triple more than once, i.e. duplicate entries are not created" do
28
+ @st.add(:foo, :bar, :baz)
29
+ @st.add(:foo, :bar, :baz)
30
+ @st.spo[:foo][:bar].should eql([:baz])
31
+ @st.pos[:bar][:baz].should eql([:foo])
32
+ @st.osp[:baz][:foo].should eql([:bar])
33
+ end
34
+
35
+ it "should be able to remove a triple" do
36
+ @st.add(:foo, :bar, :baz)
37
+ @st.remove(:foo, :bar, :baz)
38
+ @st.spo.should_not be_include(:foo)
39
+ @st.pos.should_not be_include(:bar)
40
+ @st.osp.should_not be_include(:baz)
41
+ end
42
+
43
+ it "should not complain when removing a non-existent triple" do
44
+ @st.add(:foo, :bar, :baz)
45
+ @st.remove(:foo, :bar, :baz)
46
+ @st.remove(:foo, :bar, :baz)
47
+ lambda{@st.remove(:foo, :bar, :baz)}.should_not raise_error
48
+ end
49
+
50
+ end
51
+
52
+ context "query" do
53
+ before do
54
+ @st = SlenderT.new
55
+ @st.add(:a, :implies, :b)
56
+ @st.add(:a, :implies, :d)
57
+ @st.add(:c, :implies, :d)
58
+ @st.add(:d, :implies, :e)
59
+ @st.add(:f, :implies, :a)
60
+ @st.add(:e, :implies, :a)
61
+ @st.add(:b, :implies, :c)
62
+ @st.add(:a, :does_not_imply, :c)
63
+ end
64
+
65
+ it "should be able to find an exact triple, returning an array of arrays" do
66
+ @st.find(:a, :implies, :b).should eql([[:a, :implies, :b]])
67
+ @st.find(:c, :implies, :d).should eql([[:c, :implies, :d]])
68
+ end
69
+
70
+ it "should return an empty set if an exact triple can't be found" do
71
+ @st.find(:x, :implies, :y).should eql([])
72
+ end
73
+
74
+ it "should find all matching subjects and predicates" do
75
+ @st.find(:a, :does_not_imply).should eql([[:a, :does_not_imply, :c]])
76
+ @st.find(:a, :implies).should eql([[:a, :implies, :b],[:a, :implies, :d]])
77
+ end
78
+
79
+ it "should find all matching subjects and objects" do
80
+ @st.find(:a, nil, :d).should eql([[:a, :implies, :d]])
81
+ @st.find(:b, nil, :c).should eql([[:b, :implies, :c]])
82
+ end
83
+
84
+ it "should find all matching subjects" do
85
+ found = @st.find(:a)
86
+ found.size.should eql(3)
87
+ found.should be_include([:a, :implies, :b])
88
+ found.should be_include([:a, :implies, :d])
89
+ found.should be_include([:a, :does_not_imply, :c])
90
+ end
91
+
92
+ it "should find all matching predicates and objects" do
93
+ found = @st.find(nil, :implies, :d)
94
+ found.size.should eql(2)
95
+ found.should be_include([:a, :implies, :d])
96
+ found.should be_include([:c, :implies, :d])
97
+ @st.find(nil, :implies, :e).should eql([[:d, :implies, :e]])
98
+ end
99
+
100
+ it "should find all matching predicates" do
101
+ found = @st.find(nil, :implies, nil)
102
+ found.size.should eql(7)
103
+ found.should be_include([:a, :implies, :b])
104
+ found.should be_include([:a, :implies, :d])
105
+ found.should be_include([:c, :implies, :d])
106
+ found.should be_include([:d, :implies, :e])
107
+ found.should be_include([:f, :implies, :a])
108
+ found.should be_include([:e, :implies, :a])
109
+ found.should be_include([:b, :implies, :c])
110
+ @st.find(nil, :does_not_imply, nil).should eql([[:a, :does_not_imply, :c]])
111
+ end
112
+
113
+ it "should find all matching objects" do
114
+ found = @st.find(nil, nil, :d)
115
+ found.size.should eql(2)
116
+ found.should be_include([:a, :implies, :d])
117
+ found.should be_include([:c, :implies, :d])
118
+ @st.find(nil, nil, :e).should eql([[:d, :implies, :e]])
119
+ end
120
+
121
+ it "should find all triplets" do
122
+ found = @st.find(nil, nil, nil)
123
+ found.size.should eql(8)
124
+ found.should be_include([:a, :implies, :b])
125
+ found.should be_include([:a, :implies, :d])
126
+ found.should be_include([:c, :implies, :d])
127
+ found.should be_include([:d, :implies, :e])
128
+ found.should be_include([:f, :implies, :a])
129
+ found.should be_include([:e, :implies, :a])
130
+ found.should be_include([:b, :implies, :c])
131
+ found.should be_include([:a, :does_not_imply, :c])
132
+ end
133
+
134
+ it "should be able to see the missing value of the first queried result" do
135
+ @st.value(:a, :implies).should eql(:b)
136
+ end
137
+ end
138
+
139
+ context "load" do
140
+
141
+ it "should be able to load file contents from the class method" do
142
+ @st = SlenderT.load(simple_filename)
143
+ found = @st.find(nil, nil, nil)
144
+ found.size.should eql(8)
145
+ found.should be_include(%w(a implies b))
146
+ found.should be_include(%w(a implies d))
147
+ found.should be_include(%w(c implies d))
148
+ found.should be_include(%w(d implies e))
149
+ found.should be_include(%w(f implies a))
150
+ found.should be_include(%w(e implies a))
151
+ found.should be_include(%w(b implies c))
152
+ found.should be_include(%w(a does_not_imply c))
153
+ end
154
+
155
+ it "should be able to load csv string from the class method" do
156
+ @st = SlenderT.load(simple_content)
157
+ found = @st.find(nil, nil, nil)
158
+ found.size.should eql(8)
159
+ found.should be_include(%w(a implies b))
160
+ found.should be_include(%w(a implies d))
161
+ found.should be_include(%w(c implies d))
162
+ found.should be_include(%w(d implies e))
163
+ found.should be_include(%w(f implies a))
164
+ found.should be_include(%w(e implies a))
165
+ found.should be_include(%w(b implies c))
166
+ found.should be_include(%w(a does_not_imply c))
167
+ end
168
+
169
+ it "should be able to load file contents from the instance method" do
170
+ @st = SlenderT.new
171
+ @st.load(simple_filename)
172
+ found = @st.find(nil, nil, nil)
173
+ found.size.should eql(8)
174
+ found.should be_include(%w(a implies b))
175
+ found.should be_include(%w(a implies d))
176
+ found.should be_include(%w(c implies d))
177
+ found.should be_include(%w(d implies e))
178
+ found.should be_include(%w(f implies a))
179
+ found.should be_include(%w(e implies a))
180
+ found.should be_include(%w(b implies c))
181
+ found.should be_include(%w(a does_not_imply c))
182
+ end
183
+
184
+ it "should be able to load csv string from the instance method" do
185
+ @st = SlenderT.new
186
+ @st.load(simple_content)
187
+ found = @st.find(nil, nil, nil)
188
+ found.size.should eql(8)
189
+ found.should be_include(%w(a implies b))
190
+ found.should be_include(%w(a implies d))
191
+ found.should be_include(%w(c implies d))
192
+ found.should be_include(%w(d implies e))
193
+ found.should be_include(%w(f implies a))
194
+ found.should be_include(%w(e implies a))
195
+ found.should be_include(%w(b implies c))
196
+ found.should be_include(%w(a does_not_imply c))
197
+ end
198
+
199
+ end
200
+
201
+ end
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'slender_t'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+ def simple_content
9
+ File.read(simple_filename)
10
+ end
11
+
12
+ def simple_filename
13
+ File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'simple.csv'))
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slender_t
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - David Richards
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-20 00:00:00 -06:00
13
+ default_executable: slender_t
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Simple triples storage for projects too small to install an RDF database.
26
+ email: david@fleetventures.com
27
+ executables:
28
+ - slender_t
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - bin/slender_t
42
+ - lib/slender_t.rb
43
+ - spec/fixtures/movies.csv
44
+ - spec/fixtures/simple.csv
45
+ - spec/slender_t_spec.rb
46
+ - spec/spec_helper.rb
47
+ has_rdoc: true
48
+ homepage: http://github.com/davidrichards/slender_t
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options:
53
+ - --charset=UTF-8
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ requirements: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.3.5
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Simple triples storage
75
+ test_files:
76
+ - spec/slender_t_spec.rb
77
+ - spec/spec_helper.rb