Skip to content

Instantly share code, notes, and snippets.

@peta
Created January 21, 2015 21:33
Show Gist options
  • Save peta/2db61e8609dab12ffc34 to your computer and use it in GitHub Desktop.
Save peta/2db61e8609dab12ffc34 to your computer and use it in GitHub Desktop.
Gist linguist test
#QUERY <http://localhost:9090/test-rdf-fuseki/query>
#UPDATE <http://localhost:9090/test-rdf-fuseki/update>
PREFIX : <urn:example#>
INSERT DATA {
:instDefault :theLabel 'Hello from DEFAULT graph'
GRAPH :graph1 { :instDefault1 :theLabel 'Hello from graph1'. :instDefault1b :theLabel 'Hello from graph1'. }
GRAPH :graph2 { :instDefault2 :theLabel 'Hello from graph2'. :instDefault2b :theLabel 'Hello from graph1'.}
GRAPH :graph3 { :instDefault3 :theLabel 'Hello from graph3'. :instDefault3b :theLabel 'Hello from graph1'.}
GRAPH :graph4 { :instDefault4 :theLabel 'Hello from graph4'. :instDefault4b :theLabel 'Hello from graph1'.}
}
#---
#name= insert-some-bnode
PREFIX : <urn:example#>
INSERT DATA {
[ a :MyClass ] :label 'bnode 1' .
[ a :MyClass ] :label 'bnode 2' .
[ a :MyClass ] :label 'bnode 3' .
}
#---
#name= insert-some-bnode-named
PREFIX : <urn:example#>
INSERT DATA {
GRAPH :g1 { [ a :MyClass ] :label 'bnode 1' }
GRAPH :g2 { [ a :MyClass ] :label 'bnode 2' }
GRAPH :g3 { [ a :MyClass ] :label 'bnode 3' }
}
#---
#name= select-all-bnodes
#descr= Selects all bnodes in the default graph
SELECT DISTINCT *
WHERE {
?s ?p ?o
FILTER isBLANK(?s)
}
#/
#---
SELECT DISTINCT ?s ?p ?o
WHERE {
[] ?p ?o .
#FILTER( isBLANK( ?s ) )
}
#---
#name= delete-all-bnodes
#descr= Deletes all bnode statements from default graph (by using the pattern matching strategy).
#INCLUDE <drop-all>
#INCLUDE <insert-some-bnode>
#INCLUDE <select-all-bnodes>
DELETE { ?s ?p ?o }
WHERE {
[] ?p ?o .
?s <urn:example#label> ?o .
?s ?p 'bnode 2' .
#FILTER( isBLANK( ?s ) )
}
#INCLUDE <select-all-bnodes>
#---
#name= delete-all-bnodes-named
#descr= Deletes all bnode statements from named graphs (by using the pattern matching strategy).
DELETE {
GRAPH ?g { ?s ?p ?o }
}
WHERE {
GRAPH ?g {
?s ?p ?o .
?s <urn:example#label> 'bnode 1' .
FILTER( isBLANK( ?s ) )
}
}
#DELETE { ?s ?p ?o }
#WHERE { ?s ?p ?o . FILTER(isBLANK(?s)) }
#---
#name= simple-select-default-merge.sparql
#descr=
# Temporarily merge <urn:example#graph1> into the default graph and select all triple statements.
# Note: By doing such a merge, you also discard any additional graph informations. You will not
# be able to tell if a particular triple was originally held by the default graph or a named one.
#
PREFIX : <urn:example#>
SELECT *
FROM :graph1
WHERE { ?s ?p ?o }
#---
#name= drop-default
#descr= Drop the default graph (deletes both, the graph and the data it contains)
DROP DEFAULT
#---
#name= drop-all
#descr= Drop all graphs – both, the default graph and all named ones
DROP ALL
#---
#descr=
# Select all statements from both, the default and all named graphs, order them by
# graph, subject and predicate and finally present them as quads
SELECT ?g ?s ?p ?o
WHERE {
{ ?s ?p ?o } UNION
{ GRAPH ?g { ?s ?p ?o } }
}
ORDER BY ?g ?s ?p
#---
#name= here we go
#descr= Delete given triples from the a named graph
#
BASE <urn:example>
DELETE DATA {
GRAPH <#graph1> {
<#instGraph1> <#theLabel> "Hello from graph1"
}
}
#---
# Delete given triples from the default graph and named graphs
BASE <urn:example>
DELETE DATA {
<#instDefault> <#theLabel> "Hello from DEFAULT graph" .
GRAPH <#graph1> { <#instDefault1> <#theLabel> "Hello from graph1" } .
GRAPH <#graph2> { <#instDefault2> <#theLabel> "Hello from graph2" } .
}
#---
# Simple example that shows how to insert and then update
# statements using the SPARUL 1.1
BASE <urn:example:insup>
PREFIX ppl: <urn:example:insup:people#>
PREFIX cpl: <urn:example:insup:people#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX wedd: <urn:exmaple:insup:wedding-vocab#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
# Assume there are two people – Peter and Mary
INSERT DATA {
GRAPH <#people> {
ppl:peter foaf:firstName 'Peter';
foaf:lastName 'Parker'.
ppl:mary foaf:firstName 'Mary';
foaf:lastName 'Watson'.
}
}
# One day, they become friends
WITH <#people>
INSERT {
?peter foaf:knows ?mary .
?mary foaf:knows ?peter
}
WHERE {
?peter foaf:firstName 'Peter' .
?mary foaf:firstName 'Mary' .
}
# Then, after a few years later, they marry – and Mary will
# take Peter's family name and, in line with the family's tradition,
# they become part of the <#couples> graph
WITH <#people>
DELETE {
?person foaf:lastName ?lastName
}
INSERT {
?person foaf:lastName 'Parker' .
GRAPH <#couples> {
cpl:peter-mary a wedd:Couple;
wedd:day '2013-03-18'^^xsd:date;
wedd:husband ppl:peter;
wedd:wife ppl:mary.
}
}
WHERE {
?person ?p ?lastName .
?person foaf:firstName 'Mary' .
?person foaf:lastName 'Watson'
}
#---
DELETE DATA {
<#instDefault> <#theLabel> "Hello from DEFAULT graph" .
GRAPH <#graph1> { <#instDefault1> <#theLabel> "Hello from graph1" } .
GRAPH <#graph2> { <#instDefault2> <#theLabel> "Hello from graph2" } .
}
#---
PREFIX : <urn:example2#>
SELECT (COUNT(?subj) AS ?n_subjs)
WHERE {
?subj a :ClassA
}
#---
# Check if a graph with the given IRI exists
ASK { GRAPH <urn:mygraph> { ?s ?p ?o } }
#---
# Get list of all named graphs and order them by their IRI value
SELECT DISTINCT ?g
WHERE { GRAPH ?g { } }
ORDER BY ?g
#---
# Get list of all graphs (both, default and named) and order them by their IRI value
SELECT DISTINCT ?g
WHERE {
{ } UNION
{ GRAPH ?g { } }
}
ORDER BY ?g
WHERE {}
#---
#QUERY <http://dbpedia.org/sparql>
SELECT DISTINCT *
FROM NAMED <http://dbpedia.org/sparql>
WHERE {
GRAPH <http://dbpedia.org/sparql> {
?s ?p ?o
}
}
LIMIT 50
#---
ASK FROM <urn:test:graph1> WHERE { <urn:test:graph1#instance> <urn:test:graph1#predicate> <urn:test:graph1#object> . }
#---
CONSTRUCT { <urn:text#subject> <urn:text#predicat> <urn:text#subject> } WHERE {}
#---
SELECT ?s ?p ?o
FROM <urn:foo1>
FROM <urn:foo2>
WHERE {
<http://ar.to/#self> <http://xmlns.com/foaf/0.1/mbox_sha1sum> ?o
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment