Skip to content

Concept specificity SPARQL queries

Jindrich Mynarz edited this page Jan 13, 2015 · 3 revisions

Here we show example SPARQL queries for computing CPV concept specificity.

Sum of weighted frequencies of all CPV concepts

PREFIX pc: <http://purl.org/procurement/public-contracts#>

SELECT (SUM(?contractWeight) AS ?count)
WHERE {
  {
    SELECT DISTINCT ?contract ?contractWeight
    WHERE {
      GRAPH <http://linked.opendata.cz/resource/dataset/vestnikverejnychzakazek.cz/2014-08-25> {
        VALUES ?objectProperty {
          pc:mainObject
          pc:additionalObject
        }
        ?contract a pc:Contract ;
          ?objectProperty [] .
        OPTIONAL {
          ?parentContract pc:lot ?contract .
        }
        BIND (IF(BOUND(?parentContract), 0.5, 1) AS ?contractWeight)
      }
    }
  }
}

Concept specificity for asserted CPV concepts

PREFIX pc: <http://purl.org/procurement/public-contracts#>

SELECT ?cpv (SUM(?weight) AS ?weightedFrequency)
WHERE {
  {
    SELECT DISTINCT ?contract ?cpv ((?propertyWeight * ?contractWeight) AS ?weight)
    WHERE {
      GRAPH <http://linked.opendata.cz/resource/dataset/vestnikverejnychzakazek.cz/2014-08-25> {
        VALUES (?objectProperty     ?propertyWeight) {
               (pc:mainObject       1)
               (pc:additionalObject 0.5)
        }
        ?contract a pc:Contract ;
          ?objectProperty ?cpv .
        OPTIONAL {
          ?parentContract pc:lot ?contract .
        }
        BIND (IF(BOUND(?parentContract), 0.5, 1) AS ?contractWeight)
      }
    }
  }
}
GROUP BY ?cpv

Concept specificity for inferred CPV concepts

PREFIX pc:   <http://purl.org/procurement/public-contracts#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

SELECT ?cpv (SUM(?weight) AS ?weightedFrequency)
WHERE {
  {
    SELECT DISTINCT ?contract ?explicitCPV ((?propertyWeight * ?contractWeight) AS ?weight)
    WHERE {
      GRAPH <http://linked.opendata.cz/resource/dataset/vestnikverejnychzakazek.cz/2014-08-25> {
        VALUES (?objectProperty     ?propertyWeight) {
               (pc:mainObject       1)
               (pc:additionalObject 0.5)
        }
        ?contract a pc:Contract ;
          ?objectProperty ?explicitCPV .
        OPTIONAL {
          ?parentContract pc:lot ?contract .
        }
        BIND (IF(BOUND(?parentContract), 0.5, 1) AS ?contractWeight)
      }
    }
  }
  GRAPH <http://linked.opendata.cz/resource/dataset/cpv-2008> {
    ?explicitCPV skos:broaderTransitive+ ?cpv .
  }
}
GROUP BY ?cpv
Clone this wiki locally