POLIFONIA - Useful queries

A selection of example SPARQL queries to get you started exploring the Musical Meetups Knowledge Graph.

The Musical Meetups Knoweldge Graph (MMKG) is made available for querying via an open SPARQL endpoint at the following address:

https://polifonia.kmi.open.ac.uk/meetups/sparql

HTTP GET/POST queries can be made to this URL, passing your SPARQL query in a URL or form parameter name 'query'.


Retrieving the list of biographies
PREFIX mtp: 
PREFIX rdf:    
PREFIX rdfs:   

SELECT DISTINCT ?subjectID ?subjectLabel
WHERE {
    ?meetupID  mtp:hasSubject ?subjectID .
    ?subjectID rdfs:label ?subjectLabel
}
LIMIT 10
Retrieving all meetups for the biography of Edward Elgar
PREFIX mtp: <http://w3id.org/polifonia/ontology/meetups-ontology#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX geo: <https://www.w3.org/2003/01/geo/wgs84_pos>
PREFIX time: <http://www.w3.org/2006/time#>

SELECT ?meetup ?evidence_text ?purpose
(GROUP_CONCAT( DISTINCT ?participant; separator=", " ) as ?participants_URI )
(GROUP_CONCAT( DISTINCT ?participant_label; separator=", " ) as ?participants_label )
(GROUP_CONCAT( DISTINCT ?location_uri; separator=", " ) as ?locations_URI )
(GROUP_CONCAT( DISTINCT ?location_label; separator=", " ) as ?locations_label )
(GROUP_CONCAT( DISTINCT ?lat ; separator=", " ) as ?lats )
(GROUP_CONCAT( DISTINCT ?long ; separator=", " ) as ?longs )
(GROUP_CONCAT( DISTINCT ?time_expression_URI ; separator=", " ) as ?time_expression_URIs )
(GROUP_CONCAT( DISTINCT ?beginDate ; separator=", " ) as ?beginDates )
(GROUP_CONCAT( DISTINCT ?endDate ; separator=", " ) as ?endDates )
(GROUP_CONCAT( DISTINCT ?time_evidence_text ; separator=", " ) as ?time_evidence_texts )
WHERE
{
    VALUES ?subject { <http://dbpedia.org/resource/Edward_Elgar> }
    ?meetup
        mtp:hasSubject ?subject ;
        mtp:hasEvidenceText ?evidence_text ;
        mtp:hasType "HM" .
  ?meetup mtp:hasParticipant ?aParticipantIRI .
  ?aParticipantIRI rdf:type mtp:Participant ;
                   mtp:hasEntity ?participant .
  OPTIONAL { ?participant rdfs:label ?participant_label  } .
  ?meetup mtp:hasPurpose ?aPurposeIRI .
  ?aPurposeIRI rdf:type mtp:Purpose ;
               mtp:hasAPurposeFirst ?purpose1 .
  ?purpose1 rdfs:label ?purpose .
  ?meetup mtp:hasPlace ?aPlaceIRI .
  ?aPlaceIRI mtp:hasEntity ?location_uri .
  OPTIONAL { ?location_uri rdfs:label ?location_label ;
  		geo:lat ?lat ;
        geo:long ?long . } .
  ?meetup mtp:happensAt ?time_expression_URI .
    FILTER  (!regex (str(?participant), str(?subject) ) ) .
    ?participant rdfs:label ?participant_label .
    ?purpose_uri rdfs:label ?purpose .
    ?time_expression_URI mtp:hasEvidenceText ?hasEvidenceTextTimeExpression ;
    rdf:type ?typeTimeExpression .
    FILTER ( ?typeTimeExpression !=  mtp:TimeExpression ) .
    OPTIONAL {
        ?time_expression_URI time:hasBeginning ?beginDate;
            time:hasEnd ?endDate ;
            mtp:hasEvidenceText ?time_evidence_text .
    } .
}
GROUP BY ?meetup ?evidence_text ?purpose 
Search for meetups that contain participant: Django
PREFIX geo: <hhttps://www.w3.org/2003/01/geo/wgs84_pos>
PREFIX bds: <hhttp://www.bigdata.com/rdf/search#>
PREFIX rdf: <hhttp://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <hhttp://www.w3.org/2000/01/rdf-schema#>
PREFIX mtp: <hhttp://w3id.org/polifonia/ontology/meetups-ontology#>
PREFIX time: <hhttp://www.w3.org/2006/time#>

SELECT ?subject ?subject_label ?meetup ?evidence_text ?purpose_Label
(GROUP_CONCAT( DISTINCT ?place_uri; separator=", " ) as ?locations_URI )
(GROUP_CONCAT( DISTINCT ?location_label; separator=", " ) as ?locations_label )
(GROUP_CONCAT( DISTINCT ?lat ; separator=", " ) as ?lats )
(GROUP_CONCAT( DISTINCT ?long ; separator=", " ) as ?longs )
(GROUP_CONCAT( DISTINCT ?participant_uri; separator=", " ) as ?participants_URI )
(GROUP_CONCAT( DISTINCT ?participant_label; separator=", " ) as ?participants_label )
(GROUP_CONCAT( DISTINCT ?time_expression_URI ; separator=", " ) as ?time_expression_URIs )
(GROUP_CONCAT( DISTINCT ?beginDate ; separator=", " ) as ?beginDates )
(GROUP_CONCAT( DISTINCT ?endDate ; separator=", " ) as ?endDates )
(GROUP_CONCAT( DISTINCT ?time_evidence_text ; separator=", " ) as ?time_evidence_texts )
WHERE{
  {
    # Search participant
    ?meetup mtp:hasParticipant/mtp:hasEntity/rdfs:label ?lit .
    ?lit bds:search "Django" .
    ?lit bds:matchAllTerms "true" .
    }
  # Complementary information
  {
    ?meetup mtp:hasType "HM" ;
            mtp:hasEvidenceText ?evidence_text ;
            mtp:hasSubject ?subject ;
            mtp:hasParticipant/mtp:hasEntity ?participant_uri ;
            mtp:hasPlace/mtp:hasEntity ?place_uri ;
            mtp:hasPurpose/mtp:hasAPurposeFirst ?purpose_uri ;
            mtp:happensAt ?time_expression_URI .
    OPTIONAL { ?subject rdfs:label ?subject_label . } .

    # location
    OPTIONAL { ?place_uri rdfs:label ?place_tempLabel . }
    BIND ( COALESCE(?place_tempLabel, REPLACE(STR(?place_uri),"http://dbpedia.org/resource/","" )) AS ?location_label)
    OPTIONAL { ?place_uri geo:lat ?lat ; geo:long ?long . }

    # participant
    ?participant_uri rdf:type mtp:Participant .
    OPTIONAL { ?participant_uri rdfs:label ?part_tempLabel . }
    FILTER  (!regex (str(?part_tempLabel), str(?subject) ) || isBlank(?participant_uri) ) .
    OPTIONAL { ?participant_uri mtp:hasTextEvidence ?mentionPerson . } .
    BIND ( COALESCE(?part_tempLabel, ?mentionPerson) AS ?participant_label) .

    # purpose
    OPTIONAL { ?purpose_uri rdfs:label ?purpose_tempLabel . }
    BIND ( COALESCE(?purpose_tempLabel, "") AS ?purpose_Label )

    # time
  	?time_expression_URI rdf:type ?typeTimeExpression .
    FILTER ( ?typeTimeExpression !=  mtp:TimeExpression ) .
    OPTIONAL {
        ?time_expression_URI time:hasBeginning ?beginDate;
            time:hasEnd ?endDate ;
            mtp:hasEvidenceText ?time_evidence_text .
    } .

  }
}
GROUP BY ?subject ?subject_label ?meetup ?evidence_text ?purpose_Label
Search for meetups that contain place name: Vienna
PREFIX geo: <https://www.w3.org/2003/01/geo/wgs84_pos>
PREFIX bds: <http://www.bigdata.com/rdf/search#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX mtp: <http://w3id.org/polifonia/ontology/meetups-ontology#>
PREFIX time: <http://www.w3.org/2006/time#>

SELECT ?subject ?subject_label ?meetup ?evidence_text ?purpose_Label
(GROUP_CONCAT( DISTINCT ?place_uri; separator=", " ) as ?locations_URI )
(GROUP_CONCAT( DISTINCT ?location_label; separator=", " ) as ?locations_label )
(GROUP_CONCAT( DISTINCT ?lat ; separator=", " ) as ?lats )
(GROUP_CONCAT( DISTINCT ?long ; separator=", " ) as ?longs )
(GROUP_CONCAT( DISTINCT ?participant_uri; separator=", " ) as ?participants_URI )
(GROUP_CONCAT( DISTINCT ?participant_label; separator=", " ) as ?participants_label )
(GROUP_CONCAT( DISTINCT ?time_expression_URI ; separator=", " ) as ?time_expression_URIs )
(GROUP_CONCAT( DISTINCT ?beginDate ; separator=", " ) as ?beginDates )
(GROUP_CONCAT( DISTINCT ?endDate ; separator=", " ) as ?endDates )
(GROUP_CONCAT( DISTINCT ?time_evidence_text ; separator=", " ) as ?time_evidence_texts )
WHERE{
  {
    # Search place
    ?meetup mtp:hasPlace/mtp:hasEntity/rdfs:label ?lit .
    ?lit bds:search "Vienna" .
    ?lit bds:matchAllTerms "true" .
    }
  # Complementary information
  {
    ?meetup mtp:hasType "HM" ;
            mtp:hasEvidenceText ?evidence_text ;
            mtp:hasSubject ?subject ;
            mtp:hasParticipant/mtp:hasEntity ?participant_uri ;
            mtp:hasPlace/mtp:hasEntity ?place_uri ;
            mtp:hasPurpose/mtp:hasAPurposeFirst ?purpose_uri ;
            mtp:happensAt ?time_expression_URI .
    OPTIONAL { ?subject rdfs:label ?subject_label . } .

    # location
    OPTIONAL { ?place_uri rdfs:label ?place_tempLabel . }
    BIND ( COALESCE(?place_tempLabel, REPLACE(STR(?place_uri),"http://dbpedia.org/resource/","" )) AS ?location_label)
    OPTIONAL { ?place_uri geo:lat ?lat ; geo:long ?long . }

    # participant
    ?participant_uri rdf:type mtp:Participant .
    OPTIONAL { ?participant_uri rdfs:label ?part_tempLabel . }
    FILTER  (!regex (str(?part_tempLabel), str(?subject) ) || isBlank(?participant_uri) ) .
    OPTIONAL { ?participant_uri mtp:hasTextEvidence ?mentionPerson . } .
    BIND ( COALESCE(?part_tempLabel, ?mentionPerson) AS ?participant_label) .

    # purpose
    OPTIONAL { ?purpose_uri rdfs:label ?purpose_tempLabel . }
    BIND ( COALESCE(?purpose_tempLabel, "") AS ?purpose_Label )

    # time
  	?time_expression_URI rdf:type ?typeTimeExpression .
    FILTER ( ?typeTimeExpression !=  mtp:TimeExpression ) .
    OPTIONAL {
        ?time_expression_URI time:hasBeginning ?beginDate;
            time:hasEnd ?endDate ;
            mtp:hasEvidenceText ?time_evidence_text .
    } .
  }
}
GROUP BY ?subject ?subject_label ?meetup ?evidence_text ?purpose_Label
Search for meetups that occur between 1880 and 1885
tbc
Search for meetups occurring within a specific area defined by latitude/longitude
tbc
A combined search for subject, area and timespan
tbc