@prefix ex: <https://sparql.uniprot.org/.well-known/sparql-examples/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <https://schema.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix spex:<https://purl.expasy.org/sparql-examples/ontology#> .

ex:43 a sh:SPARQLExecutable,
        sh:SPARQLSelectExecutable ;
    rdfs:comment "Connect patents cited in UniProtKB with those in the patent database at EPO via publication number, whose grant date is more than twenty years in the past."@en ;
    sh:prefixes _:sparql_examples_prefixes ;
    sh:select """PREFIX patent: <http://data.epo.org/linked-data/def/patent/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX up: <http://purl.uniprot.org/core/>

SELECT ?grantDate ?patent ?application ?applicationNo
WHERE
{
    ?citation a up:Patent_Citation ;
  skos:exactMatch ?patent .
  BIND(SUBSTR(STR(?patent), 35) AS ?applicationNo)
  BIND(SUBSTR(STR(?patent), 33, 2) AS ?countryCode)
  SERVICE <https://data.epo.org/linked-data/query>{
    ?publication patent:publicationNumber ?applicationNo ;
      patent:application ?application .
    ?application patent:grantDate ?grantDate .
  }
  BIND((year(now()) - 20) AS ?thisYearMinusTwenty)
  BIND(year(?grantDate) AS ?grantYear)
  FILTER(?grantYear < ?thisYearMinusTwenty)
} ORDER BY ?grantYear""" ;
    schema:keywords "EPO" , "cross-reference" , "patent" , "federated query", "entry history" ;
    schema:target <https://sparql.uniprot.org/sparql/> ;
    spex:federatesWith <https://data.epo.org/linked-data/query> .

