├── FamilyTree └── QueenElizabethII │ ├── ElizabethII.gif │ ├── ElizabethII.kdb │ ├── QueenElizabethII.sparql │ └── README.md ├── LICENSE ├── People ├── Influencer │ ├── AlbertEinstein.gif │ ├── AlbertEinstein.kdb │ ├── AlbertEinstein.sparql │ ├── Jesus.sparql │ └── README.md ├── NobelPrice │ ├── NobelPricePhysics.gif │ ├── NobelPricePhysics.kdb │ ├── NobelPricePhysics.sparql │ └── README.md ├── Philosophers │ └── philosophers.sparql └── Plaques │ ├── AberdeenPlaques.kdb │ ├── AberdeenPlaques.sparql │ ├── Aberdeen_plaques.gif │ └── README.md ├── Queries ├── MultiLevelQuery.sparql ├── MultiLevelQueryForPresentation.sparql └── MultiLevelQueryForPresentationCompact.sparql ├── README.md └── images ├── Example.gif └── content.txt /FamilyTree/QueenElizabethII/ElizabethII.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inforapid/SPARQL/2ec8bc0b69446ee0c8b82c2aeb3c82f40df25bf3/FamilyTree/QueenElizabethII/ElizabethII.gif -------------------------------------------------------------------------------- /FamilyTree/QueenElizabethII/ElizabethII.kdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inforapid/SPARQL/2ec8bc0b69446ee0c8b82c2aeb3c82f40df25bf3/FamilyTree/QueenElizabethII/ElizabethII.kdb -------------------------------------------------------------------------------- /FamilyTree/QueenElizabethII/QueenElizabethII.sparql: -------------------------------------------------------------------------------- 1 | # The following prefixes must be used for SPARQL variables in the SELECT statement: 2 | SELECT ?i_item ?i_itemLabel ?i_itemDescription ?ii_pic ?iu_enwiki ?rn_property1Label (?rn_property1Label as ?rc_property1Label) ?i_link1 ?rn_property2Label (?rn_property2Label as ?rc_property2Label) ?i_link2 ?rn_t_property3Label (?rn_t_property3Label as ?rc_property3Label) ?ic_DateOfBirth ?rn_t_property4Label (?rn_t_property4Label as ?rc_property4Label) ?ic_PlaceOfBirth ?ic_PlaceOfBirthLabel ?ic_PlaceOfBirthDescription ?rn_t_property5Label (?rn_t_property5Label as ?rc_property5Label) ?ic_DateOfDeath ?rn_t_property6Label (?rn_t_property6Label as ?rc_property6Label) ?ic_PlaceOfDeath ?ic_PlaceOfDeathLabel ?ic_PlaceOfDeathDescription ?rn_property7Label (?rn_property7Label as ?rc_property7Label) ?i_Spouse ?i_SpouseLabel ?i_SpouseDescription WHERE { 3 | wd:Q9682 wdt:P40* ?i_item. 4 | OPTIONAL { ?i_item wdt:P18 ?ii_pic. } 5 | OPTIONAL { ?iu_enwiki schema:about ?i_item; schema:isPartOf } 6 | OPTIONAL { ?i_item wdt:P22 ?i_link1. } 7 | OPTIONAL { ?rn_property1 wikibase:directClaim wdt:P22. } 8 | OPTIONAL { ?i_item wdt:P25 ?i_link2. } 9 | OPTIONAL { ?rn_property2 wikibase:directClaim wdt:P25. } 10 | OPTIONAL { ?i_item wdt:P569 ?ic_DateOfBirth. } 11 | OPTIONAL { ?rn_t_property3 wikibase:directClaim wdt:P569. } 12 | OPTIONAL { ?i_item wdt:P19 ?ic_PlaceOfBirth. } 13 | OPTIONAL { ?rn_t_property4 wikibase:directClaim wdt:P19. } 14 | OPTIONAL { ?i_item wdt:P570 ?ic_DateOfDeath. } 15 | OPTIONAL { ?rn_t_property5 wikibase:directClaim wdt:P570. } 16 | OPTIONAL { ?i_item wdt:P20 ?ic_PlaceOfDeath. } 17 | OPTIONAL { ?rn_t_property6 wikibase:directClaim wdt:P20. } 18 | OPTIONAL { ?i_item wdt:P26 ?i_Spouse. } 19 | OPTIONAL { ?rn_property7 wikibase:directClaim wdt:P26. } 20 | SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } 21 | } 22 | -------------------------------------------------------------------------------- /FamilyTree/QueenElizabethII/README.md: -------------------------------------------------------------------------------- 1 | # Family tree of Queen Elizabeth II 2 | 3 | Show the [SQARQL query](./QueenElizabethII.sparql) 4 | 5 | [LIVE DEMO: Family tree of Queen Elizabeth II](https://inforapid.org/webapp/webapp.php?shareddb=L3jPjGWHnKeV76En5YSTPJBgrCbI9rqe4bpExVh0ReREv3a8Fe4ztj7RcipzjRXLLsFC0Qo6SAKkr0XFGwrSC4x3pOMcp28z) 6 | 7 | Download the [KnowledgeBase Builder database](./ElizabethII.kdb) 8 | 9 | ![Family tree of Queen Elizabeth II](ElizabethII.gif?raw=true "Family tree of Queen Elizabeth II") 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 inforapid 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /People/Influencer/AlbertEinstein.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inforapid/SPARQL/2ec8bc0b69446ee0c8b82c2aeb3c82f40df25bf3/People/Influencer/AlbertEinstein.gif -------------------------------------------------------------------------------- /People/Influencer/AlbertEinstein.kdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inforapid/SPARQL/2ec8bc0b69446ee0c8b82c2aeb3c82f40df25bf3/People/Influencer/AlbertEinstein.kdb -------------------------------------------------------------------------------- /People/Influencer/AlbertEinstein.sparql: -------------------------------------------------------------------------------- 1 | SELECT ?i_influencer ?i_influencerLabel ?i_influencerDescription ?iu_influencer ?ii_influencer ?rn_influences ?i_influenced ?rn_t_DateOfBirthLabel ?ic_DateOfBirth ?rn_t_DateOfDeathLabel ?ic_DateOfDeath ?rn_notableWorkLabel ?i_notableWork ?i_notableWorkLabel ?i_notableWorkDescription ?iu_notableWork ?ii_notableWork WHERE { 2 | 3 | { 4 | SELECT ?i_influencer WHERE { 5 | { ?i_influencer wdt:P737 wd:Q937. } 6 | UNION 7 | { wd:Q937 wdt:P737 ?i_influencer. } 8 | UNION 9 | { BIND (wd:Q937 AS ?i_influencer) } 10 | } 11 | } 12 | 13 | OPTIONAL { ?i_influenced wdt:P737 ?i_influencer. } 14 | 15 | BIND (CONCAT (STR (?i_influencer), "§if") AS ?iu_influencer). 16 | 17 | OPTIONAL { ?i_influencer wdt:P18 ?ii_influencer. } 18 | 19 | BIND("influences" AS ?rn_influences). 20 | 21 | OPTIONAL { ?i_influencer wdt:P569 ?ic_DateOfBirth. 22 | ?rn_t_DateOfBirth wikibase:directClaim wdt:P569. 23 | } 24 | 25 | OPTIONAL { ?i_influencer wdt:P570 ?ic_DateOfDeath. 26 | ?rn_t_DateOfDeath wikibase:directClaim wdt:P570. 27 | } 28 | 29 | OPTIONAL { ?i_influencer wdt:P800 ?i_notableWork. 30 | BIND (CONCAT (STR (?i_notableWork), "§if") AS ?iu_notableWork). 31 | ?rn_notableWork wikibase:directClaim wdt:P800. 32 | OPTIONAL { ?i_notableWork wdt:P18 ?ii_notableWork. } 33 | } 34 | 35 | SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,de,fr". } 36 | } 37 | -------------------------------------------------------------------------------- /People/Influencer/Jesus.sparql: -------------------------------------------------------------------------------- 1 | SELECT ?i_influencer ?i_influencerLabel ?i_influencerDescription ?iu_influencer ?ii_influencer ?rn_influences ?i_influenced ?rn_t_DateOfBirthLabel ?ic_DateOfBirth ?rn_t_DateOfDeathLabel ?ic_DateOfDeath ?rn_t_CauseOfDeathLabel ?ic_CauseOfDeathLabel ?rn_presentInWorkLabel ?i_presentInWork ?i_presentInWorkLabel ?i_presentInWorkDescription ?iu_presentInWork ?ii_presentInWork ?rn_significantEventLabel ?i_significantEvent ?i_significantEventLabel ?i_significantEventDescription ?iu_significantEvent ?ii_significantEvent WHERE { 2 | 3 | { 4 | SELECT ?i_influencer WHERE { 5 | { ?i_influencer (wdt:P737|wdt:P802) wd:Q302. } 6 | UNION 7 | { wd:Q302 (wdt:P737|wdt:P802) ?i_influencer. } 8 | UNION 9 | { BIND (wd:Q302 AS ?i_influencer) } 10 | } 11 | } 12 | 13 | OPTIONAL { ?i_influenced (wdt:P737|wdt:P802) ?i_influencer. } 14 | 15 | BIND (CONCAT (STR (?i_influencer), "§if") AS ?iu_influencer). 16 | 17 | OPTIONAL { ?i_influencer wdt:P18 ?ii_influencer. } 18 | 19 | BIND("student" AS ?rn_influences). 20 | 21 | OPTIONAL { 22 | ?i_influencer wdt:P569 ?ic_DateOfBirth. 23 | ?rn_t_DateOfBirth wikibase:directClaim wdt:P569. 24 | } 25 | 26 | FILTER NOT EXISTS { 27 | ?i_influencer wdt:P569 ?DateOfBirth. 28 | FILTER (?DateOfBirth < ?ic_DateOfBirth). 29 | } 30 | 31 | OPTIONAL { 32 | ?i_influencer wdt:P570 ?ic_DateOfDeath. 33 | ?rn_t_DateOfDeath wikibase:directClaim wdt:P570. 34 | } 35 | 36 | FILTER NOT EXISTS { 37 | ?i_influencer wdt:P570 ?DateOfDeath. 38 | FILTER (?DateOfDeath < ?ic_DateOfDeath). 39 | } 40 | OPTIONAL { 41 | ?i_influencer wdt:P509 ?ic_CauseOfDeath. 42 | ?rn_t_CauseOfDeath wikibase:directClaim wdt:P509. 43 | } 44 | 45 | OPTIONAL { 46 | ?i_influencer wdt:P1441 ?i_presentInWork. 47 | BIND (CONCAT (STR (?i_presentInWork), "§if") AS ?iu_presentInWork). 48 | ?rn_presentInWork wikibase:directClaim wdt:P1441. 49 | OPTIONAL { ?i_presentInWork wdt:P18 ?ii_presentInWork. } 50 | } 51 | 52 | OPTIONAL { 53 | ?i_influencer wdt:P793 ?i_significantEvent. 54 | BIND (CONCAT (STR (?i_significantEvent), "§if") AS ?iu_significantEvent). 55 | ?rn_significantEvent wikibase:directClaim wdt:P793. 56 | OPTIONAL { ?i_significantEvent wdt:P18 ?ii_significantEvent. } 57 | } 58 | 59 | SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,de,fr". } 60 | } 61 | -------------------------------------------------------------------------------- /People/Influencer/README.md: -------------------------------------------------------------------------------- 1 | # Mind Map of People who inspired Albert Einstein and who were inspired by Albert Einstein 2 | 3 | Show the [SQARQL query](./AlbertEinstein.sparql) 4 | 5 | [LIVE DEMO: People who inspired Albert Einstein and who were inspired by Albert Einstein](https://inforapid.org/webapp/webapp.php?shareddb=0R49ois1SmEu7UmaW1pKs6uOZO16nJd0ba0UfxqCNGkn61i8RVj5t2sPljwruS3T4Qa2utDm9weeMcmLpgo7OlNjKegeExzk) 6 | 7 | Download the [KnowledgeBase Builder database](./AlbertEinstein.kdb) 8 | 9 | ![Mind Map of People who inspired Albert Einstein and who were inspired by Albert Einstein](AlbertEinstein.gif?raw=true "Mind Map of People who inspired Albert Einstein and who were inspired by Albert Einstein") 10 | -------------------------------------------------------------------------------- /People/NobelPrice/NobelPricePhysics.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inforapid/SPARQL/2ec8bc0b69446ee0c8b82c2aeb3c82f40df25bf3/People/NobelPrice/NobelPricePhysics.gif -------------------------------------------------------------------------------- /People/NobelPrice/NobelPricePhysics.kdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inforapid/SPARQL/2ec8bc0b69446ee0c8b82c2aeb3c82f40df25bf3/People/NobelPrice/NobelPricePhysics.kdb -------------------------------------------------------------------------------- /People/NobelPrice/NobelPricePhysics.sparql: -------------------------------------------------------------------------------- 1 | #query 2 | SELECT ?i_Occupation ?ic_Occupation ?i_OccupationLabel ?i_GeneralizedOccupation ?ic__Occupation ?i_GeneralizedOccupationLabel 3 | WHERE 4 | { 5 | ?i_Occupation (wdt:P279*) wd:Q169470. 6 | ?i_Occupation wdt:P279 ?i_GeneralizedOccupation. 7 | SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } 8 | } 9 | 10 | #query 11 | SELECT ?i_priceWinner ?i_priceWinnerLabel ?ii_PriceWinnerPic ?i_occupation ?ic_occupation ?i_occupationLabel ?i_occupationDescription ?rn_t_DateOfBirthLabel ?ic_DateOfBirth ?rn_t_DateOfDeathLabel ?ic_DateOfDeath ?rn_NobelPriceYear (year(?NobelPriceYear) as ?i_NobelPriceYear) ?ic_NobelPriceYear 12 | WHERE 13 | { 14 | ?i_priceWinner wdt:P166 wd:Q38104. 15 | ?i_priceWinner wdt:P106 ?i_occupation. 16 | FILTER((?i_occupation != wd:Q169470) && (?i_occupation != wd:Q1622272) && (?i_occupation != wd:Q1231865) && (?i_occupation != wd:Q205375)). 17 | ?i_priceWinner p:P166 ?statement. 18 | ?statement ps:P166 wd:Q38104. 19 | ?statement pq:P585 ?NobelPriceYear. 20 | OPTIONAL { ?i_priceWinner wdt:P18 ?ii_PriceWinnerPic. } 21 | OPTIONAL { ?i_priceWinner wdt:P569 ?ic_DateOfBirth. } 22 | OPTIONAL { ?rn_t_DateOfBirth wikibase:directClaim wdt:P569. } 23 | OPTIONAL { ?i_priceWinner wdt:P570 ?ic_DateOfDeath. } 24 | OPTIONAL { ?rn_t_DateOfDeath wikibase:directClaim wdt:P570. } 25 | BIND("awarding" AS ?rn_NobelPriceYear). 26 | SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } 27 | } 28 | -------------------------------------------------------------------------------- /People/NobelPrice/README.md: -------------------------------------------------------------------------------- 1 | # Mind Map of Nobel Price winners in Physics 2 | 3 | Show the [SQARQL query](./NobelPricePhysics.sparql) 4 | 5 | [LIVE DEMO: Nobel Price winners in physics and their profession](https://inforapid.org/webapp/webapp.php?shareddb=atwa7k9pqcOvsRcU8BeyNNLHUM5FzcaenpYad7yrUf6REqOBUmcMMIOPR43VtcGDF6gPVYu9M8bIjoTSnK4F9lTCb4N3INkH) 6 | 7 | Download the [KnowledgeBase Builder database](./NobelPricePhysics.kdb) 8 | 9 | ![Mind Map of Nobel Price winners in Physics](NobelPricePhysics.gif?raw=true "Mind Map of Nobel Price winners in Physics") 10 | -------------------------------------------------------------------------------- /People/Philosophers/philosophers.sparql: -------------------------------------------------------------------------------- 1 | SELECT DISTINCT ?i_philosopher ?i_philosopherLabel ?i_philosopherDescription ?iu_philosopher ?ii_philosopher ?rn_t_DateOfBirthLabel ?ic_birthDate ?rn_t_DateOfDeathLabel ?ic_DateOfDeath ?ic_milyear ?ic_centyear ?ic_decyear ?rn_country ?i_country ?i_countryLabel ?i_countryDecription 2 | WHERE 3 | { 4 | { 5 | SELECT ?ic_decyear ?ic_centyear 6 | WHERE 7 | { 8 | ?philosopher wdt:P106 wd:Q4964182. 9 | ?philosopher wdt:P569 ?birthDate. 10 | FILTER ((YEAR(?birthDate) > 100) && (YEAR(?birthDate) < 500)). 11 | BIND (xsd:integer(FLOOR(YEAR(?birthDate) / 10) * 10) AS ?ic_decyear). 12 | BIND (xsd:integer(FLOOR(YEAR(?birthDate) / 100) * 100) AS ?ic_centyear). 13 | } 14 | } 15 | UNION 16 | { 17 | SELECT ?ic_centyear ?ic_milyear 18 | WHERE 19 | { 20 | ?philosopher wdt:P106 wd:Q4964182. 21 | ?philosopher wdt:P569 ?birthDate. 22 | FILTER ((YEAR(?birthDate) > 100) && (YEAR(?birthDate) < 500)). 23 | BIND (xsd:integer(FLOOR(YEAR(?birthDate) / 100) * 100) AS ?ic_centyear). 24 | BIND (xsd:integer(FLOOR(YEAR(?birthDate) / 1000) * 1000) AS ?ic_milyear). 25 | } 26 | } 27 | UNION 28 | { 29 | SELECT ?i_philosopher ?iu_philosopher ?ii_philosopher ?ic_decyear ?rn_t_DateOfBirth ?ic_birthDate ?rn_t_DateOfDeath ?ic_DateOfDeath ?rn_country ?i_country 30 | WHERE 31 | { 32 | ?i_philosopher wdt:P106 wd:Q4964182. 33 | ?i_philosopher wdt:P569 ?ic_birthDate. 34 | FILTER ((YEAR(?ic_birthDate) > 100) && (YEAR(?ic_birthDate) < 500)). 35 | BIND (xsd:integer(FLOOR(YEAR(?ic_birthDate) / 10) * 10) AS ?ic_decyear). 36 | ?rn_t_DateOfBirth wikibase:directClaim wdt:P569. 37 | OPTIONAL { 38 | ?i_philosopher wdt:P570 ?ic_DateOfDeath. 39 | ?rn_t_DateOfDeath wikibase:directClaim wdt:P570. 40 | } 41 | BIND (CONCAT (STR (?i_philosopher), "§if") AS ?iu_philosopher). 42 | OPTIONAL { ?i_philosopher wdt:P18 ?ii_philosopher. } 43 | BIND ("country" AS ?rn_country). 44 | OPTIONAL { ?i_philosopher wdt:P27 ?i_country. } 45 | } 46 | } 47 | 48 | SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } 49 | } 50 | -------------------------------------------------------------------------------- /People/Plaques/AberdeenPlaques.kdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inforapid/SPARQL/2ec8bc0b69446ee0c8b82c2aeb3c82f40df25bf3/People/Plaques/AberdeenPlaques.kdb -------------------------------------------------------------------------------- /People/Plaques/AberdeenPlaques.sparql: -------------------------------------------------------------------------------- 1 | #Query to select all of the human subjects of Commemorative plaques in Aberdeen, their occupations, dates of birth / death. 2 | # Change Q62274582 to another administrative area (e.g. Q55934339 for Glasgow) to get the results for there. 3 | 4 | SELECT ?i_subject ?iu_enwiki ?i_subjectLabel ?ii_pic ?rn_t_dobLabel ?i_DOB ?rn_t_dodLabel ?i_DOD ?i_place ?i_placeLabel ?i_plaque ?i_plaqueLabel ?ii_plaqueImage ?i_occupationLabel WHERE 5 | { 6 | BIND(wd:Q62274582 as ?i_place) 7 | 8 | ?i_plaque wdt:P31 wd:Q721747; wdt:P131 wd:Q62274582 . 9 | ?i_plaque wdt:P547 ?i_subject . 10 | ?i_subject wdt:P31 wd:Q5 . 11 | 12 | OPTIONAL { ?iu_enwiki schema:about ?i_subject; schema:isPartOf } 13 | OPTIONAL {?i_subject wdt:P18 ?ii_pic. } 14 | OPTIONAL {?i_plaque wdt:P18 ?ii_plaqueImage .} 15 | OPTIONAL {?rn_t_dob wikibase:directClaim wdt:P569. } 16 | OPTIONAL {?i_subject wdt:P569 ?i_DOB .} 17 | OPTIONAL {?rn_t_dod wikibase:directClaim wdt:P570. } 18 | OPTIONAL {?i_subject wdt:P570 ?i_DOD .} 19 | SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } 20 | } -------------------------------------------------------------------------------- /People/Plaques/Aberdeen_plaques.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inforapid/SPARQL/2ec8bc0b69446ee0c8b82c2aeb3c82f40df25bf3/People/Plaques/Aberdeen_plaques.gif -------------------------------------------------------------------------------- /People/Plaques/README.md: -------------------------------------------------------------------------------- 1 | # Mind Map of Commemorative PLaques and their subjects using Aberdeen, UK as an example 2 | 3 | Show the [SQARQL query](./AberdeenPlaques.sparql) 4 | 5 | 6 | 7 | Download the [KnowledgeBase Builder database](./AberdeenPlaques.kdb) 8 | 9 | ![Mind Map of Aberdeen PLaques and their Subjects](Aberdeen_plaques.gif?raw=true "Aberdeen Commemorative Plaques and their subjects") 10 | -------------------------------------------------------------------------------- /Queries/MultiLevelQuery.sparql: -------------------------------------------------------------------------------- 1 | SELECT ?i_from ?i_fromLabel ?i_fromDescription (?i_from as ?iu_from) ?ii_fromImage ?rc_propertyLabel ?i_to ?i_toLabel ?i_toDescription (?i_to as ?iu_to) ?ii_toImage WHERE { 2 | { 3 | SELECT DISTINCT ?i_from ?i_fromLabel ?i_fromDescription ?rc_propertyLabel ?i_to ?i_toLabel ?i_toDescription WHERE { 4 | VALUES ?root { 5 | wd:Q460387 6 | } 7 | { 8 | BIND(?root AS ?i_to) 9 | ?i_from ?property1 ?root. 10 | FILTER(STRSTARTS(STR(?property1), str(wdt:))) 11 | } 12 | UNION 13 | { 14 | BIND(?root AS ?i_from) 15 | ?root ?property1 ?i_to. 16 | FILTER(STRSTARTS(STR(?property1), str(wdt:))) 17 | } 18 | UNION 19 | { 20 | ?i_to ?property2 ?root. 21 | ?i_from ?property1 ?i_to. 22 | FILTER(STRSTARTS(STR(?property2), str(wdt:))) 23 | FILTER(STRSTARTS(STR(?property1), str(wdt:))) 24 | } 25 | UNION 26 | { 27 | ?i_from ?property2 ?root; 28 | ?property1 ?i_to. 29 | FILTER(STRSTARTS(STR(?property2), str(wdt:))) 30 | FILTER(STRSTARTS(STR(?property1), str(wdt:))) 31 | } 32 | UNION 33 | { 34 | ?root ?property2 ?i_from. 35 | ?i_from ?property1 ?i_to. 36 | FILTER(STRSTARTS(STR(?property2), str(wdt:))) 37 | FILTER(STRSTARTS(STR(?property1), str(wdt:))) 38 | } 39 | UNION 40 | { 41 | ?root ?property2 ?i_to. 42 | ?i_from ?property1 ?i_to. 43 | FILTER(STRSTARTS(STR(?property2), str(wdt:))) 44 | FILTER(STRSTARTS(STR(?property1), str(wdt:))) 45 | } 46 | UNION 47 | { 48 | ?i_mid ?property3 ?root. 49 | ?i_to ?property2 ?i_mid. 50 | ?i_from ?property1 ?i_to. 51 | FILTER(STRSTARTS(STR(?property3), str(wdt:))) 52 | FILTER(STRSTARTS(STR(?property2), str(wdt:))) 53 | FILTER(STRSTARTS(STR(?property1), str(wdt:))) 54 | } 55 | SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } 56 | OPTIONAL { ?rc_property wikibase:directClaim ?property1. } 57 | } 58 | LIMIT 10000 59 | } 60 | FILTER(LANG(?i_fromLabel)) 61 | FILTER(LANG(?i_toLabel)) 62 | OPTIONAL { ?i_from wdt:P18 ?ii_fromImage. } 63 | OPTIONAL { ?i_to wdt:P18 ?ii_toImage. } 64 | } 65 | -------------------------------------------------------------------------------- /Queries/MultiLevelQueryForPresentation.sparql: -------------------------------------------------------------------------------- 1 | SELECT ?i_from ?i_fromLabel ?i_fromDescription ?ii_fromImage ?rc_propertyLabel ?i_to ?i_toLabel ?i_toDescription ?ii_toImage WHERE { 2 | { 3 | SELECT DISTINCT ?i_from ?i_fromLabel ?i_fromDescription ?rc_propertyLabel ?i_to ?i_toLabel ?i_toDescription WHERE { 4 | VALUES ?root { 5 | wd:Q37200 6 | } 7 | { 8 | BIND(?root AS ?i_to) 9 | ?i_from ?property1 ?root. 10 | FILTER(STRSTARTS(STR(?property1), str(wdt:))) 11 | } 12 | UNION 13 | { 14 | BIND(?root AS ?i_from) 15 | ?root ?property1 ?i_to. 16 | FILTER(STRSTARTS(STR(?property1), str(wdt:))) 17 | } 18 | UNION 19 | { 20 | ?i_to ?property2 ?root. 21 | ?i_from ?property1 ?i_to. 22 | FILTER(STRSTARTS(STR(?property2), str(wdt:))) 23 | FILTER(STRSTARTS(STR(?property1), str(wdt:))) 24 | } 25 | UNION 26 | { 27 | ?i_from ?property2 ?root; 28 | ?property1 ?i_to. 29 | FILTER(STRSTARTS(STR(?property2), str(wdt:))) 30 | FILTER(STRSTARTS(STR(?property1), str(wdt:))) 31 | } 32 | UNION 33 | { 34 | ?root ?property2 ?i_from. 35 | ?i_from ?property1 ?i_to. 36 | FILTER(STRSTARTS(STR(?property2), str(wdt:))) 37 | FILTER(STRSTARTS(STR(?property1), str(wdt:))) 38 | } 39 | UNION 40 | { 41 | ?root ?property2 ?i_to. 42 | ?i_from ?property1 ?i_to. 43 | FILTER(STRSTARTS(STR(?property2), str(wdt:))) 44 | FILTER(STRSTARTS(STR(?property1), str(wdt:))) 45 | } 46 | UNION 47 | { 48 | ?i_mid ?property3 ?root. 49 | ?i_to ?property2 ?i_mid. 50 | ?i_from ?property1 ?i_to. 51 | FILTER(STRSTARTS(STR(?property3), str(wdt:))) 52 | FILTER(STRSTARTS(STR(?property2), str(wdt:))) 53 | FILTER(STRSTARTS(STR(?property1), str(wdt:))) 54 | } 55 | SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } 56 | OPTIONAL { ?rc_property wikibase:directClaim ?property1. } 57 | } 58 | LIMIT 10000 59 | } 60 | FILTER(LANG(?i_fromLabel)) 61 | FILTER(LANG(?i_toLabel)) 62 | OPTIONAL { ?i_from wdt:P18 ?ii_fromImage. } 63 | OPTIONAL { ?i_to wdt:P18 ?ii_toImage. } 64 | FILTER (BOUND(?ii_fromImage) || BOUND(?ii_toImage)) 65 | } 66 | -------------------------------------------------------------------------------- /Queries/MultiLevelQueryForPresentationCompact.sparql: -------------------------------------------------------------------------------- 1 | SELECT ?i_from ?i_fromLabel ?i_fromDescription (?i_from as ?iu_from) ?ii_fromImage ?rc_propertyLabel ?i_to ?i_toLabel ?i_toDescription (?i_to as ?iu_to) ?ii_toImage WHERE { 2 | { 3 | SELECT DISTINCT ?i_from ?i_fromLabel ?i_fromDescription ?rc_propertyLabel ?i_to ?i_toLabel ?i_toDescription WHERE { 4 | VALUES ?root { 5 | wd:Q37200 6 | } 7 | { 8 | BIND(?root AS ?i_from) 9 | ?root ?property ?i_to. 10 | FILTER(STRSTARTS(STR(?property), str(wdt:))) 11 | FILTER(?property NOT IN (wdt:P1343, wdt:P5008, wdt:P495, wdt:P2596, wdt:P17, wdt:P31, wdt:P131, wdt:P186, wdt:P149, wdt:P910, wdt:P1424, wdt:P1889, wdt:P355, wdt:P793)) 12 | } 13 | UNION 14 | { 15 | ?root ?property ?i_to. 16 | ?i_from ?property ?i_to. 17 | FILTER(STRSTARTS(STR(?property), str(wdt:))) 18 | FILTER(?property NOT IN (wdt:P1343, wdt:P5008, wdt:P495, wdt:P2596, wdt:P17, wdt:P31, wdt:P131, wdt:P186, wdt:P149, wdt:P910, wdt:P1424, wdt:P1889, wdt:P355, wdt:P793)) 19 | } 20 | UNION 21 | { 22 | ?root ?property1 ?i_from. 23 | ?i_from ?property ?i_to. 24 | FILTER(STRSTARTS(STR(?property1), str(wdt:))) 25 | FILTER(?property1 NOT IN (wdt:P1343, wdt:P5008, wdt:P495, wdt:P2596, wdt:P17, wdt:P31, wdt:P131, wdt:P186, wdt:P149, wdt:P910, wdt:P1424, wdt:P1889, wdt:P355, wdt:P793)) 26 | FILTER(STRSTARTS(STR(?property), str(wdt:))) 27 | FILTER(?property NOT IN (wdt:P1343, wdt:P5008, wdt:P495, wdt:P2596, wdt:P17, wdt:P31, wdt:P131, wdt:P186, wdt:P149, wdt:P910, wdt:P1424, wdt:P1889, wdt:P355, wdt:P793)) 28 | } 29 | SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } 30 | OPTIONAL { ?rc_property wikibase:directClaim ?property. } 31 | } 32 | LIMIT 500 33 | } 34 | FILTER(LANG(?i_fromLabel)) 35 | FILTER(LANG(?i_toLabel)) 36 | OPTIONAL { ?i_from wdt:P18 ?ii_fromImage. } 37 | OPTIONAL { ?i_to wdt:P18 ?ii_toImage. } 38 | FILTER (BOUND(?ii_fromImage) || BOUND(?ii_toImage)) 39 | } 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SPARQL 2 | 3 | In this project I want to collect useful SPARQL queries for the WikiData endpoint for use with the InfoRapid KnowledgeBase Builder. Please participate and publish your own favorite SPARQL queries. 4 | 5 | ## SPARQL and the InfoRapid KnowledgeBase Builder 6 | 7 | ![3D rotating MindMap of SPARQL query result](images/Example.gif?raw=true "Example") 8 | 9 | ### The following prefixes must be used for SPARQL variables in the KnowledgeBase Builder SELECT statement: 10 | ``` 11 | i_ : item 12 | ic_ : item category, the column values are ignored, only the column header is relevant 13 | in_ or i_XXXLabel or ic_XXXLabel: item name 14 | id_ or i_XXXDescription or ic_XXXDescription: item description 15 | iu_ : item url 16 | ii_ : item image 17 | idi_ : item description image 18 | rn_ : relation name 19 | rn_t_ : relation name for a table relation 20 | rc_ : relation category 21 | 22 | The columns in the SELECT statement must have the following order (the values in round brackets are optional) 23 | 24 | ?i_item1 (?ic_item1) (?in_item1) (?id_item1) (?iu_item1) (?ii_item1) (?rn_relation1) (?rc_relation1) ?i_item2 (?ic_item2) ... (?rn_relation2) (?i_item3) ... 25 | 26 | This SELECT statement connects item1 through relation1 with item2 and through relation 2 with item3 27 | 28 | One result row can connect item1 with any number of other items 29 | 30 | A line starting with the comment #query can be used to separte many queries 31 | ``` 32 | 33 | ## Tips for SPARQL queries 34 | * Use OPTIONAL to prevent timeouts wherever it's possible 35 | 36 | ## SPARQL code snippets for use with the InfoRapid KnowledgeBase Builder 37 | 38 | #### Convert an url so that it opens inplace in the KnowledgeBase Builder: 39 | ``` 40 | BIND (CONCAT (STR (?url), "§if") AS ?iu_url). 41 | ``` 42 | 43 | #### Create an url which links ?i_place to its position in Google Maps 44 | ``` 45 | OPTIONAL { ?i_place p:P625 ?statement. 46 | ?statement psv:P625 ?coordinate_node. 47 | ?coordinate_node wikibase:geoLatitude ?lat. 48 | ?coordinate_node wikibase:geoLongitude ?long. 49 | BIND (CONCAT ("http://www.google.com/maps/place/", STR(?lat), ",", STR(?long), "§if") AS ?iu_url). 50 | } 51 | ``` 52 | 53 | #### Query the Wikipedia url for i_item 54 | ``` 55 | OPTIONAL { ?iu_wikipedia_url schema:about ?i_item; schema:isPartOf } 56 | ``` 57 | 58 | #### Find all places within a given radius around a central location 59 | ``` 60 | ?centerPlace wdt:P625 ?centerLoc. 61 | SERVICE wikibase:around { 62 | ?i_place wdt:P625 ?location. # the first statement must include the place and the location 63 | bd:serviceParam wikibase:center ?centerLoc. 64 | bd:serviceParam wikibase:radius "10". # maximum distance in kilometers 65 | bd:serviceParam wikibase:distance ?dist. # current distance in kilometers 66 | } 67 | ``` 68 | 69 | #### Calculate the distance between two locations 70 | ``` 71 | BIND (geof:distance (?location1, ?location2) AS ?dist). 72 | ``` 73 | 74 | #### Round the distance with a precision of 10 meters and add the unit m 75 | ``` 76 | BIND (CONCAT (xsd:string (xsd:integer (CEIL (100 * ?dist) * 10)), " m") AS ?rounded_dist_in_m). 77 | ``` 78 | 79 | #### item1 is connected to item2 through property, get the propertyName (SELECT propertyNameLabel) 80 | ``` 81 | ?item1 ?property ?item2. 82 | OPTIONAL { ?propertyName wikibase:directClaim ?property. } 83 | ``` 84 | 85 | #### Get the image to an item 86 | ``` 87 | OPTIONAL { ?i_item wdt:P18 ?ii_itemImage. } 88 | ``` 89 | 90 | #### Get Date of Birth / Date of Death / Place of Birth / Place of Death for a person 91 | ``` 92 | OPTIONAL { ?i_person wdt:P569 ?ic_DateOfBirth. } 93 | OPTIONAL { ?rn_t_DateOfBirth wikibase:directClaim wdt:P569. } 94 | OPTIONAL { ?i_person wdt:P570 ?ic_DateOfDeath. } 95 | OPTIONAL { ?rn_t_DateOfDeath wikibase:directClaim wdt:P570. } 96 | OPTIONAL { ?i_person wdt:P19 ?ic_PlaceOfBirth. } 97 | OPTIONAL { ?rn_t_PlaceOfBirth wikibase:directClaim wdt:P19. } 98 | OPTIONAL { ?i_person wdt:P20 ?ic_PlaceOfDeath. } 99 | OPTIONAL { ?rn_t_PlaceOfDeath wikibase:directClaim wdt:P20. } 100 | ``` 101 | 102 | #### Define a constant 103 | ``` 104 | VALUES (?item) {(wd:Q138809)} 105 | ``` 106 | -------------------------------------------------------------------------------- /images/Example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inforapid/SPARQL/2ec8bc0b69446ee0c8b82c2aeb3c82f40df25bf3/images/Example.gif -------------------------------------------------------------------------------- /images/content.txt: -------------------------------------------------------------------------------- 1 | Content 2 | --------------------------------------------------------------------------------