## Example of FROM Clause
## with distinct values:
SELECT DISTINCT ?Concept
FROM <http://dbpedia.org>
WHERE
{
?s a ?Concept
}
LIMIT 10
## Example "Make a Local Name Graph IRI
## from URL of external Resource.
## The Actual Document URL is
## <http://dig.csail.mit.edu/2005/ajar/ajaw/data>:
DEFINE input:grab-var "dev"
DEFINE input:grab-var "proj"
DEFINE input:grab-var "projectName"
DEFINE input:grab-follow-predicate
<http://usefulinc.com/ns/doap#developer>
DEFINE input:grab-depth 3
DEFINE input:grab-limit 50
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX doap: <http://usefulinc.com/ns/doap#>
SELECT DISTINCT ?name
FROM <http://dig.csail.mit.edu/2005/ajar/ajaw/data>
WHERE
{
<http://dig.csail.mit.edu/2005/ajar/ajaw/data#Tabulator>
doap:developer ?dev .
?dev foaf:name ?name .
}
## Example with FROM NAMED Clause:
SELECT ?id
FROM NAMED
<http://www.openlinksw.com/dataspace/person/kidehen@openlinksw.com>
OPTION (get:soft "soft", get:method "GET")
WHERE
{
GRAPH ?g { ?id a ?o . filter (!isblank(?id))}
}
## Example with multiple graphs
## and UNION
PREFIX gr: <http://purl.org/goodrelations/v1#>
SELECT ?object
FROM NAMED
<http://www.ebusiness-unibw.org/tools/goodrelations-validator/examples/test8.rdf>
OPTION (get:soft "soft", get:method "GET")
FROM NAMED <http://purl.org/goodrelations/v1>
OPTION (get:soft "soft", get:method "GET")
WHERE
{
{
GRAPH
<http://www.ebusiness-unibw.org/tools/goodrelations-validator/examples/test8.rdf>
{
?object gr:hasGlobalLocationNumber ?gln
}
}
UNION
{
GRAPH
<http://purl.org/goodrelations/v1>
{
?object gr:hasGlobalLocationNumber ?gln
}
}
}
## Example with OPTIONAL values:
DEFINE input:grab-var "foafn"
DEFINE input:grab-var "friend"
DEFINE input:grab-var "friendsURI"
DEFINE input:grab-follow-predicate <http://usefulinc.com/ns/doap#developer>
DEFINE input:grab-depth 10
DEFINE input:grab-limit 50
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX doap: <http://usefulinc.com/ns/doap#>
SELECT DISTINCT ?friendsname ?friendshomepage ?foafsname ?foafshomepage
FROM NAMED <http://richard.cyganiak.de/foaf.rdf>
WHERE
{
GRAPH
<http://richard.cyganiak.de/foaf.rdf>
{
{
<http://richard.cyganiak.de/foaf.rdf#cygri> foaf:knows ?friend .
?friend foaf:mbox_sha1sum ?mbox .
?friendsURI foaf:mbox_sha1sum ?mbox .
?friendsURI foaf:name ?friendsname .
?friendsURI foaf:homepage ?friendshomepage .
}
OPTIONAL {
?friendsURI foaf:knows ?foafn .
?foafn foaf:name ?foafsname .
?foafn foaf:homepage ?foafshomepage .
}
}
}
## Example with DISTINCT values:
DEFINE input:grab-var "dev"
DEFINE input:grab-var "proj"
DEFINE input:grab-var "projectName"
DEFINE input:grab-follow-predicate <http://usefulinc.com/ns/doap#developer>
DEFINE input:grab-depth 10
DEFINE input:grab-limit 50
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX doap: <http://usefulinc.com/ns/doap#>
SELECT DISTINCT *
FROM NAMED <http://dig.csail.mit.edu/2005/ajar/ajaw/data>
WHERE
{
GRAPH <http://dig.csail.mit.edu/2005/ajar/ajaw/data>
{
<http://dig.csail.mit.edu/2005/ajar/ajaw/data#Tabulator>
doap:developer ?dev .
?dev foaf:name ?name .
OPTIONAL { ?dev foaf:mbox ?mbox }
OPTIONAL {
?dev doap:project ?proj .
?proj foaf:name ?projectName
}
}
}
DEFINE input:grab-var "foafn"
DEFINE input:grab-var "friend"
DEFINE input:grab-var "friendsURI"
DEFINE input:grab-follow-predicate <http://xmlns.com/foaf/0.1/knows>
DEFINE input:grab-depth 10
DEFINE input:grab-limit 50
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX doap: <http://usefulinc.com/ns/doap#>
SELECT DISTINCT *
FROM NAMED
<http://richard.cyganiak.de/foaf.rdf>
WHERE
{
GRAPH
<http://richard.cyganiak.de/foaf.rdf>
{
{
<http://richard.cyganiak.de/foaf.rdf#cygri>
foaf:knows ?friend .
?friend foaf:mbox_sha1sum ?mbox .
OPTIONAL { ?friendsURI foaf:mbox_sha1sum ?mbox } .
OPTIONAL { ?friendsURI foaf:name ?friendsname } .
OPTIONAL { ?friendsURI foaf:homepage ?friendshomepage } .
}
OPTIONAL {
?friendsURI foaf:knows ?foafn .
?foafn foaf:name ?foafsname .
?foafn foaf:homepage ?foafshomepage .
}
}
}
DEFINE input:grab-var "foafn"
DEFINE input:grab-var "friend"
DEFINE input:grab-var "friendsURI"
DEFINE input:grab-follow-predicate <http://xmlns.com/foaf/0.1/knows>
DEFINE input:grab-depth 10
DEFINE input:grab-limit 50
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX doap: <http://usefulinc.com/ns/doap#>
SELECT DISTINCT *
FROM NAMED
<http://id.myopenlink.net/dataspace/person/kidehen>
WHERE
{
{
{
{
SELECT ?start ?friend
WHERE
{
?start foaf:knows ?friend .
}
}
OPTION ( transitive, t_in (?start), t_out (?friend) )
FILTER ( ?start =
<http://id.myopenlink.net/dataspace/person/kidehen#this>
)
}
OPTIONAL { ?friend foaf:mbox_sha1sum ?mbox } .
OPTIONAL { ?friendsURI foaf:mbox_sha1sum ?mbox } .
OPTIONAL { ?friendsURI foaf:name ?friendsname } .
OPTIONAL { ?friendsURI foaf:homepage ?friendshomepage } .
}
OPTIONAL {
?friendsURI foaf:knows ?foafn .
?foafn foaf:name ?foafsname .
?foafn foaf:homepage ?foafshomepage .
}
}
## Example of pragma "grab-base" usage:
DEFINE input:grab-var "?more"
DEFINE input:grab-depth 10
DEFINE input:grab-limit 100
DEFINE input:grab-base
"http://www.openlinksw.com/dataspace/kidehen@openlinksw.com/weblog/kidehen@openlinksw.com%27s%20BLOG%20%5B127%5D/1300"
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?id ?firstname ?nick
WHERE
{
GRAPH ?g
{
?id rdf:type foaf:Person .
?id foaf:firstName ?firstname .
?id foaf:knows ?fn .
?fn foaf:nick ?nick .
OPTIONAL { ?id rdfs:SeeAlso ?more } .
FILTER (!isblank(?id)) .
}
}
LIMIT 10
## Example of pragma "sql:signal-void-variables" usage:
DEFINE sql:signal-void-variables 1
DEFINE input:grab-var "db"
SELECT *
FROM <http://data.nytimes.com#people>
WHERE
{
<http://data.nytimes.com/N66220017142656459133> owl:sameAs ?db.
GRAPH ?g
{
?db ?p ?o
}
}
LIMIT 10
## Example of pragma "get:soft "replace" usage:
## New York Times DBpedia Join
## Using Sponger to remote HTTP GET and then
## make a local Named Graph from the Resource at
## URL: <http://data.nytimes.com/N66220017142656459133.rdf>
DEFINE input:same-as "yes"
DEFINE get:soft "replace"
DEFINE input:grab-var "db"
SELECT ?nyt_entity ?attribute ?attribute_value
FROM <http://data.nytimes.com/N66220017142656459133.rdf>
WHERE
{
?nyt_entity owl:sameAs ?dbpedia_entity.
GRAPH ?g
{
?dbpedia_entity ?attribute ?attribute_value
}
}
## Example of pragma "input:same-as "yes"" usage:
DEFINE input:same-as "yes"
SELECT *
WHERE
{
?s <http://xmlns.com/foaf/0.1/name> "Kingsley Idehen" .
FILTER (!isblank(?s)) .
}
LIMIT 10
## Example of pragma "grab-var" usage:
DEFINE input:grab-var "dev"
DEFINE input:grab-var "proj"
DEFINE input:grab-var "projectName"
DEFINE input:grab-follow-predicate <http://usefulinc.com/ns/doap#developer>
DEFINE input:grab-depth 10
DEFINE input:grab-limit 50
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX doap: <http://usefulinc.com/ns/doap#>
SELECT DISTINCT ?name ?mbox ?projectName
FROM NAMED <http://dig.csail.mit.edu/2005/ajar/ajaw/data>
WHERE
{
GRAPH <http://dig.csail.mit.edu/2005/ajar/ajaw/data>
{
<http://dig.csail.mit.edu/2005/ajar/ajaw/data#Tabulator>
doap:developer ?dev .
?dev foaf:name ?name .
OPTIONAL { ?dev foaf:mbox ?mbox } .
OPTIONAL {
?dev doap:project ?proj .
?proj foaf:name ?projectName
}
}
}
## Example of pragma "grab-iri" usage:
DEFINE input:storage ""
DEFINE input:grab-iri
<http://www.openlinksw.com/dataspace/kidehen@openlinksw.com/weblog/kidehen@openlinksw.com%27s%20BLOG%20%5B127%5D/sioc.ttl>
DEFINE input:grab-var "id"
DEFINE input:grab-depth 10
DEFINE input:grab-limit 100
DEFINE input:grab-base
"http://www.openlinksw.com/dataspace/kidehen@openlinksw.com/weblog/kidehen@openlinksw.com%27s%20BLOG%20%5B127%5D/1300"
SELECT ?id
WHERE
{
graph ?g
{
?id a ?o
}
}
LIMIT 10
## Example of pragma "grab-all" usage:
DEFINE input:grab-all "yes"
DEFINE input:grab-depth 10
DEFINE input:grab-limit 100
DEFINE input:grab-base
"http://www.openlinksw.com/dataspace/kidehen@openlinksw.com/weblog/kidehen@openlinksw.com%27s%20BLOG%20%5B127%5D/1300"
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?id ?firstname ?nick
WHERE
{
GRAPH ?g
{
?id rdf:type foaf:Person .
?id foaf:firstName ?firstname .
?id foaf:knows ?fn .
?fn foaf:nick ?nick .
}
}
LIMIT 10
## Example of pragma "grab-seealso" usage:
DEFINE input:grab-iri
<http://www.openlinksw.com/dataspace/kidehen@openlinksw.com/weblog/kidehen@openlinksw.com%27s%20BLOG%20%5B127%5D/sioc.ttl>
DEFINE input:grab-var "id"
DEFINE input:grab-depth 10
DEFINE input:grab-limit 100
DEFINE input:grab-base
"http://www.openlinksw.com/dataspace/kidehen@openlinksw.com/weblog/kidehen@openlinksw.com%27s%20BLOG%20%5B127%5D/1300"
DEFINE input:grab-seealso <foaf:maker>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?id
WHERE
{
GRAPH ?g
{
?id a foaf:Person .
}
}
LIMIT 10
## Example of pragma "grab-limit" usage:
DEFINE input:grab-depth 10
DEFINE input:grab-limit 100
DEFINE input:grab-var "more"
DEFINE input:grab-base
"http://www.openlinksw.com/dataspace/kidehen@openlinksw.com/weblog/kidehen@openlinksw.com%27s%20BLOG%20%5B127%5D/1300"
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?id ?o
WHERE
{
GRAPH ?g
{
?id a foaf:Person .
OPTIONAL { ?id foaf:maker ?more }
?id ?t ?o .
FILTER (!isblank(?id)) .
}
}
LIMIT 10
## Example of pragma "default-graph-uri" usage:
DEFINE input:default-graph-uri <http://mygraph.com>
INSERT INTO <http://mygraph.com>
{
<http://myopenlink.net/dataspace/Kingsley#this>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
<http://rdfs.org/sioc/ns#User>
}
## Example of pragma "grab-follow-predicate" usage:
DEFINE input:grab-var "o"
DEFINE input:grab-follow-predicate foaf:knows
DEFINE input:grab-depth 10
DEFINE input:grab-limit 50
SELECT ?o ?dist
(
(
SELECT COUNT ( * )
WHERE
{
?o foaf:knows ?xx
}
)
) AS ?count
WHERE
{
{
SELECT ?s ?o
WHERE
{
?s foaf:knows ?o .
}
}
OPTION ( transitive,
t_distinct,
t_in ( ?s ),
t_out ( ?o ),
t_min ( 1 ),
t_max ( 4 ),
t_step ( 'step_no' ) AS ?dist
) .
FILTER ( ?s = <http://www.w3.org/People/Berners-Lee/card#i> )
}
ORDER BY ?dist DESC 3
LIMIT 100
## Example of pragma "grab-depth" usage:
DEFINE input:grab-var "dev"
DEFINE input:grab-var "proj"
DEFINE input:grab-var "projectName"
DEFINE input:grab-follow-predicate
<http://usefulinc.com/ns/doap#developer>
DEFINE input:grab-depth 10
DEFINE input:grab-limit 50
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX doap: <http://usefulinc.com/ns/doap#>
SELECT DISTINCT ?name ?mbox ?projectName
WHERE
{
{
{
{
SELECT ?start ?dev
WHERE
{
?start doap:developer ?dev .
}
}
OPTION ( transitive, t_in (?start), t_out (?dev) )
FILTER ( ?start =
<http://dig.csail.mit.edu/2005/ajar/ajaw/data#Tabulator> )
}
?dev foaf:name ?name .
}
OPTIONAL { ?dev foaf:mbox ?mbox } .
OPTIONAL {
?dev doap:project ?proj .
?proj foaf:name ?projectName
}
}
## No Named Graph specificity
## Name Graphs will be created internally based
## on the URLs of dereferenced Document URLs
DEFINE input:grab-var "friend"
DEFINE input:grab-var "Others"
DEFINE input:grab-follow-predicate foaf:knows
DEFINE input:grab-depth 2
DEFINE input:grab-limit 50
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX doap: <http://usefulinc.com/ns/doap#>
SELECT DISTINCT *
WHERE
{
<http://www.openlinksw.com/dataspace/person/kidehen@openlinksw.com#this>
foaf:knows ?friend .
?friend foaf:knows ?Others.
}
DEFINE input:grab-var "friend"
DEFINE input:grab-var "Others"
DEFINE input:grab-follow-predicate
<http://xmlns.com/foaf/0.1/#knows>
DEFINE input:grab-depth 2
DEFINE input:grab-limit 50
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX doap: <http://usefulinc.com/ns/doap#>
SELECT DISTINCT *
WHERE
{
{
{
{
SELECT ?start ?friend
WHERE
{
?start foaf:knows ?friend .
}
}
OPTION ( transitive, t_in (?start), t_out (?friend) )
FILTER ( ?start =
<http://www.w3.org/People/Berners-Lee/card#i> )
}
?friend foaf:knows ?Others .
}
}
LIMIT 10
#Conditional use of owl:sameAs inference rule
DEFINE input:same-as "yes"
PREFIX geonames: <http://www.geonames.org/ontology#>
SELECT *
WHERE
{
?s geonames:parentFeature ?z
}
DEFINE input:grab-follow-predicate
<http://dbpedia.org/property/hasPhotoCollection>
DEFINE input:grab-depth 10
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT DISTINCT *
WHERE
{
<http://dbpedia.org/resource/Munich> foaf:depiction ?z
}
DEFINE input:grab-follow-predicate <foaf:knows>
DEFINE input:grab-depth 10
DEFINE input:grab-limit 100
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?my_id ?Knows ?their_id ?fname
WHERE
{
<http://www.openlinksw.com/dataspace/kidehen@openlinksw.com/weblog/kidehen@openlinksw.com%27s%20BLOG%20%5B127%5D/1300>
foaf:maker ?my_id .
?my_id a foaf:Person .
OPTIONAL { ?my_id foaf:nick ?fname } .
OPTIONAL { ?my_id foaf:knows ?their_id } .
OPTIONAL { ?their_id foaf:nick ?Knows } .
}
## Distinct DBpedia URIs from the sponged resource
DEFINE get:soft "replace"
SELECT DISTINCT ?o ?dbp
FROM <http://webr3.org/__play/optimal/webr3.html>
WHERE
{
?s rdfs:seeAlso ?o .
?o ?p ?dbp
FILTER ( REGEX( str( ?dbp ), ".*Low resolution" ) )
}
SELECT ?o2 ?o3
FROM <http://webr3.org/__play/optimal/webr3.html>
WHERE
{
?s rdfs:seeAlso ?o .
?o <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?o2 .
}
LIMIT 50
## Example by given URI
## http://mypenlink.net/dataspace/person/kidehen#this
## and with transitivity option:
DEFINE input:grab-var "friend"
DEFINE input:grab-var "Others"
DEFINE input:grab-follow-predicate <http://xmlns.com/foaf/0.1/#knows>
DEFINE input:grab-depth 2
DEFINE input:grab-limit 50
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX doap: <http://usefulinc.com/ns/doap#>
SELECT DISTINCT *
WHERE
{
{
{
{
SELECT ?start ?friend
WHERE
{
?start foaf:knows ?friend .
}
}
OPTION ( transitive, t_in (?start), t_out (?friend) )
FILTER ( ?start =
<http://mypenlink.net/dataspace/person/kidehen#this> )
}
?friend foaf:knows ?Others .
}
}
DEFINE input:grab-all "yes"
DEFINE input:grab-depth 1
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT DISTINCT ?friendsname ?friendshomepage
?foafsname ?foafshomepage
WHERE
{
{
{
{
SELECT ?start ?friend
WHERE
{
?start foaf:knows ?friend .
}
}
OPTION ( transitive, t_in (?start), t_out (?friend) )
FILTER ( ?start = <http://www.w3.org/People/Berners-Lee/card> )
}
?friend foaf:mbox_sha1sum ?mbox .
?friendsURI foaf:mbox_sha1sum ?mbox .
?friendsURI foaf:name ?friendsname .
?friendsURI foaf:homepage ?friendshomepage .
}
OPTIONAL {
?friendsURI foaf:knows ?foaf .
?foaf foaf:name ?foafsname .
?foaf foaf:homepage ?foafshomepage .
}
}
DEFINE input:grab-follow-predicate <foaf:knows>
DEFINE input:grab-depth 10
PREFIX sioc: <http://rdfs.org/sioc/ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
CONSTRUCT
{
?s ?p ?o
}
FROM <http://blogs.zdnet.com/semantic-web/?p=105>
WHERE
{
?s ?p ?o
FILTER REGEX( ?o, ".*DataSource*" )
}
DEFINE input:grab-follow-predicate <foaf:knows>
DEFINE input:grab-var "their_id"
DEFINE input:grab-depth 2
DEFINE input:grab-limit 350
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?my_id ?firstname ?Knows ?their_id
FROM NAMED <http://www.openlinksw.com/dataspace/person/kidehen@openlinksw.com>
WHERE
{
GRAPH ?g
{
?my_id a foaf:Person ;
foaf:firstName ?firstname ;
foaf:knows ?their_id .
?their_id foaf:nick ?Knows .
}
}
LIMIT 350
DEFINE input:grab-var "rsf"
DEFINE input:grab-follow-predicate rdfs:seeAlso
DEFINE input:grab-depth 3
DEFINE input:grab-limit 50
SELECT DISTINCT *
WHERE
{
<http://linkeddata.uriburner.com/about/id/entity/http/www.amazon.com/o/ASIN/1591842778> rdfs:seeAlso ?rsf .
?rsf a <http://purl.org/ontology/bibo/Document> .
}