This page presents a set of SPARQL queries used to build SPARQL Builder Metadata (SBM). Because SBM are simple but essential data that describes RDF graph structure on SPARQL endpoints, similar metadata specifications have been proposed so far: however, SBM is designed with original specialised vocabulary to build SPARQL query for lice-science RDF datasets interactively with users. To describe informal semantics of SBM vocabulary, the SPARQL queries used in the SBM crawler, a component to traverse on a SPARQL endpoint and generate its SBM, are listed below with the corresponding SBM properties and classes.
[About this document]
The developers of the SPARQL Builder including SBM would like to contribute with standardisation processes among similar projects by research collaboration, specification proposal and specification induction. Please feel free to discuss with us; any suggestions and opinions are welcome.
SPARQL Builder Metadata and their SPARQL queries
(SPARQL Builder Metadata version May 2014)
1. SPARQL endpoint and graph
QUERY 1, Obtain graph URIs on a SPARQL endpoint.
SELECT DISTINCT ?g WHERE{ GRAPH ?g{ ?s ?p ?o.} }
2. Class
QUERY 2, Obtain the classes c on a graph g
PREFIX rdfs: PREFIX rdf: 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. } }
QUERY 3, Obtain the classes c having instances on a graph g
PREFIX rdf: SELECT DISTINCT ?c FROM <g> WHERE{ [] rdf:type ?c. }
QUERY 4, Obtain the label of the class c from a graph g
PREFIX rdfs: SELECT DISTINCT ?label FROM <g> WHERE{ <c> rdfs:label ?label. }
QUERY 5, Obtain the label of the list of classes c1, c2,…,cn from a graph g
PREFIX rdfs: SELECT DISTINCT ?c ?label FROM <g> WHERE{ ?c rdfs:label ?label. ?c IN (c1, c2, ..., cn) }
QUERY 6, Obtain the number num of instances of class c on a graph g
PREFIX rdfs: PREFIX rdf: SELECT (count(DISTINCT ?i) AS ?num) FROM <g> WHERE{ {?i rdf:type <c>.} UNION { [] ?p ?i. ?p rdfs:range <c>. } UNION { ?i ?p []. ?p rdfs:domain <c>. } }
3. Property
QUERY 7, Obtain the domain classes d of property p on a graph g
// To get properties apearing in the dataset: SELECT DISTINCT ?p FROM <g> WHERE{ ?s ?p ?o. }
QUERY 8, Obtain the domain classes d of property p on a graph g
PREFIX rdfs: SELECT DISTINCT ?d FROM <g> WHERE{ <p> rdfs:domain ?d. }
QUERY 9, Obtain the range classes r of property p on a graph g
PREFIX rdfs: SELECT DISTINCT ?r FROM <g> WHERE{ <p> rdfs:range ?r. }
QUERY 10, Obtain the class-class relationships (d-r) extracted from triples including the property p on a graph g
PREFIX rdfs: PREFIX rdf: SELECT DISTINCT ?d ?r FROM <g> WHERE{ ?i <p> ?o. OPTIONAL{ ?i rdf:type ?d.} OPTIONAL{ ?o rdf:type ?r.} }
QUERY 11, Obtain the class-datatype relationships (d-idt) extracted from triples including the property p on a graph g
PREFIX rdf: SELECT DISTINCT ?d (datatype(?o) AS ?ldt) FROM <g> WHERE{ ?i <p> ?o. OPTIONAL{ ?i rdf:type ?d.} FILTER(isLiteral(?o)) }
QUERY 12, Obtain the numbers numTripes, numDomIns and numRanIns of triples, subject instances of class d and object instances of class r from triples including the property p on a graph g
PREFIX rdf: SELECT (count(?i) AS ?numTriples) (count(DISTINCT ?i) AS ?numDomIns) (count(DISTINCT ?o) AS ?numRanIns) FROM <g> WHERE{ SELECT DISTINCT ?i ?o WHERE{ ?i <p> ?o. ?i rdf:type <d>. ?o rdf:type <r>. } }
QUERY 13, Obtain the numbers numTripes, numDomIns and numRanIns of triples, subject instances of class d and object literals of type idt from triples including the property p on a graph g
PREFIX rdf: SELECT (count(?i) AS ?numTriples) (count(DISTINCT ?i) AS ?numDomIns) (count(DISTINCT ?o) AS ?numRanIns) FROM <g> WHERE{ SELECT DISTINCT ?i ?o WHERE{ ?i <p> ?o. ?i rdf:type ?d. FILTER( datatype(?o) = <idt> } }
QUERY 14, Obtain the numbers numTripes, numDomIns and numRanIns of triples, subjects and objects from triples including the property p on a graph g
SELECT (count(?i) AS ?numTriples) (count(DISTINCT ?i) AS ?numDomIns) (count(DISTINCT ?o) AS ?numRanIns) FROM <g> WHERE{ ?i <p> ?o. }
QUERY 15, Obtain the numbers numTripesWithDom and numDomIns of triples and triples whose subject instances are associated with a class from triples including the property p on a graph g
PREFIX rdf: SELECT (count(DISTINCT ?i) AS ?numDomIns) (count(?i) AS ?numTriplesWithDom) FROM <g> WHERE { SELECT DISTINCT ?i ?o WHERE{ ?i <p> ?o. ?i rdf:type ?d. } }
QUERY 16, Obtain the numbers numTripesWithRan and numRanIns of triples and triples whose object instances are associated with a class from triples including the property p on a graph g
PREFIX rdf: SELECT (count(DISTINCT ?o) AS ?numRanIns) (count(?o) AS ?numTriplesWithRan) FROM <g> WHERE { SELECT DISTINCT ?i ?o WHERE{ ?i <p> ?o. ?o rdf:type ?r. } }
QUERY 17, Obtain the numbers numTriplesWithRan and numRanIns of triples and triples whose object literals from triples including the property p on a graph g
SELECT (count(DISTINCT ?o) AS ?numRanIns) (count(?o) AS ?numTriplesWithRan) FROM <g> WHERE { SELECT DISTINCT ?i ?o WHERE{ ?i <p> ?o. FILTER(isLiteral(?o)) } }
QUERY 18, Obtain the properties p, domain class d and range class r of the property p on a graph g
PREFIX rdfs: SELECT ?p ?d ?r FROM <g> WHERE{ ?p rdfs:domain ?d. ?p rdfs:range ?r. }
4. Datatype
QUERY 19, Obtain the datatypes idt on a graph g
SELECT DISTINCT (datatype(?o) AS ?ldt) FROM <g> WHERE{ [] ?p ?o. FILTER(isLiteral(?o)) }