Skip to content

Commit

Permalink
Updated SPARQL, added unit test to remove objects
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-aravind committed Sep 10, 2024
1 parent 396fddb commit 7076d08
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
10 changes: 7 additions & 3 deletions sparql/remove_objects.sparql
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
PREFIX schema: <http://schema.org/>
PREFIX schemaHttps: <https://schema.org/>

DELETE {
?subject ?predicate ?object .
?s ?p ?o .
}
WHERE {
?subject ?predicate ?object .
?subject a <http://schema.org/SiteNavigationElement> .
?s ?p ?o .
?s a ?type .
VALUES ?type { schema:SiteNavigationElement schemaHttps:SiteNavigationElement }
}
46 changes: 46 additions & 0 deletions tests/fixtures/test_remove_object.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"@context": "http://schema.org",
"@graph": [
{
"@id": "https://example.com/temporary/unique-id-1",
"@type": [
"https://schema.org/SiteNavigationElement"
],
"http://www.w3.org/ns/prov#wasDerivedFrom": [
{
"@id": "https://example.com/source-page-1"
}
]
},
{
"@id": "https://example.com/temporary/unique-id-2",
"@type": [
"http://schema.org/SiteNavigationElement"
],
"http://schema.org/name": [
{
"@value": "Example Name 1"
},
{
"@value": "Example Name 2"
}
],
"http://schema.org/url": [
{
"@id": "https://example.com/page-1"
},
{
"@id": "https://example.com/page-2"
},
{
"@id": "https://example.com/login-page"
}
],
"http://www.w3.org/ns.prov#wasDerivedFrom": [
{
"@id": "https://example.com/source-page-1"
}
]
}
]
}
21 changes: 21 additions & 0 deletions tests/remove_object_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'minitest/autorun'
require 'linkeddata'

class RemoveObjectTest < Minitest::Test
def setup
@remove_object_sparql_file = "./sparql/remove_objects.sparql"
end

def test_remove_object
sparql = SPARQL.parse(File.read(@remove_object_sparql_file), update: true)
graph = RDF::Graph.load("./tests/fixtures/test_remove_object.jsonld")

# puts "before: #{graph.dump(:jsonld)}"
graph.query(sparql)

# puts "after: #{graph.dump(:jsonld)}"
assert_equal(0, graph.count, "The graph should have no objects after the SPARQL update.")
end


end

0 comments on commit 7076d08

Please sign in to comment.