Jump to content

EDM queries

From NeoWiki Demo

This wiki's SPARQL store holds two projections of its pages: the native one, in NeoWiki's own vocabulary, and the EDM one defined by Mapping:EDM, which targets the Europeana Data Model. A query can be written in EDM terms, in native terms, or in both at once.

Every example below uses the {{#sparql_raw}} parser function and returns raw SPARQL JSON. The Lua and REST surfaces answer the same queries — see SPARQL queries.

Query in EDM terms

The Person and Artist Schemas both map to edm:Agent, so a query in EDM terms spans them without knowing either Schema. The birth date sits in its own GRAPH block because it does not always live with the agent: where a birth is modelled as its own Subject, Mapping:EDM contributes rdaGr2:dateOfBirth from the Birth page's graph instead.

{{#sparql_raw:PREFIX edm: <http://www.europeana.eu/schemas/edm/> PREFIX rdaGr2: <http://rdvocab.info/ElementsGr2/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?agent ?dateOfBirth WHERE { GRAPH ?agentGraph { ?a a edm:Agent ; rdfs:label ?agent } GRAPH ?birthGraph { ?a rdaGr2:dateOfBirth ?dateOfBirth } } ORDER BY ?agent}}

Result:

{
    "head": {
        "vars": [
            "agent",
            "dateOfBirth"
        ]
    },
    "results": {
        "bindings": [
            {
                "agent": {
                    "type": "literal",
                    "value": "Carl Philipp Emanuel Bach"
                },
                "dateOfBirth": {
                    "datatype": "http://www.w3.org/2001/XMLSchema#date",
                    "type": "literal",
                    "value": "1714-03-08"
                }
            },
            {
                "agent": {
                    "type": "literal",
                    "value": "Claude Monet"
                },
                "dateOfBirth": {
                    "datatype": "http://www.w3.org/2001/XMLSchema#gYear",
                    "type": "literal",
                    "value": "1840"
                }
            },
            {
                "agent": {
                    "type": "literal",
                    "value": "Diego Vel\u00e1zquez"
                },
                "dateOfBirth": {
                    "datatype": "http://www.w3.org/2001/XMLSchema#gYear",
                    "type": "literal",
                    "value": "1599"
                }
            },
            {
                "agent": {
                    "type": "literal",
                    "value": "Gustav Klimt"
                },
                "dateOfBirth": {
                    "datatype": "http://www.w3.org/2001/XMLSchema#gYear",
                    "type": "literal",
                    "value": "1862"
                }
            },
            {
                "agent": {
                    "type": "literal",
                    "value": "Johann Ambrosius Bach"
                },
                "dateOfBirth": {
                    "datatype": "http://www.w3.org/2001/XMLSchema#date",
                    "type": "literal",
                    "value": "1645-02-22"
                }
            },
            {
                "agent": {
                    "type": "literal",
                    "value": "Johann Christian Bach"
                },
                "dateOfBirth": {
                    "datatype": "http://www.w3.org/2001/XMLSchema#date",
                    "type": "literal",
                    "value": "1735-09-05"
                }
            },
            {
                "agent": {
                    "type": "literal",
                    "value": "Johann Sebastian Bach"
                },
                "dateOfBirth": {
                    "datatype": "http://www.w3.org/2001/XMLSchema#date",
                    "type": "literal",
                    "value": "1685-03-21"
                }
            },
            {
                "agent": {
                    "type": "literal",
                    "value": "Johannes Vermeer"
                },
                "dateOfBirth": {
                    "datatype": "http://www.w3.org/2001/XMLSchema#gYear",
                    "type": "literal",
                    "value": "1632"
                }
            },
            {
                "agent": {
                    "type": "literal",
                    "value": "Pablo Picasso"
                },
                "dateOfBirth": {
                    "datatype": "http://www.w3.org/2001/XMLSchema#date",
                    "type": "literal",
                    "value": "1881-10-25"
                }
            },
            {
                "agent": {
                    "type": "literal",
                    "value": "Vincent van Gogh"
                },
                "dateOfBirth": {
                    "datatype": "http://www.w3.org/2001/XMLSchema#gYear",
                    "type": "literal",
                    "value": "1853"
                }
            },
            {
                "agent": {
                    "type": "literal",
                    "value": "Wilhelm Friedemann Bach"
                },
                "dateOfBirth": {
                    "datatype": "http://www.w3.org/2001/XMLSchema#date",
                    "type": "literal",
                    "value": "1710-11-22"
                }
            }
        ]
    },
    "meta": {
        "query-time-ms": 4,
        "result-size-total": 11
    }
}

A relation projects as a direct triple between two entity IRIs, so a query follows it the way it would in any EDM dataset. The artwork and its creator live on separate wiki pages, hence in separate named graphs:

{{#sparql_raw:PREFIX edm: <http://www.europeana.eu/schemas/edm/> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX dcterms: <http://purl.org/dc/terms/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?work ?created ?creator WHERE { GRAPH ?workGraph { ?w a edm:ProvidedCHO ; rdfs:label ?work ; dcterms:created ?created ; dc:creator ?c } GRAPH ?creatorGraph { ?c a edm:Agent ; rdfs:label ?creator } } ORDER BY ?created}}

Result:

{
    "head": {
        "vars": [
            "work",
            "created",
            "creator"
        ]
    },
    "results": {
        "bindings": [
            {
                "work": {
                    "type": "literal",
                    "value": "Las Meninas"
                },
                "created": {
                    "datatype": "http://www.w3.org/2001/XMLSchema#gYear",
                    "type": "literal",
                    "value": "1656"
                },
                "creator": {
                    "type": "literal",
                    "value": "Diego Vel\u00e1zquez"
                }
            },
            {
                "work": {
                    "type": "literal",
                    "value": "The Milkmaid"
                },
                "created": {
                    "datatype": "http://www.w3.org/2001/XMLSchema#gYear",
                    "type": "literal",
                    "value": "1658"
                },
                "creator": {
                    "type": "literal",
                    "value": "Johannes Vermeer"
                }
            },
            {
                "work": {
                    "type": "literal",
                    "value": "The Art of Painting"
                },
                "created": {
                    "datatype": "http://www.w3.org/2001/XMLSchema#gYear",
                    "type": "literal",
                    "value": "1666"
                },
                "creator": {
                    "type": "literal",
                    "value": "Johannes Vermeer"
                }
            },
            {
                "work": {
                    "type": "literal",
                    "value": "Starry Night Over the Rh\u00f4ne"
                },
                "created": {
                    "datatype": "http://www.w3.org/2001/XMLSchema#gYear",
                    "type": "literal",
                    "value": "1888"
                },
                "creator": {
                    "type": "literal",
                    "value": "Vincent van Gogh"
                }
            },
            {
                "work": {
                    "type": "literal",
                    "value": "Water Lilies"
                },
                "created": {
                    "datatype": "http://www.w3.org/2001/XMLSchema#gYear",
                    "type": "literal",
                    "value": "1906"
                },
                "creator": {
                    "type": "literal",
                    "value": "Claude Monet"
                }
            },
            {
                "work": {
                    "type": "literal",
                    "value": "The Kiss"
                },
                "created": {
                    "datatype": "http://www.w3.org/2001/XMLSchema#gYear",
                    "type": "literal",
                    "value": "1908"
                },
                "creator": {
                    "type": "literal",
                    "value": "Gustav Klimt"
                }
            }
        ]
    },
    "meta": {
        "query-time-ms": 11,
        "result-size-total": 6
    }
}

Query across both projections

Mapping:EDM maps no predicate for the Person Schema's Source property, so it is absent from the EDM projection — the native projection still has it as neo-prop:Source.

Both projections mint the same entity IRIs, so one query can take the birth date from EDM and the source from the native projection:

{{#sparql_raw:PREFIX edm: <http://www.europeana.eu/schemas/edm/> PREFIX rdaGr2: <http://rdvocab.info/ElementsGr2/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX neo-prop: <{{SERVER}}/prop/> SELECT ?agent ?dateOfBirth ?source ?edmGraph ?nativeGraph WHERE { GRAPH ?edmGraph { ?a a edm:Agent ; rdaGr2:dateOfBirth ?dateOfBirth } GRAPH ?nativeGraph { ?a rdfs:label ?agent ; neo-prop:Source ?source } } ORDER BY ?agent}}

Result:

{
    "head": {
        "vars": [
            "agent",
            "dateOfBirth",
            "source",
            "edmGraph",
            "nativeGraph"
        ]
    },
    "results": {
        "bindings": [
            {
                "agent": {
                    "type": "literal",
                    "value": "Pablo Picasso"
                },
                "dateOfBirth": {
                    "datatype": "http://www.w3.org/2001/XMLSchema#date",
                    "type": "literal",
                    "value": "1881-10-25"
                },
                "source": {
                    "type": "literal",
                    "value": "A Life of Picasso I: The Prodigy: 1881-1906 by John Richardson (ISBN 978-0375711497)"
                },
                "edmGraph": {
                    "type": "uri",
                    "value": "https://neowiki.dev/graph/EDM/page/181"
                },
                "nativeGraph": {
                    "type": "uri",
                    "value": "https://neowiki.dev/graph/native/page/181"
                }
            }
        ]
    },
    "meta": {
        "query-time-ms": 4,
        "result-size-total": 1
    }
}

Set this up

Each store entry names one projection, and several entries may point at one endpoint — see Several projections in one store. The NeoWiki development stack points a native and an EDM entry at one QLever, which is why these queries reach both.

Learn more