Skip to content
Shuichi Kawashima edited this page Jun 23, 2016 · 4 revisions

2.4 Usefulness

Listing 4: Obtain graph URIs on a SPARQL endpoint

SELECT DISTINCT ?g
WHERE {
  GRAPH ?g {?s ?p ?o .}
}

Listing 5: Obtain the classes on a graph g

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?c
FROM <g>
WHERE {
  { ?c rdf:type rdfs:Class . }
  UNION
  { [] rdf:type ?c . }
  UNION
  { [] rdfs:domain ?c . }
  UNION
  { [] rdfs:range ?c . }
  UNION
  {?c rdfs:subClassOf [] . }
  UNION
  { [] rdfs:subClassOf ?c .}
}
LIMIT 100

Listing 6: Obtain the classes having instances on a graph g

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT DISTINCT ?c
FROM <g>
WHERE {
  [] rdf:type ?c .
}

Listing 7: Obtain labels of the classes c1 c2 ... cn from a graph g

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT DISTINCT ?c ?label
WHERE {
  GRAPH <g> {
    ?c rdfs:label ?label .
    FILTER (?c IN (<c1>, <c2>, ..., <cn>))
  }
}

Listing 7: Obtain the datatypes on a graph g

SELECT DISTINCT (datatype(?o) AS ?ldt)
FROM <g>
WHERE {
  [] ?p ?o .
  FILTER (isLiteral(?o))
}

Listing 9: Obtain the properties on a graph g

SELECT DISTINCT ?p
WHERE {
  ?s ?p ?o .
}

2.5 Validity

Listing 10: A query for searching non-URI subjects

SELECT *
WHERE {
  GRAPH ?g {?s ?p ?o} .
    FILTER (!isURI(?s) &&
            !isBLANK(?s) &&
            ?g NOT IN (<http://www.openlinksw.com/schemas/virtrdf#>)
           )
}
LIMIT 1

Listing 11: A query for searching non-HTTP-URI subjects

SELECT *
WHERE {
  GRAPH ?g {?s ?p ?o} .
    FILTER (!regex(?s, "http://", "i") &&
            !isBLANK(?s) &&
            ?g NOT IN (<http://www.openlinksw.com/schemas/virtrdf#>)
           )
}
LIMIT 1

Listing 12: A query for a subject

SELECT *
WHERE {
  GRAPH ?g {?s ?p ?o} .
  FILTER (!isURI(?s) &&
          ?g NOT IN (<http://www.openlinksw.com/schemas/virtrdf#>)
         )
}
LIMIT 1
OFFSET 100

Listing 13: A query for a sameAs statement

PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT *
WHERE {
  GRAPH ?g {?s owl:sameAs ?o} .
}
LIMIT 1

Listing 14: A query for a seeAlso statement

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT *
WHERE {
  GRAPH ?g {?s rdfs:seeAlso ?o} .
}
LIMIT 1

Listing 15: A most simple query

ASK {}

Listing 16: A query for listing graphs

SELECT DISTINCT ?g
WHERE {
  GRAPH ?g {?s ?p ?o}
}
Clone this wiki locally