SPARQL Examples

From Semantic Lab
Revision as of 01:20, 25 February 2025 by Matt (talk | contribs)
Jump to navigation Jump to search

All -- records

All records associated with our various projects on Wikibase


 # All records associated with our various projects on Wikibase

SELECT DISTINCT ?item ?itemLabel ?type ?typeLabel ?project ?projectLabel WHERE {
    ?item wdt:P1 ?type.
    ?item wdt:P11 ?project.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  
}
ORDER BY ?projectLabel

All -- person records

 #All person records associated with our projects on Wikibase

SELECT ?person ?personLabel ?project ?projectLabel
WHERE 
{
  ?person  wdt:P1 wd:Q1.
  ?person wdt:P11 ?project.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

ORDER BY ?projectLabel

All -- city records

 #All city records associated with our projects on Wikibase

SELECT ?city ?cityLabel WHERE {
  ?city wdt:P1 wd:Q19058.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

All -- sponsored by

Show all the entities that have the property P155 ("sponsored by") claim with the value, what the item is and who they are sponsored by


 #Show all the entities that have the property P155 ("sponsored by") claim with the value, what the item is and who they are sponsored by
SELECT ?item ?itemLabel ?sponsored_by ?sponsored_byLabel ?instance_of ?instance_ofLabel ?part_of_project ?part_of_projectLabel WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?item wdt:P155 ?sponsored_by. }
  OPTIONAL { ?item wdt:P1 ?instance_of. }
  OPTIONAL { ?item wdt:P11 ?part_of_project. }
}


All -- locations of performances

 #What are all the locations(venues) that people or performances were performed at and if availble, what was their city and state?
SELECT ?item ?itemLabel ?performed_at ?performed_atLabel ?location ?locationLabel WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?item wdt:P68 ?performed_at.
  ?item p:P68 ?statement.
  OPTIONAL { ?statement pq:P125 ?location. }
}


All -- price of things

 #Return the entity (regardless of "instance of" value) where there is a  property P145 ("price")  statement and the value of the P149  ("price type") qualifier (regardless of value).
SELECT DISTINCT ?item ?itemLabel ?instance_of ?instance_ofLabel ?price ?priceLabel ?price_type ?price_typeLabel WHERE {
  ?item wdt:P1 ?instance_of.
  ?item wdt:P145 ?price.
  ?item p:P145 ?statement.
  OPTIONAL{ ?statement pq:P149 ?price_type.}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }  
}
ORDER BY ?price_typeLabel

All -- employers

Return the entity and entity label where P110 ("employer") claim is made and the value of that claim

 #return the entity and entity label where P110 ("employer") claim is made and the value of that claim
SELECT ?item ?itemLabel ?employer ?employerLabel ?part_of_project ?part_of_projectLabel WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?item wdt:P110 ?employer. }
  OPTIONAL { ?item wdt:P11 ?part_of_project. }
}

All -- employees

 #return the instance of organizations with claim of "employee" P179 and their values
SELECT DISTINCT ?item ?itemLabel ?employee ?employeeLabel WHERE {
  ?item wdt:P1 wd:Q19049;
    wdt:P179 ?employee.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}


All -- fuzzy string search

 #Fuzzy match on a particular word (ex is with "tennis") in a block text
# fuzzy search 
SELECT ?item ?label ?block_text WHERE
{
  ?item rdfs:label ?label.
  ?item wdt:P19 ?block_text
  FILTER (CONTAINS(LCASE(STR(?block_text)), "tennis"))
}



E.A.T. Knowledge Graph -- works and materials used

 #return the entities and their instance of where the entities are part of project EAT + LOD and  use the property  P185 ("uses") claim and the value of the claim 
SELECT Distinct ?item ?itemLabel ?instance_of ?instance_ofLabel ?uses ?usesLabel WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?item wdt:P11 wd:Q19104.
  ?item wdt:P1 ?instance_of.
  ?item wdt:P185 ?uses.
  ?item p:P185 ?statement.
}
ORDER BY ?itemLabel


E.A.T. Knowledge Graph -- materials used in works

 #return the entities and their instance of where the entities are part of project EAT + LOD and  use the property  P194 ("used in") claim and the value of the claim 
SELECT Distinct ?item ?itemLabel ?instance_of ?instance_ofLabel ?used_in ?used_inLabel WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?item wdt:P11 wd:Q19104.
  ?item wdt:P1 ?instance_of.
  ?item wdt:P194 ?used_in.
  ?item p:P194 ?statement.
}
ORDER BY ?itemLabel


E.A.T. Knowledge Graph -- connect blocks to parent documents

 #query demonstrates the ability to identify the blocks that connect to the parent document which ultimately connects to the source of the document, allowing for verification of the material.
SELECT DISTINCT ?item ?label ?block_text ?parent_document ?parent_documentLabel WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  {
    SELECT DISTINCT ?item ?label ?block_text ?parent_document ?parent_documentLabel WHERE {
      {
        ?item wdt:P11 wd:Q19104.
        ?item rdfs:label ?label;
        wdt:P24 ?parent_document;
        wdt:P19 ?block_text.
      }
      UNION
      {
        ?item wdt:P11 wd:Q20517.
        ?item rdfs:label ?label;
        wdt:P24 ?parent_document;
        wdt:P19 ?block_text.
       }
    }
  }
}
ORDER BY ASC (?parent_documentLabel)