Skip to main content

Querying the different layers of the catalog graph

How do I query my catalog?

Now that you understand the different layers that make the catalog, let us find how you can query the catalog.

  • To query the merged layer, add FROM :current to the SPARQL query.

    As an example, the following query gives you the list of business terms available in the merged layer. By default the query results include the deleted resources. The sample query provides a way to exclude the terms that are deleted.

    SELECT *
    FROM :current
    WHERE {
        ?s a dwec:BusinessTerm;
         dct:title       ?title;
         dct:description ?description.   
     #exclude deleted business terms   
     MINUS {       
     ?s a dwec:HiddenEntity.  
      }
    }
    sample_query.png
  • To query the base layer, add FROM : to your SPARQL query.

    As an example, the following query gives you the list of business terms that are added in the base layer. By default the query results include the deleted resources. The sample query provides a way to exclude the terms that are deleted.

    SELECT *
    FROM :
    WHERE {
        ?s a dwec:BusinessTerm;
         dct:title       ?title;
         dct:description ?description.   
     #exclude deleted business terms   
     MINUS {       
     ?s a dwec:HiddenEntity.  
      }
    }
    sample_query01.png
  • To query the edit layer, add FROM :edit to the SPARQL query.

    As an example, the following query gives you the list of business terms that are added from the edit layer. By default the query results include the deleted resources. The sample query provides a way to exclude the terms that are deleted.

    SELECT *
    FROM :edit
    WHERE {
        ?s a dwec:BusinessTerm;
         dct:title       ?title;
         dct:description ?description.   
     #exclude deleted business terms   
     MINUS {       
     ?s a dwec:HiddenEntity.  
      }
    }
    sample_query02.png

How do I find edits made to resources in the edit layer?

Use the following query to find all the places where one property value is replaced by another in the edit layer.

SELECT *
FROM NAMED :
FROM NAMED :current
FROM NAMED :edit
WHERE {
# find all the places where a value has been changed in :edit
GRAPH : { ?resource ?predicate ?from . }
GRAPH :edit { ?resource ?predicate ?to . }
GRAPH :current { ?resource ?predicate ?to . }
}

Sample results:

Querying_edits_to_resources.png

How do I find additions made to resources in the edit layer?

Use the following query to find all the properties that are added in the edit layer.

Important

This query does not include information about datasets and projects, which are added to the catalog via the edit layer.

SELECT *
FROM NAMED :
FROM NAMED :current
FROM NAMED :edit
WHERE {
# find all the places where a value has been "added" in :edit
GRAPH :edit { ?resource ?predicate ?to . }
GRAPH :current { ?resource ?predicate ?to . }
FILTER NOT EXISTS {
GRAPH : { ?resource ?predicate [] . }
}
}

Sample results:

Querying_additions_to_resources.png

How do I find properties removed from resources?

Use the following query to find why a property that is available in the base layer is not visible in the UI.

SELECT *
FROM NAMED :
FROM NAMED :current
FROM NAMED :edit
WHERE {
{
# all the (subject, predicate) tombstones
GRAPH :edit {
[
a dwec:RemoveTriplePattern ;
rdf:subject ?resource ;
rdf:predicate ?predicate ;
] .
}
}
UNION
{
# all the (subject, predicate, object) tombstones
GRAPH :edit {
[
a dwec:RemoveTriple ;
rdf:subject ?resource ;
rdf:predicate ?predicate ;
rdf:object ?from ;
] .
}
}
}

Sample results:

catalog_layers_05.png

How do I find a list of Soft Deleted resources?

Use the following query to check for soft deletes across the base layer and the edit layer.

SELECT *
FROM NAMED :
FROM NAMED :current
FROM NAMED :edit
WHERE {
# check for soft deletes across both of these graphs
VALUES ?g { : :edit }
GRAPH ?g { ?resource a dwec:HiddenEntity . }
GRAPH :current { ?resource a dwec:HiddenEntity . }
}

Sample results:

catalog_layers_06.png

Is there a way to get a single report of all changes to the catalog layers?

This query is a report across any catalog that ties together all of the above into a single report. This should help troubleshoot any issues that stem from layer confusion in the catalog.

SELECT *
FROM NAMED :
FROM NAMED :current
FROM NAMED :edit
WHERE {
{
VALUES ?situation { "resource deleted in base layer" }
GRAPH : { ?resource a dwec:HiddenEntity . }
}
UNION
{
VALUES ?situation { "resource deleted in edit layer" }
GRAPH :edit { ?resource a dwec:HiddenEntity . }
GRAPH :current { ?resource a dwec:HiddenEntity . }
}
UNION
{
VALUES ?situation { "value changed in edit layer" }
GRAPH : { ?resource ?predicate ?from . }
GRAPH :edit { ?resource ?predicate ?to . }
GRAPH :current { ?resource ?predicate ?to . }
}
UNION
{
VALUES ?situation { "value added in edit layer" }
GRAPH :edit { ?resource ?predicate ?to . }
GRAPH :current { ?resource ?predicate ?to . }
FILTER NOT EXISTS {
GRAPH : { ?resource ?predicate [] . }
}
}
UNION
{
VALUES ?situation { "all values for property removed in edit layer" }
GRAPH :edit {
[
a dwec:RemoveTriplePattern ;
rdf:subject ?resource ;
rdf:predicate ?predicate ;
] .
}
}
UNION
{
VALUES ?situation { "specific triple removed in edit layer" }
GRAPH :edit {
[
a dwec:RemoveTriple ;
rdf:subject ?resource ;
rdf:predicate ?predicate ;
rdf:object ?from ;
] .
}
}
}

Sample results:

catalog_layers_07.png

Can I remove edits made in the edit layer and restore the base layer?