Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* AbstractStore#destroy either removes all triples from store, or spe…

…cified context. No longer removes the DB file.
  • Loading branch information...
commit cb14226a77a5c9dd1596cf9291cdc18581caa86f 1 parent fd0168d
@gkellogg authored
View
8 lib/rdf_context/store/abstract_sql_store.rb
@@ -72,6 +72,14 @@ def close(commit_pending_transactions = false)
@db.close
end
+ # Destroy store or context
+ # If context is specified remove that context, otherwise, remove all triples
+ #
+ # @option configuration [Graph] :context Remove the specified context
+ def destroy(configuration = {})
+ remove(Triple.new(nil, nil, nil), configuration[:context])
+ end
+
# Add a triple to the store
# Add to default context, if context is nil
#
View
6 lib/rdf_context/store/abstract_store.rb
@@ -62,6 +62,12 @@ def remove(triple, context = nil); raise StoreException, "not implemented"; end
# @raise [StoreException] Not Implemented
# @return [Boolean]
def contains?(triple, context = nil); raise StoreException, "not implemented"; end
+
+ # Return contexts in the store (optionally matching triple), or empty if not context aware
+ # @return [Array<Graph>]
+ def contexts(triple = nil)
+ return []
+ end
# Default (sub-optimal) implemenations of interfaces
def inspect
View
6 lib/rdf_context/store/active_record_store.rb
@@ -122,12 +122,6 @@ def teardown
executeSQL("DROP TABLE #{asserted_type_table}")
executeSQL("DROP TABLE #{asserted_table}")
end
-
- # Destroy database
- #
- # @option options[String] :path Path to database file defaults to a file in the current directory based on a hash of the store identifier
- def destroy(options = {})
- end
protected
View
5 lib/rdf_context/store/list_store.rb
@@ -16,6 +16,11 @@ def inspect
"ListStore[id=#{identifier}, size=#{@triples.length}]"
end
+ # Destroy the store, as it can contain only one context
+ def destroy(configuration = {})
+ @triples = []
+ end
+
# Add triple to store
# @param [Triple] triple
# @param [Graph] context (nil) ignored
View
7 lib/rdf_context/store/sqlite3_store.rb
@@ -142,13 +142,6 @@ def teardown
executeSQL("DROP TABLE #{asserted_table}")
end
- # Destroy database
- #
- # @option options[String] :path Path to database file defaults to a file in the current directory based on a hash of the store identifier
- def destroy(options = {})
- File.delete(@path)
- end
-
protected
# Where clase utility functions
View
32 spec/graph_spec.rb
@@ -8,7 +8,7 @@
@bn_ctx = {}
end
- subject { Graph.new(:store => ListStore.new) }
+ subject { Graph.new(:store => MemoryStore.new) }
it "should allow you to add one or more triples" do
lambda do
subject.add_triple(BNode.new, URIRef.new("http://xmlns.com/foaf/0.1/knows"), BNode.new)
@@ -111,7 +111,7 @@
describe "with named store" do
before(:all) do
@identifier = URIRef.new("http://foo.bar")
- @store = ListStore.new(:identifier => @identifier)
+ @store = MemoryStore.new(:identifier => @identifier)
end
subject {
@@ -138,7 +138,7 @@
subject {
dc = Namespace.new("http://purl.org/dc/terms/", "dc")
xhtml = Namespace.new("http://www.w3.org/1999/xhtml", "")
- g = Graph.new(:store => ListStore.new)
+ g = Graph.new(:store => MemoryStore.new)
g << Triple.new(
URIRef.new("http://www.w3.org/2006/07/SWD/RDFa/testsuite/xhtml1-testcases/0011.xhtml"),
URIRef.new("http://purl.org/dc/terms/title"),
@@ -171,7 +171,7 @@
describe "with bnodes" do
subject {
- g = Graph.new(:store => ListStore.new)
+ g = Graph.new(:store => MemoryStore.new)
a = BNode.new("a")
b = BNode.new("b")
@@ -219,7 +219,7 @@
end
describe "with namespaces" do
- subject { Graph.new(:store => ListStore.new) }
+ subject { Graph.new(:store => MemoryStore.new) }
it "should use namespace with trailing slash" do
ns = Namespace.new("http://www.example.com/ontologies/test/", "test")
@@ -245,7 +245,7 @@
describe "with triples" do
subject {
- g = Graph.new(:store => ListStore.new)
+ g = Graph.new(:store => MemoryStore.new)
g.add_triple(@ex.john, @foaf.knows, @ex.jane)
g.add_triple(@ex.john, @foaf.knows, @ex.rick)
g.add_triple(@ex.jane, @foaf.knows, @ex.rick)
@@ -429,7 +429,7 @@
describe "rdf:_n sequences" do
subject {
- g = Graph.new(:store => ListStore.new)
+ g = Graph.new(:store => MemoryStore.new)
g.add_triple(@ex.Seq, RDF_TYPE, RDF_NS.Seq)
g.add_triple(@ex.Seq, RDF_NS._1, @ex.john)
g.add_triple(@ex.Seq, RDF_NS._2, @ex.jane)
@@ -446,7 +446,7 @@
describe "rdf:first/rdf:rest sequences" do
it "should return object list" do
a, b = BNode.new("a"), BNode.new("b"), BNode.new("c")
- g = Graph.new(:store => ListStore.new)
+ g = Graph.new(:store => MemoryStore.new)
g.add_triple(@ex.List, RDF_NS.first, @ex.john)
g.add_triple(@ex.List, RDF_NS.rest, a)
g.add_triple(a, RDF_NS.first, @ex.jane)
@@ -460,25 +460,25 @@
end
it "should generate a list of resources" do
- g = Graph.new(:store => ListStore.new)
+ g = Graph.new(:store => MemoryStore.new)
g.add_seq(@ex.List, RDF_NS.first, [@ex.john, @ex.jane, @ex.rick])
g.seq(@ex.List).should == [@ex.john, @ex.jane, @ex.rick]
end
it "should generate an empty list" do
- g = Graph.new(:store => ListStore.new)
+ g = Graph.new(:store => MemoryStore.new)
g.add_seq(@ex.List, RDF_NS.first, [])
g.seq(@ex.List).should == []
end
it "should return a list with a predicate" do
- g = Graph.new(:store => ListStore.new)
+ g = Graph.new(:store => MemoryStore.new)
g.add_seq(@ex.List, @ex.includes, [@ex.john, @ex.jane, @ex.rick])
g.seq(@ex.List, @ex.includes).should == [@ex.john, @ex.jane, @ex.rick]
end
it "should add a list with a predicate" do
- g = Graph.new(:store => ListStore.new)
+ g = Graph.new(:store => MemoryStore.new)
g.add_seq(@ex.List, @ex.includes, [@ex.john, @ex.jane, @ex.rick])
l = g.properties(@ex.List)[@ex.includes.to_s].first
l.should be_a(BNode)
@@ -486,7 +486,7 @@
end
it "should remove existing sequence when adding entry to sequence" do
- g = Graph.new(:store => ListStore.new)
+ g = Graph.new(:store => MemoryStore.new)
g.add_seq(@ex.List, @ex.includes, [@ex.john, @ex.jane, @ex.rick])
g.add_seq(@ex.List, @ex.includes, [@ex.john, @ex.jane, @ex.rick, @ex.julie])
l = g.properties(@ex.List)[@ex.includes.to_s].first
@@ -501,7 +501,7 @@
describe "which are merged" do
it "should be able to integrate another graph" do
subject.add_triple(BNode.new, URIRef.new("http://xmlns.com/foaf/0.1/knows"), BNode.new)
- g = Graph.new(:store => ListStore.new)
+ g = Graph.new(:store => MemoryStore.new)
g.merge!(subject)
g.size.should == 1
end
@@ -520,7 +520,7 @@
# of them, before merging the documents.
it "should remap bnodes to avoid duplicate bnode identifiers" do
subject.add_triple(BNode.new("a1", @bn_ctx), URIRef.new("http://xmlns.com/foaf/0.1/knows"), BNode.new("a2", @bn_ctx))
- g = Graph.new(:store => ListStore.new)
+ g = Graph.new(:store => MemoryStore.new)
g.add_triple(BNode.new("a1", @bn_ctx), URIRef.new("http://xmlns.com/foaf/0.1/knows"), BNode.new("a2", @bn_ctx))
g.merge!(subject)
g.size.should == 2
@@ -534,7 +534,7 @@
it "should remove duplicate triples" do
subject.add_triple(@ex.a, URIRef.new("http://xmlns.com/foaf/0.1/knows"), @ex.b)
- g = Graph.new(:store => ListStore.new)
+ g = Graph.new(:store => MemoryStore.new)
g.add_triple(@ex.a, URIRef.new("http://xmlns.com/foaf/0.1/knows"), @ex.b)
g.merge!(subject)
g.size.should == 1
View
4 spec/sqlite3_store_spec.rb
@@ -26,9 +26,9 @@
it_should_behave_like "Store"
it_should_behave_like "Context Aware Store"
- it "should destroy DB file" do
+ it "should not destroy DB file" do
subject.destroy
- File.exists?(@dbfile).should be_false
+ File.exists?(@dbfile).should be_true
end
it "should close db" do
View
84 spec/store_helper.rb
@@ -9,24 +9,21 @@
subject.should be_a(AbstractStore)
end
- it "should allow you to add a triple" do
- subject.add(Triple.new(@ex.a, @ex.b, @ex.c), nil)
- subject.add(Triple.new(@ex.a, @ex.b, @ex.d), nil)
- subject.size.should == 2
- end
+ describe "#add" do
+ it "adds URIRefs" do
+ subject.add(Triple.new(@ex.a, @ex.b, @ex.c), nil)
+ subject.add(Triple.new(@ex.a, @ex.b, @ex.d), nil)
+ subject.size.should == 2
+ end
- it "should allow you to add triples with bnodes" do
- subject.add(Triple.new(BNode.new, @ex.b, @ex.c), nil)
- subject.add(Triple.new(@ex.a, BNode.new, @ex.c), nil)
- subject.add(Triple.new(@ex.a, @ex.b, BNode.new), nil)
- subject.size.should == 3
+ it "adds BNodes" do
+ subject.add(Triple.new(BNode.new, @ex.b, @ex.c), nil)
+ subject.add(Triple.new(@ex.a, BNode.new, @ex.c), nil)
+ subject.add(Triple.new(@ex.a, @ex.b, BNode.new), nil)
+ subject.size.should == 3
+ end
end
- it "should allow you to create and bind Namespace objects" do
- foaf = Namespace.new("http://xmlns.com/foaf/0.1/", "foaf")
- subject.bind(foaf).should == foaf
- end
-
it "should retrieve identifier" do
subject.identifier.should == @identifier
end
@@ -36,6 +33,11 @@
subject.bind(@ex)
end
+ it "should allow you to create and bind Namespace objects" do
+ foaf = Namespace.new("http://xmlns.com/foaf/0.1/", "foaf")
+ subject.bind(foaf).should == foaf
+ end
+
it "should return namespace by prefix" do
subject.namespace(@ex.prefix).should == @ex
end
@@ -139,6 +141,11 @@
t = subject.item(0)
subject.contains?(t).should be_true
end
+
+ it "destroys triples" do
+ subject.destroy
+ subject.size.should == 0
+ end
end
describe "with typed triples" do
@@ -266,8 +273,40 @@
found += 1
end
found.should == 1
+ subject.contexts.length.should == 1
+ subject.contexts.should include(@ctx2)
end
+ it "should destroy from specific context" do
+ subject.add(@triple, @ctx1)
+ subject.add(@triple, @ctx2)
+ subject.destroy(:context => @ctx1)
+ subject.triples(@triple, @ctx1).length.should == 0
+ subject.triples(@triple, @ctx2).length.should == 1
+ found = 0
+ subject.triples(@triple, nil) do |triple, context|
+ found += 1
+ end
+ found.should == 1
+ subject.contexts.length.should == 1
+ subject.contexts.should include(@ctx2)
+ end
+
+ it "should remove context when graph destroyed" do
+ subject.add(@triple, @ctx1)
+ subject.add(@triple, @ctx2)
+ @ctx1.destroy
+ subject.triples(@triple, @ctx1).length.should == 0
+ subject.triples(@triple, @ctx2).length.should == 1
+ found = 0
+ subject.triples(@triple, nil) do |triple, context|
+ found += 1
+ end
+ found.should == 1
+ subject.contexts.length.should == 1
+ subject.contexts.should include(@ctx2)
+ end
+
it "should remove from multiple contexts" do
subject.add(@triple, @ctx1)
subject.add(@triple, @ctx2)
@@ -279,6 +318,7 @@
found += 1
end
found.should == 0
+ subject.contexts.length.should == 0
end
it "should remove context" do
@@ -293,5 +333,19 @@
subject.triples(@triple, @ctx2).length.should == 0
end
+ it "should return new context after equivalent context destroyed" do
+ ctx1 = Graph.new(:identifier => URIRef.new("http://new1.ctx"), :store => subject)
+ subject.add(@triple, ctx1)
+ subject.contexts.length.should == 1
+ subject.contexts.should include(ctx1)
+
+ ctx1.destroy
+ subject.contexts.should be_empty
+
+ ctx1 = Graph.new(:identifier => URIRef.new("http://new1.ctx"), :store => subject)
+ subject.add(@triple, ctx1)
+ subject.contexts.length.should == 1
+ subject.contexts.should include(ctx1)
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.