linkedpipes / dcat-ap-viewer

Viewer of DCAT-AP 2.0.1 compatible dataset metadata
MIT License
6 stars 6 forks source link

Optimize SPARQL provider #218

Open jakubklimek opened 3 years ago

jakubklimek commented 3 years ago

The label query does not use the "GRAPH" pattern. Therefore, publisher labels are searched for in cartesian products of many named graphs - the publisher name is present in each dataset graph in out endpoints. https://github.com/linkedpipes/dcat-ap-viewer/blob/5aab9c1233a914a369dabf6504265e0a834346f0/server/sparql-provider/sparql-query.js#L425

Therefore, we need to add option to enclose the WHERE clause in GRAPH {} like this:

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dcterms: <http://purl.org/dc/terms/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
CONSTRUCT { <https://data.gov.cz/zdroj/ovm/MinFin> ?predicate ?object } WHERE { GRAPH ?g {
  <https://data.gov.cz/zdroj/ovm/MinFin> ?predicate ?object .

  OPTIONAL { 
    <https://data.gov.cz/zdroj/ovm/MinFin> ?predicate ?label_primary . 
    FILTER(LANG(?label_primary) = "cs") 
  }
  OPTIONAL { 
    <https://data.gov.cz/zdroj/ovm/MinFin> ?predicate ?label_secondary . 
    FILTER(LANG(?label_secondary) = "en")
  } }

  BIND( COALESCE(?label_primary, ?label_secondary) as ?label )

  VALUES ( ?predicate ) {
   ( foaf:name )
   ( skos:prefLabel )
   ( dcterms:title )
   ( rdfs:label )
  }
}
skodapetr commented 3 years ago

The createLabelSparql method now utilize GRAPH to enclose the content of the query in case of datasetPerGraph set to true.