Sparql Queries Samples

General queries and CIDOC-CRM queries

A. Queries based on the RDF formalism

List of concepts.

SELECT Distinct ?concept
WHERE
{
[] rdf:type ?concept .
}
Order By ?concept

Number of concepts.

SELECT Distinct (Count(Distinct ?concept) As ?numberOfConcepts)
WHERE
{
[] rdf:type ?concept .
}

List of predicates.

SELECT Distinct ?predicate
WHERE
{
?subject ?predicate ?object .
}
Order By ?predicate

Number of predicates.

SELECT Distinct (Count(Distinct ?predicate) As ?numberOfPredicates)
WHERE
{
?subject ?predicate ?object .
}

List of terminal triples where the terminal node is non-empty.

SELECT Distinct ?subject ?predicate ?object
WHERE
{
?subject ?predicate ?object .
Filter ( isLiteral(?object) && ?object != "" )
}

List of terminal predicates where the terminal node is non-empty.

SELECT Distinct ?predicate
WHERE
{
?subject ?predicate ?object .
Filter ( isLiteral(?object) && ?object != "" )
}

Extracts of paths leading to non-empty terminal nodes.

SELECT ?object0 ?predicate0 ?subject0 ?predicate1 ?subject1 ?predicate2 ?subject2
WHERE
{
?subject0 ?predicate0 ?object0 .
Optional {
?subject1 ?predicate1 ?subject0 .
Optional {
?subject2 ?predicate2 ?subject1 .
}
}
Filter ( isLiteral(?object0) && ?object0 != "" )
}

List of triples that have as subject a given node (examples: http://erlangen-crm.org/150929/E39_Actor, http://dbpedia.org/resource/Venus_de_Milo, http://dbpedia.org/resource/Peter_Jackson).

SELECT ?subject ?predicate ?object
WHERE
{
?subject ?predicate ?object .
Filter ( ?subject = <http://erlangen-crm.org/150929/E39_Actor> )
}

B. Queries based on the CIDOC-CRM norm

List of non-empty labels of specific entities by using generic classes: type (E55_Type), title (E35_Title), dimension (E54_Dimension), material (E57_Material), place (E53_Place), etc.

SELECT Distinct ?type
WHERE
{
?type_uri rdf:type ecrm:E55_Type .
?type_uri rdfs:label ?type .
Filter ( ?type != "" )
}

SELECT Distinct ?material
WHERE
{
?material_uri rdf:type ecrm:E57_Material .
?material_uri rdfs:label ?material .
Filter ( ?material != "" )
}

List of non-empty labels of specific entities by using properties: type (P2_has_type), title (P102_has_title), dimension (P43_has_dimension), material (P45_consists_of), place (P87_is_identified_by), etc.

SELECT Distinct ?subject ?title
WHERE
{
?subject ecrm:P102_has_title ?title_uri .
?title_uri rdfs:label ?title .
Filter ( ?title != "" )
}

SELECT Distinct ?subject ?place
WHERE
{
?subject ecrm:P87_is_identified_by ?place_uri .
?place_uri rdfs:label ?place .
Filter ( ?place != "" )
}

List of characteristics (identifier, type, note, etc.) that come from the root entity "E1 CRM Entity".

SELECT Distinct ?id1 ?id2 ?type ?description
WHERE
{
?e1_obj ecrm:P48_has_preferred_identifier ?id1_uri .
?id1_uri rdfs:label ?id1 .
?e1_obj ecrm:P1_is_identified_by ?id2_uri .
?id2_uri rdfs:label ?id2 .
?e1_obj ecrm:P2_has_type ?type_uri .
?type_uri rdfs:label ?type .
?e1_obj ecrm:P3_has_note ?description .
}

List of characteristics (dimension, title, material) that come from persistent entities (different from the root entity "E1 CRM Entity").

SELECT Distinct ?id1 ?dimensions ?title ?material
WHERE
{
?obj ecrm:P48_has_preferred_identifier ?id1_uri .
?id1_uri rdfs:label ?id1 .

?obj ecrm:P43_has_dimension ?dimensions_uri .
?dimensions_uri rdfs:label ?dimensions .
?obj ecrm:P102_has_title ?title_uri .
?title_uri rdfs:label ?title .
?obj ecrm:P45_consists_of ?material_uri .
?material_uri rdfs:label ?material .
}

Datation (date) of origin of objects.

SELECT Distinct ?id1 ?time_span_uri ?dateOrigin
WHERE
{
?obj ecrm:P48_has_preferred_identifier ?id1_uri .
?id1_uri rdfs:label ?id1 .

?obj ecrm:P92i_was_brought_into_existence_by ?e63_beginning_of_existence .

?e63_beginning_of_existence ecrm:P4_has_time-span ?time_span_uri .
?time_span_uri ecrm:P78_is_identified_by ?time_appellation_uri .
?time_appellation_uri rdfs:label ?dateOrigin .

Filter ( ?dateOrigin != "" )
}

Origin of objects (date, place, participants).

SELECT Distinct ?id1 ?dateOrigin ?placeOrigin ?actorOrigin
WHERE
{
?obj ecrm:P48_has_preferred_identifier ?id1_uri .
?id1_uri rdfs:label ?id1 .

?obj ecrm:P92i_was_brought_into_existence_by ?e63_beginning_of_existence .

?e63_beginning_of_existence ecrm:P4_has_time-span ?time_span_uri .
?time_span_uri ecrm:P78_is_identified_by ?time_appellation_uri .
?time_appellation_uri rdfs:label ?dateOrigin .

?e63_beginning_of_existence ecrm:P7_took_place_at ?place_uri .
?place_uri ecrm:P87_is_identified_by ?place_appellation_uri .
?place_appellation_uri rdfs:label ?placeOrigin .

?e63_beginning_of_existence ecrm:P11_had_participant ?actor_uri .
?actor_uri rdfs:label ?actorOrigin .
}

Localisation (place) of custody of objects.

SELECT Distinct ?place_custody_uri ?placeCustody
WHERE
{
?obj ecrm:P30i_custody_transferred_through ?e10_transfer_of_custody .

?e10_transfer_of_custody ecrm:P7_took_place_at ?place_custody_uri .
?place_custody_uri ecrm:P87_is_identified_by ?place_appellation_custody_uri .
?place_appellation_custody_uri rdfs:label ?placeCustody .

Filter ( ?placeCustody != "" )
}

Transfer of Custody of objects (date, place, participants).

SELECT Distinct ?id1 ?dateCustody ?placeCustoddy ?actorCustody
WHERE
{
?obj ecrm:P48_has_preferred_identifier ?id1_uri .
?id1_uri rdfs:label ?id1 .

?obj ecrm:P30i_custody_transferred_through ?e10_transfer_of_custody .

?e10_transfer_of_custody ecrm:P4_has_time-span ?time_span_custody_uri .
?time_span_custody_uri ecrm:P78_is_identified_by ?time_appellation_custody_uri .
?time_appellation_custody_uri rdfs:label ?dateCustody .

?e10_transfer_of_custody ecrm:P7_took_place_at ?place_custody_uri .
?place_custody_uri ecrm:P87_is_identified_by ?place_custody_appellation_uri .
?place_custody_appellation_uri rdfs:label ?placeCustody .

?e10_transfer_of_custody ecrm:P11_had_participant ?actor_custody_uri .
?actor_custody_uri rdfs:label ?actorCustody .
}