Skip to content

Instantly share code, notes, and snippets.

@mepcotterell
Created February 15, 2012 05:45
Show Gist options
  • Save mepcotterell/1833564 to your computer and use it in GitHub Desktop.
Save mepcotterell/1833564 to your computer and use it in GitHub Desktop.
Example SPARQL Queries
:Albert_Einstein :hasAcademicAdvisor :Alfred_Kleiner .
SELECT DISTINCT * WHERE { :Albert_Einstein ?p :Alfred_Kleiner . }
:Albert_Einstein :isMarriedTo :Mileva_Marić . :Mileva_Marić :isMarriedTo :Albert_Einstein . :Albert_Einstein :hasAcademicAdvisor :Alfred_Kleiner .
:Albert_Einstein :isMarriedTo :Elsa_Einstein . :Elsa_Einstein :isMarriedTo :Albert_Einstein . :Albert_Einstein :hasAcademicAdvisor :Alfred_Kleiner .
SELECT DISTINCT * WHERE { :Albert_Einstein ?p1 ?o2 . ?o2 ?p2 ?o3 . ?o3 ?p3 :Alfred_Kleiner . }
{p=http://yago-knowledge.org/resource/hasAcademicAdvisor}
// This shows the semantic relationship between Albert Einstein
// and Alfred Kleiner
SELECT * WHERE { :Albert_Einstein ?p :Alfred_Kleiner }
{o=http://yago-knowledge.org/resource/wordnet_person_100007846, p=http://www.w3.org/1999/02/22-rdf-syntax-ns#type}
{o=http://yago-knowledge.org/resource/wikicategory_Cosmologists, p=http://www.w3.org/1999/02/22-rdf-syntax-ns#type}
{o=http://yago-knowledge.org/resource/wikicategory_Naturalized_citizens_of_the_United_States, p=http://www.w3.org/1999/02/22-rdf-syntax-ns#type}
{o=http://yago-knowledge.org/resource/wikicategory_Religious_skeptics, p=http://www.w3.org/1999/02/22-rdf-syntax-ns#type}
{o=http://yago-knowledge.org/resource/wikicategory_American_philosophers, p=http://www.w3.org/1999/02/22-rdf-syntax-ns#type}
{o=http://yago-knowledge.org/resource/wikicategory_German_philosophers, p=http://www.w3.org/1999/02/22-rdf-syntax-ns#type}
{o=http://yago-knowledge.org/resource/wikicategory_German-language_philosophers, p=http://www.w3.org/1999/02/22-rdf-syntax-ns#type}
{o=http://yago-knowledge.org/resource/wikicategory_19th-century_German_people, p=http://www.w3.org/1999/02/22-rdf-syntax-ns#type}
{o=http://yago-knowledge.org/resource/wikicategory_People_from_Ulm, p=http://www.w3.org/1999/02/22-rdf-syntax-ns#type}
{o=http://yago-knowledge.org/resource/wikicategory_American_humanitarians, p=http://www.w3.org/1999/02/22-rdf-syntax-ns#type}
// This shows all the associations between Albert Einstein
// and other objects in YAGO2.
SELECT * WHERE { :Albert_Einstein ?p ?o } LIMIT 10
{o2=http://yago-knowledge.org/resource/Rudolf_Carnap, o3=http://yago-knowledge.org/resource/Willard_Van_Orman_Quine, o4=http://yago-knowledge.org/resource/Daniel_Dennett}
{o2=http://yago-knowledge.org/resource/Rudolf_Carnap, o3=http://yago-knowledge.org/resource/Willard_Van_Orman_Quine, o4=http://yago-knowledge.org/resource/Noam_Chomsky}
{o2=http://yago-knowledge.org/resource/Rudolf_Carnap, o3=http://yago-knowledge.org/resource/Willard_Van_Orman_Quine, o4=http://yago-knowledge.org/resource/Saul_Kripke}
{o2=http://yago-knowledge.org/resource/Rudolf_Carnap, o3=http://yago-knowledge.org/resource/Willard_Van_Orman_Quine, o4=http://yago-knowledge.org/resource/Richard_Rorty}
{o2=http://yago-knowledge.org/resource/Rudolf_Carnap, o3=http://yago-knowledge.org/resource/Willard_Van_Orman_Quine, o4=http://yago-knowledge.org/resource/Susan_Haack}
{o2=http://yago-knowledge.org/resource/Rudolf_Carnap, o3=http://yago-knowledge.org/resource/Willard_Van_Orman_Quine, o4=http://yago-knowledge.org/resource/Patricia_Churchland}
{o2=http://yago-knowledge.org/resource/Rudolf_Carnap, o3=http://yago-knowledge.org/resource/Willard_Van_Orman_Quine, o4=http://yago-knowledge.org/resource/Scott_Soames}
{o2=http://yago-knowledge.org/resource/Rudolf_Carnap, o3=http://yago-knowledge.org/resource/Willard_Van_Orman_Quine, o4=http://yago-knowledge.org/resource/Nelson_Goodman}
{o2=http://yago-knowledge.org/resource/Rudolf_Carnap, o3=http://yago-knowledge.org/resource/Willard_Van_Orman_Quine, o4=http://yago-knowledge.org/resource/Jack_Abbott}
{o2=http://yago-knowledge.org/resource/Rudolf_Carnap, o3=http://yago-knowledge.org/resource/Willard_Van_Orman_Quine, o4=http://yago-knowledge.org/resource/Michael_Devitt}
// This creates an influence graph(?) representing the influence
// of Albert Einstein up to 4 hops.
PREFIX yago: <http://yago-knowledge.org/resource/>
SELECT DISTINCT * WHERE {:Albert_Einstein yago:influences ?o2 . OPTIONAL{ ?o2 yago:influences ?o3 . ?o3 yago:influences ?o4 .} } LIMIT 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment