SPARQL Queries

In the context of TED-SWS, SPARQL queries can be used to query the data of notices published in RDF by the Publications Office. These queries can be made on the SPARQL end point available in EU Vocabularies

SPARQL stands for "SPARQL Protocol and RDF Query Language". SPARQL queries retrieve and manipulate data stored in RDF (Resource Description Framework) format. It allows users to write complex queries to retrieve specific information from RDF datasets.

The data available covers Contract Award Notices published after 28/08/2023. Data on eForm Result notices are not yet available.

A query is submitted to the SPARQL end point by replacing the text highlighted below in blue in the Query Text box below with the desired query:

SPARQL End Point
Figure 1. End point user interface

The format of the result can be changed using the drop-down box of the Results format.

Once the query is in place, and the Results format chosen, the query can be run by pressing “Run Query”.

Below are some query examples:

Query: How many contractors are SMEs for a given country and given date ?

 

This SPARQL query aims to count the number of distinct procurement notices that meet specific criteria related to publication date, country code (Germany), and business size (SME).

The query retrieves:

  • The number of distinct procurement notices

The notice publication date, organization country and organization size can be changed to create other queries. To do this, change the following section:

VALUES (?NoticePublicationDate ?CountryCode ?BusinessSize) {
        ("20230905"
        <http://publications.europa.eu/resource/authority/country/DEU>
        <http://publications.europa.eu/resource/authority/economic-operator-size/sme>)
  • Existing value for publication date in example above:

    "20230905"
  • Existing value for organization country in example above:

    <http://publications.europa.eu/resource/authority/country/DEU>
  • Existing value for organization size in example above:

    <http://publications.europa.eu/resource/authority/economic-operator-size/sme>

Query text:

PREFIX epo: <http://data.europa.eu/a4g/ontology#>
PREFIX cccev: <http://data.europa.eu/m8g/>
SELECT
(COUNT(DISTINCT ?Notice) as ?NrOfNotices)
WHERE {
    VALUES (?NoticePublicationDate ?CountryCode ?BusinessSize) {
            ("20230905"
            <http://publications.europa.eu/resource/authority/country/DEU>
            <http://publications.europa.eu/resource/authority/economic-operator-size/sme>)
    }
    ?Notice epo:hasPublicationDate ?NoticePublicationDate .
    ?Notice epo:announcesRole ?Winner .
    ?Winner a epo:Winner ;
            epo:playedBy ?Organization .
    ?Organization epo:hasBusinessSize ?BusinessSize .
    ?Organization cccev:registeredAddress / epo:hasCountryCode ?CountryCode .
}

Query: Which notices have been published by Buyers from a specific country for a given date ?

 

This SPARQL query retrieves information about contract award notices that have been published by buyers from Germany and published on TED on 05-09-2023.

The query retrieves:

  • The ID of the resource which contains the Notice ID

  • The URI of the organisation within the notice

  • The name of the buyer.

It does so by specifying a set of values and then querying the RDF data based on those values. The query returns information about the notices, the organizations (buyers), and their legal names.

The publication date and organization country can be changed to create other queries. To do this, change the following section:

VALUES (?PublicationDate ?countryCode) {
        ("20230905" <http://publications.europa.eu/resource/authority/country/DEU>)
}
  • Existing value for publication date in example above:

    "20230905"
  • Existing value for organization country in example above:

    <http://publications.europa.eu/resource/authority/country/DEU>

Query text:

PREFIX epo: <http://data.europa.eu/a4g/ontology#>
PREFIX cccev: <http://data.europa.eu/m8g/>
PREFIX org: <http://www.w3.org/ns/org#>
SELECT DISTINCT
?Notice
?Organization
?LegalName
WHERE {
    VALUES (?PublicationDate ?countryCode) {
            ("20230905" <http://publications.europa.eu/resource/authority/country/DEU>)
    }
    ?Notice epo:hasPublicationDate ?PublicationDate .
    ?Notice epo:announcesRole ?Buyer .
    ?Buyer a epo:Buyer ;
            epo:playedBy ?Organization .
    ?Organization cccev:registeredAddress / epo:hasCountryCode ?countryCode .
    ?Organization epo:hasLegalName ?LegalName .
}

Query: Who are the winners for a given date ?

 

This SPARQL query aims to retrieve information about the winners of procurement lots for a specific date ("20230831" or 31-08-2023). It does so by specifying a value for the publication date, and then querying the RDF data based on that value. The query returns information about the lots, the organizations that won them, and details about the awarded amounts and currencies.

The query retrieves:

  • Winner Legal Name

  • Winner Country Code

  • Lot value awarded to winner

  • The currency of the awarded value

The notice publication date and winner legal name language can be changed to create other queries. To do this, change the following section:

VALUES ?NoticePublicationDate {
    "20230905"
}
FILTER(LANG(?WinnerLegalName) = 'en')
  • Existing value for publication date in example above:

    "20230905"
  • Existing value for winner legal name language in example above:

    'en'

Query text:

PREFIX epo: <http://data.europa.eu/a4g/ontology#>
PREFIX org: <http://www.w3.org/ns/org#>
PREFIX cccev: <http://data.europa.eu/m8g/>
SELECT DISTINCT
?WinnerLegalName
(SAMPLE(?WinnerCountryCode) as ?WinnereCountryCodeURI)
(SUM(?AwardedValue) as ?TotalAwardedValue)
(?AwardedValueCurrency as ?AwardedValueCurrencyURI)
WHERE {
    VALUES ?NoticePublicationDate {
        "20230905"
    }
    FILTER(LANG(?WinnerLegalName) = 'en')
    ?Notice a epo:Notice;
            epo:hasPublicationDate ?NoticePublicationDate ;
            epo:refersToLot ?Lot .
    ?LotAwardOutcome epo:describesLot ?Lot ;
                     epo:hasAwardedValue ?MonetaryValue ;
                     epo:comprisesTenderAwardOutcome ?TenderAwardOutcome.
    ?TenderAwardOutcome a epo:TenderAwardOutcome;
                        epo:indicatesAwardOfLotToWinner / epo:playedBy ?Winner.
    ?Winner a org:Organization;
            epo:hasLegalName ?WinnerLegalName .
    OPTIONAL {
        ?Winner cccev:registeredAddress / epo:hasCountryCode ?WinnerCountryCode.
    }
    ?MonetaryValue a epo:MonetaryValue;
                   epo:hasAmountValue ?AwardedValue;
                   epo:hasCurrency ?AwardedValueCurrency .
}
GROUP BY ?WinnerLegalName ?AwardedValueCurrency

Query: Which is the highest value published for a contract award for a given date ?

 

This SPARQL query aims to retrieve the procurement notice, its publication date, the corresponding lot, and the highest awarded amount along with the currency code for a specific date ("20230905" or 05-09-2023). It does so by specifying a value for the date and then querying the RDF data based on that value. The query returns the information in descending order of the awarded amount, with only the highest value being displayed.

The query retrieves:

  • Lot URI

  • The legal name of the winner

  • The winners country code as URI

  • Lot value awarded to winner

  • The currency of the awarded value

The notice publication date and winner legal name language can be changed to create other queries. To do this, change the following section:

VALUES (?NoticePublicationDate ?LotAwardedValueCurrency) {
    ("20230905" <http://publications.europa.eu/resource/authority/currency/EUR>)
}
FILTER(LANG(?WinnerLegalName) = 'en')
  • Existing value for publication date in example above:

    "20230905"
  • Existing value for winner legal name language in example above:

    'en'
  • EXisting value for currency in example above:

    <http://publications.europa.eu/resource/authority/currency/EUR>

Query text:

PREFIX epo: <http://data.europa.eu/a4g/ontology#>
PREFIX org: <http://www.w3.org/ns/org#>
PREFIX cccev: <http://data.europa.eu/m8g/>
SELECT
?LotURI
?WinnerLegalName
?WinnerCountryCode
?LotAwardedValue
?LotAwardedValueCurrency
WHERE {
    VALUES (?NoticePublicationDate ?LotAwardedValueCurrency) {
        ("20230905" <http://publications.europa.eu/resource/authority/currency/EUR>)
    }
    FILTER(LANG(?WinnerLegalName) = 'en')
    ?Notice epo:hasPublicationDate ?NoticePublicationDate ;
            epo:refersToLot ?LotURI .
    ?LotAwardOutcome epo:describesLot ?LotURI ;
                     epo:hasAwardedValue ?MonetaryValue ;
                     epo:comprisesTenderAwardOutcome ?TenderAwardOutcome.
    ?TenderAwardOutcome a epo:TenderAwardOutcome;
                        epo:indicatesAwardOfLotToWinner / epo:playedBy ?Winner.
    ?Winner a org:Organization;
            epo:hasLegalName ?WinnerLegalName .
    OPTIONAL {
        ?Winner cccev:registeredAddress / epo:hasCountryCode ?WinnerCountryCode.
    }
    ?MonetaryValue a epo:MonetaryValue;
                   epo:hasAmountValue ?LotAwardedValue;
                   epo:hasCurrency ?LotAwardedValueCurrency .
}
ORDER BY DESC(?LotAwardedValue)
LIMIT 1

Any comments on the documentation?