1 of 22

Accessing data with SPARQL

  • SPARQL is a query language to search RDF triples
  • Cellar ‘s SPARQL editor: http://publications.europa.eu/webapi/rdf/sparql

​

1

Part 4: Access and Usage

2 of 22

To retrieve who-is-who data

2

Part 4: Access and Usage

Accessing data with SPARQL

3 of 22

To retrieve who-is-who data for a person

3

PREFIX cdm: <http://publications.europa.eu/ontology/cdm#>

PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

PREFIX foaf: <http://xmlns.com/foaf/0.1/>

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

PREFIX euvoc: <http://publications.europa.eu/ontology/euvoc#>

PREFIX org: <http://www.w3.org/ns/org#>

PREFIX vcard: <http://www.w3.org/2006/vcard/ns#>

PREFIX person: <http://publications.europa.eu/resource/person>

​

SELECT distinct ?person ?hasMembership ?org ?prefLabel ?familyName ?givenName ?citizenship ?img ?hasHonorificPrefix ?role

?prefLabelRole ?positionComplement ?homepage ?hasEmail ?tel

WHERE{

?person rdf:type foaf:Person.

?person org:hasMembership ?hasMembership.

FILTER(str(?familyName)= 'VON DER LEYEN').

optional{?hasMembership org:organization ?org

optional{?org skos:prefLabel ?prefLabel.FILTER(LANGMATCHES(LANG(?prefLabel),"en"))}

?person foaf:familyName ?familyName.

OPTIONAL{?person foaf:givenName ?givenName.}

OPTIONAL{?person person:citizenship ?citizenship.}

OPTIONAL{?person foaf:img ?img}

OPTIONAL{?person vcard:hasHonorificPrefix ?hasHonorificPrefix.}

optional{?hasMembership org:role ?role. ?role skos:prefLabel ?prefLabelRole. FILTER(LANGMATCHES(LANG(?prefLabelRole),"en"))}

optional{?hasMembership euvoc:positionComplement ?positionComplement. FILTER(LANGMATCHES(LANG(?positionComplement),"en"))}

OPTIONAL{?hasMembership euvoc:contactPoint ?contactPoint.

optional{?contactPoint vcard:hasAddress ?hasAddress optional{?contactPoint foaf:homepage ?homepage}

OPTIONAL{?contactPoint vcard:hasEmail ?hasEmail} OPTIONAL{?contactPoint vcard:hasTelephone ?hasTelephone.?hasTelephone vcard:hasValue ?tel.}

}} } }

Part 4: Access and Usage

Accessing data with SPARQL

4 of 22

To retrieve metadata of a publication

4

Part 4: Access and Usage

Accessing data with SPARQL

5 of 22

To retrieve URI of “Values and identities of EU citizens” publication by ISBN property

5

Part 4: Access and Usage

Accessing data with SPARQL

prefix cdm: <http://publications.europa.eu/ontology/cdm#>

​

select ?work

where {

?expression cdm:expression_belongs_to_work ?work .

?manifestation cdm:manifestation_manifests_expression ?expression .

?manifestation cdm:manifestation_isbn ?isbn. filter (str(?isbn) = "978-92-76-43232-6")

}

6 of 22

To retrieve what “Values and identities of EU citizens” publication is about

6

prefix cdm: <http://publications.europa.eu/ontology/cdm#>

​

select ?work ?label

where {

values(?work){(<http://publications.europa.eu/resource/cellar/1da26cfe-475c-11ec-91ac-01aa75ed71a1>)}

?work cdm:work_is_about_concept_eurovoc ?eurovoc .

?eurovoc skos:prefLabel ?label .

filter (lang(?label)='en')

}

Part 4: Access and Usage

Accessing data with SPARQL

7 of 22

To retrieve expressions and manifestations of “Values and identities of EU citizens”

7

prefix cdm: <http://publications.europa.eu/ontology/cdm#>

​

select ?work ?expression ?expressionProperty ?expressionPropertyValue

?manifestation ?manifestationProperty ?manifestationPropertyValue

where

{

values(?work){(<http://publications.europa.eu/resource/cellar/1da26cfe-475c-11ec-91ac-01aa75ed71a1>)}

{

?expression cdm:expression_belongs_to_work ?work .

?manifestation cdm:manifestation_manifests_expression ?expression .

?manifestation ?manifestationProperty ?manifestationPropertyValue .

}

union

{

?expression cdm:expression_belongs_to_work ?work .

?expression ?expressionProperty ?expressionPropertyValue .

}

}

order by ?work desc(?expressionProperty)

Part 4: Access and Usage

Accessing data with SPARQL

8 of 22

To retrieve the official journals for a specific period

8

prefix cdm: <http://publications.europa.eu/ontology/cdm#>

prefix xsd: <http://www.w3.org/2001/XMLSchema#>

prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT ?uri ?ojclass ?ojnumber ?ojcollection ?ojyear ?workdatedoc

WHERE {

?uri cdm:official-journal_class ?ojclass .

?uri cdm:official-journal_number ?ojnumber .

?uri cdm:official-journal_part_of_collection_document ?ojcollection .

?uri cdm:official-journal_year "2022"^^xsd:gYear .

?uri cdm:official-journal_year ?ojyear .

?uri cdm:work_date_document ?workdatedoc .

?uri rdf:type cdm:official-journal .

FILTER( ?workdatedoc >= "2022-01-01"^^xsd:date

&& ?workdatedoc < "2022-04-01"^^xsd:date)}

Part 4: Access and Usage

Accessing data with SPARQL

9 of 22

To retrieve the most recent date of all OJ in a specific year and sort it by date

9

prefix cdm: <http://publications.europa.eu/ontology/cdm#>

prefix xsd: <http://www.w3.org/2001/XMLSchema#>

prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT ?workdatedoc

WHERE {

?uri rdf:type cdm:official-journal .

?uri cdm:work_date_document ?workdatedoc .

?uri cdm:official-journal_year "2022"^^xsd:gYear

}

ORDER BY DESC(?workdatedoc) LIMIT 1

Part 4: Access and Usage

Accessing data with SPARQL

10 of 22

To retrieve multilingual titles and subtitles of a publication

10

prefix cdm: <http://publications.europa.eu/ontology/cdm#>

​

select ?expressionId

substr(str(?expressionLanguageUri), 59) AS ?expressionLanguage

str(?subtitle) AS ?subtitle

lang(?title) AS ?language

str(?title) AS ?title

​

where {

?expressionId cdm:expression_belongs_to_work ?workId.

?expressionId cdm:expression_title ?title.

?expressionId cdm:expression_uses_language ?expressionLanguageUri.

OPTIONAL{

?expressionId cdm:expression_subtitle ?subtitle.

}

values(?workId) {(<http://publications.europa.eu/resource/cellar/1c4905ef-02c2-467a-ba3c-2a340d23bd15>)}

}

Part 4: Access and Usage

Accessing data with SPARQL

11 of 22

To retrieve all EU treaties

11

prefix cdm: <http://publications.europa.eu/ontology/cdm#>

select distinct ?work ?doc_id

where

{

?work a cdm:treaty;

cdm:work_id_document ?doc_id.

FILTER not exists{?work a cdm:fragment_resource_legal}.

}

Accessing data with SPARQL

Part 4: Access and Usage

12 of 22

To retrieve EU legislation in force about the EuroVoc concept ‘cambiamento climatico’

12

prefix cdm: <http://publications.europa.eu/ontology/cdm#>

​

select distinct ?work

where

{

?work cdm:resource_legal_in-force "true"^^<http://www.w3.org/2001/XMLSchema#boolean> ;

a cdm:legislation_secondary;

cdm:work_is_about_concept_eurovoc <http://eurovoc.europa.eu/5482> .

}

prefix cdm: <http://publications.europa.eu/ontology/cdm#>

prefix skos-core: <http://www.w3.org/2004/02/skos/core#>

​

select distinct ?work

where

{

?work cdm:resource_legal_in-force "true"^^<http://www.w3.org/2001/XMLSchema#boolean> ;

a cdm:legislation_secondary;

cdm:work_is_about_concept_eurovoc ?eurovoc .

{select ?eurovoc where

{?eurovoc skos-core:inScheme <http://eurovoc.europa.eu/100141>;

skos-core:prefLabel ?label . filter (str(?label)="cambiamento climatico") }}

}

or,

Accessing data with SPARQL

Part 4: Access and Usage

13 of 22

To retrieve all concepts of corporate-body list and to sort them by URI

13

prefix cdm: <http://publications.europa.eu/ontology/cdm#>

prefix skos: <http://www.w3.org/2004/02/skos/core#>

​

select distinct ?concept ?label

​

{?concept skos:inScheme ?scheme .

values(?scheme){(<http://publications.europa.eu/resource/authority/corporate-body>)}

?concept skos:prefLabel ?label .

FILTER (lang(?label ) = 'en')}

order by ?concept

Accessing data with SPARQL

Part 4: Access and Usage

14 of 22

To describe ‘European Space Agency‘ concept of corporate-body NAL

14

​

DESCRIBE

<http://publications.europa.eu/resource/authority/corporate-body/ESA>

FROM <http://publications.europa.eu/resource/authority/corporate-body>

​

Accessing data with SPARQL

Part 4: Access and Usage

15 of 22

REST API

15

HTTPS operations to exploit WEMI objects

    • Retrieve the XML notice of an object (work, expression, manifestation)
    • Retrieve all the identifiers of a specific document (sameAs)
    • Retrieve the RDF/XML metadata for an object
    • Retrieve content streams
    • etc.

HTTPS operations to exploit ontologies and vocabularies

    • Retrieve supported languages
    • Retrieve concept scheme(s)
    • Retrieve concept
    • Retrieve concept relatives
    • Retrieve top concepts, domains
    • etc.

Part 4: Access and Usage

16 of 22

REST API: Use cases

  • I want to retrieve the full XML tree notice of a work, given the work identifier (URI). E.g. OJ identifier.
  • I want a content stream (actual item), given the work identifier, expression language, and a content type (mime-type)
  • ...

16

Part 4: Access and Usage

REST API

Access by REST API

17 of 22

Retrieve the XML Tree notice

17

curl -H 'Accept:application/xml;notice=tree'

http://publications.europa.eu/resource/oj/JOL_2014_001_R_0001_01?language=eng

Part 4: Access and Usage

REST API

Access by REST API

18 of 22

Retrieve Content stream

  • A content stream of the manifestation (e.g., the xml format) belonging to the given work (e.g., a given OJ) and to the expression (e.g., the french version) in the given accept language (e.g., fra), and which contains at least 1 content stream of the given accept format.

18

GET http://publications.europa.eu/resource/{ps-name}/{psid}

​

HTTP headers must be set on the request:

  • Accept:{mime-type}, where {mime-type} is a valid (or a comma-separated list of) mime type that identify the format of the content stream to return
  • Accept-Language:{acc-lang}, where {acc-lang} is a 3-chars ISO_639-3 language code identifying the accept language to use: this will be used for retrieving the correct expression
  • Accept-Max-Cs-Size:{size}, where {size} is a positive integer which specifies the max. content stream size in bytes.

curl example on the next slide

Part 4: Access and Usage

REST API

Access by REST API

19 of 22

Retrieve Content stream: example

19

curl --location --request GET 'http://publications.europa.eu/resource/oj/JOL_2014_001_R_0001_0' \

--header 'Accept: application/xhtml+xml' \

--header 'Accept-Language: fra' 

Part 4: Access and Usage

REST API

Access by REST API

20 of 22

RSS and Atom feeds

  • Feeds about the ingestion of documents, the loading of NALs and the loading of ontologies in the form of an RSS or Atom feed.
  • By accessing these feeds, it is possible to get a complete history of the performed actions.

20

Part 4: Access and Usage

RSS Feeds

21 of 22

Ingestion feed

21

  • Provides an overview of all ingestion actions, filtered by the given parameters.

− startDate: Defines the date (inclusive) since which the ingestion notifications shall be retrieved.

- endDate: Defines the date (inclusive) until which the ingestion notifications shall be retrieved

− type: A string value, either CREATE, UPDATE or DELETE. It defines the type of ingestion to be retrieved

− wemiClasses: A comma-separated list of WEMI classes: work, expression, manifestation, item, dossier, event or agent

− page: The number of the page on the feed to display. This parameter may be used to page large results.

http://publications.europa.eu/webapi/notification/ingestion ?{parameters}

5.3. Notifications (Feeds)

Part 4: Access and Usage

RSS Feeds

22 of 22

22

curl -X GET http://publications.europa.eu/webapi/notification/ingestion?startDate=2022-01-01&endDate=2022-01-04&type=create&wemiClasses=work&page=1 -H "Accept: application/rss+xml"

5.3. Notifications (Feeds)

Part 4: Access and Usage

RSS Feeds