79322315

Date: 2025-01-01 21:00:54
Score: 2.5
Natty:
Report link

Using suggestion from Ivo Velitchkov I have been able to update the code in my original question to form a working TED URL.

import sparqldataframe
import pandas as pd

# Define the SPARQL query
sparql_query = """
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX epo: <http://data.europa.eu/a4g/ontology#>  
PREFIX cccev: <http://data.europa.eu/m8g/>  
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>  
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dcterms: <http://purl.org/dc/terms/>

SELECT DISTINCT ?publicationNumber ?legalName ?publicationDate ?title ?description WHERE {
  
  GRAPH ?g {
      ?notice a epo:Notice ; 
        epo:hasPublicationDate ?publicationDate ;
        epo:hasNoticePublicationNumber ?publicationNumber ;
        epo:announcesRole [  
          a epo:Buyer ;  
           epo:playedBy [
                  epo:hasLegalName ?legalName ;
                  cccev:registeredAddress [
                    epo:hasCountryCode ?countryUri
                ] 
            ]  
        ] ;
        epo:refersToProcedure [
            dcterms:title ?title ;
            dcterms:description ?description 
        ] .
  }
  
  ?countryUri a skos:Concept ;
      skos:prefLabel "Ireland"@en .

  FILTER(CONTAINS(LCASE(STR(?legalName)), "dublin city council"))
} 
ORDER BY ?publicationDate
"""

# SPARQL endpoint URL
endpoint_url = "https://publications.europa.eu/webapi/rdf/sparql"

# Execute the SPARQL query
try:
    df = sparqldataframe.query(endpoint_url, sparql_query)
    
    if not df.empty:
        # Build the TED URL based on the publication number and drop leading zeros
        df['noticeTEDuri'] = df['publicationNumber'].apply(
            lambda x: f"https://ted.europa.eu/en/notice/-/detail/{int(x.split('-')[0])}-{x.split('-')[-1]}"
        )
        
        # Display the results
        print("Tender Details with TED URLs for Dublin City Council:")
        print(df[['publicationNumber', 'legalName', 'publicationDate', 'title', 'description', 'noticeTEDuri']])
    else:
        print("No tenders found for Dublin City Council.")
except Exception as e:
    print("An error occurred while querying the SPARQL endpoint:", str(e))

This gives a result where a working TED url is constructed using the publicationNumber.

TED Publication Number

TED Publication Number

TED URL

TED URL constructed from TED Publication Number

What I am looking for is a field that I can hopefully retrieve using SPARQL query

etenders URL containing Resource ID

Reasons:
  • Blacklisted phrase (2): I am looking for
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Christopher