A simple 4 lines script to convert JSON-exported CONSTRUCT
queries from WIKIDATA into Turtle (ttl) file
Build a CONSTRUCT
query into Wikidata Query Service and export the result in JSON using the "Download button"
For exemple this query exporting Game Of Thrones Characters
PREFIX schema: <http://schema.org/>
CONSTRUCT {
?c a schema:Person .
?c schema:name ?cLabel .
?c schema:parent ?cm .
?c schema:parent ?cf .
?c schema:sibling ?cs .
?c schema:affiliation ?cfa .
?c schema:gender ?cgenderLabel .
?c schema:birthPlace ?cbirthPlaceLabel .
# ?c schema:deathPlace ?cdeathPlaceLabel . SPOILERS
?c schema:spouse ?cspouse .
?cfa a schema:Organization .
?cfa schema:name ?cfaLabel .
}
WHERE {
?c wdt:P31 wd:Q20086263 .
?c wdt:P1080 wd:Q2461698 .
OPTIONAL { ?c wdt:P25 ?cm . ?cm wdt:P1080 wd:Q2461698 . } # Mother
OPTIONAL { ?c wdt:P21 ?cgender} # Gender
OPTIONAL { ?c wdt:P19 ?cbirthPlace} # Birthplace
OPTIONAL { ?c wdt:P20 ?cdeathPlace} # DeathPlace
OPTIONAL { ?c wdt:P22 ?cf . ?cf wdt:P1080 wd:Q2461698 . } # Father
OPTIONAL { ?c wdt:P3373 ?cs . ?cs wdt:P1080 wd:Q2461698 . } # Sibling
OPTIONAL { ?c wdt:P26 ?cspouse . ?cspouse wdt:P1080 wd:Q2461698 . } # Spouse
OPTIONAL { ?c wdt:P53 ?cfa . ?cfa wdt:P1080 wd:Q2461698 . } # family
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Edit the 2 first lines and set your downloaded file path in SOURCE
and the target turtle file in DESTINATION
.
Paste the 4 lines into your shell and run it