SPARQLスニペット
Fumihiro Kato edited this page Jul 16, 2015
·
1 revision
PREFIX lodacid: <http://lod.ac/id/> SELECT * WHERE { lodacid:455 ?p ?o . }
PREFIX dc: <http://purl.org/dc/terms/> PREFIX lodac: <http://lod.ac/ns/lodac#> PREFIX lodacid: <http://lod.ac/id/> SELECT ?work ?title WHERE { lodacid:359 lodac:creates ?work . ?work dc:title ?title . }
PREFIX dc: <http://purl.org/dc/terms/> PREFIX lodacid: <http://lod.ac/id/> SELECT * WHERE { lodacid:3172 dc:references ?ref . ?ref ?p ?o . }
PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT * WHERE { ?s a foaf:Organization; rdfs:label ?label . } LIMIT 100
PREFIX dc: <http://purl.org/dc/terms/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX lodac: <http://lod.ac/ns/lodac#> PREFIX lodacid: <http://lod.ac/id/> SELECT DISTINCT ?genre WHERE { lodacid:3172 lodac:isProviderOf ?work . ?work rdfs:label ?label; dc:references ?workRef . ?workRef lodac:genre ?genre . }
PREFIX dc: <http://purl.org/dc/terms/> PREFIX dc11: <http://purl.org/dc/elements/1.1/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX lodac: <http://lod.ac/ns/lodac#> PREFIX lodacid: <http://lod.ac/id/> SELECT ?work ?title ?creator ?created ?genre ?material ?size WHERE { lodacid:3172 lodac:isProviderOf ?work . ?work rdfs:label ?title; dc:references ?workRef . ?workRef lodac:genre "日本画"@ja; dc11:creator ?creator; dc:medium ?material; dc:extent ?size . OPTIONAL{ ?workRef dc:created ?created . } } LIMIT 100
PREFIX dc: <http://purl.org/dc/terms/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX lodac: <http://lod.ac/ns/lodac#> PREFIX lodacid: <http://lod.ac/id/> SELECT ?work ?label WHERE { lodacid:3172 lodac:isProviderOf ?work . ?work rdfs:label ?label; dc:references ?workRef . ?workRef dc:medium "紙本着色"@ja . } LIMIT 100
PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/terms/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX lodac: <http://lod.ac/ns/lodac#> PREFIX lodacid: <http://lod.ac/id/> SELECT ?work ?label WHERE { lodacid:3172 lodac:isProviderOf ?work . ?work rdfs:label ?label ; dc:creator ?workRef . ?workRef foaf:name "前田青邨"@ja . } LIMIT 100
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dc: <http://purl.org/dc/terms/> PREFIX omgeo: <http://www.ontotext.com/owlim/geo#> PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> PREFIX lodac: <http://lod.ac/ns/lodac#> PREFIX vcard: <http://www.w3.org/2006/vcard/ns#> SELECT distinct ?link ?title ?lat ?long ?postalcode ?address ?access WHERE { ?link rdf:type foaf:Organization; rdfs:label ?title; dc:references ?ref . ?ref omgeo:within(37.29417220890252 143.09140847471917 29.030252776842698 133.20371316221917); geo:lat ?lat; geo:long ?long; vcard:postal-code ?postalcode; <http://ocdi.jp/ns/pi#address> ?address . OPTIONAL{ ?ref dc:abstract ?access . } } ORDER BY (omgeo:distance(?lat, ?long, 33.259834887744994, 138.14756081846917))
PREFIX ical: <http://www.w3.org/2002/12/cal/icaltzd#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX event: <http://lod.ac/ns/event#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT * WHERE { ?event a event:Event ; rdfs:label ?event_name ; ical:location ?location ; ical:dtstart ?dtstart ; ical:dtend ?dtend . ?location rdfs:label ?location_name . FILTER (?dtstart >= "2010-01-01T00:00:00+09:00"^^xsd:dateTime) FILTER (?dtend < "2010-02-01T00:00:00+09:00"^^xsd:dateTime) } LIMIT 100
PREFIX ical: <http://www.w3.org/2002/12/cal/icaltzd#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX event: <http://lod.ac/ns/event#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX dc: <http://purl.org/dc/terms/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX lodacid: <http://lod.ac/id/> PREFIX dc11: <http://purl.org/dc/elements/1.1/> SELECT * WHERE { ?link a event:Event ; rdfs:label ?title ; event:fee ?fee; ical:categories ?cat; ical:location lodacid:3172 ; ical:dtstart ?dtstart ; ical:dtend ?dtend . lodacid:3172 rdfs:label ?location . ?cat dc11:title ?category. OPTIONAL{ ?link event:Credit ?crd . ?crd dc11:description ?credit . } FILTER ((?dtstart > "2011-07-01T00:00:00+09:00"^^xsd:dateTime && ?dtstart < "2011-07-31T00:00:00+09:00"^^xsd:dateTime) || (?dtend > "2011-07-01T00:00:00+09:00"^^xsd:dateTime && ?dtend < "2011-07-31T00:00:00+09:00"^^xsd:dateTime) || (?dtstart < "2011-07-01T00:00:00+09:00"^^xsd:dateTime && ?dtend > "2011-07-31T00:00:00+09:00"^^xsd:dateTime)) }
PREFIX ical: <http://www.w3.org/2002/12/cal/icaltzd#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX event: <http://lod.ac/ns/event#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX dc: <http://purl.org/dc/terms/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX lodacid: <http://lod.ac/id/> PREFIX omgeo: <http://www.ontotext.com/owlim/geo#> PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> PREFIX vcard: <http://www.w3.org/2006/vcard/ns#> SELECT distinct ?event ?lat ?long ?title ?location_name ?location ?fee ?dtstart ?dtend WHERE { ?event a event:Event ; rdfs:label ?title ; event:fee ?fee; ical:location ?location ; ical:dtstart ?dtstart ; ical:dtend ?dtend . ?location rdfs:label ?location_name ; dc:references ?locRef. ?locRef omgeo:within(37.29417220890252 143.09140847471917 29.030252776842698 133.20371316221917); vcard:postal-code ?postalcode; geo:lat ?lat; geo:long ?long. FILTER ((?dtstart > "2011-07-01T00:00:00+09:00"^^xsd:dateTime && ?dtstart < "2011-07-31T00:00:00+09:00"^^xsd:dateTime) || (?dtend > "2011-07-01T00:00:00+09:00"^^xsd:dateTime && ?dtend < "2011-07-31T00:00:00+09:00"^^xsd:dateTime) || (?dtstart < "2011-07-01T00:00:00+09:00"^^xsd:dateTime && ?dtend > "2011-07-31T00:00:00+09:00"^^xsd:dateTime)) } ORDER BY (omgeo:distance(?lat, ?long, 33.259834887744994, 138.14756081846917))
PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dc: <http://purl.org/dc/terms/> PREFIX lodac: <http://lod.ac/ns/lodac#> PREFIX lodacid: <http://lod.ac/id/> SELECT ?work ?label ?startyear ?endyear ?img WHERE { ?lodacRef a lodac:LODACReference; dc:created "1984"; lodac:startYear ?startyear; lodac:endYear ?endyear; dc:isReferencedBy ?work . ?work rdfs:label ?label; dc:references ?workRef. ?workRef foaf:depiction ?img. }
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX lodac: <http://lod.ac/ns/lodac#> PREFIX dc: <http://purl.org/dc/terms/> PREFIX lodacid: <http://lod.ac/id/> SELECT * WHERE { ?s dc:references ?ref . MINUS { ?s dc:references/rdf:type lodac:LODACReference . } } LIMIT 100
SELECT DISTINCT ?s ?label WHERE { ?s rdfs:label ?label . ?label luc:myIndex "*北海道*" . } LIMIT 10
PREFIX lodac: <http://lod.ac/ns/lodac#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?workName (COUNT(?workName) AS ?countName) WHERE { ?work a lodac:Work; rdfs:label ?workName. FILTER (lang(?workName) = "ja") } GROUP BY ?workName ORDER BY DESC(?countName) LIMIT 100
workrefのcurrent_locationにはリソースとリテラルの両ケースがあるので、それを統合
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX lodac: <http://lod.ac/ns/lodac#> PREFIX dc: <http://purl.org/dc/terms/> PREFIX crm: <http://purl.org/NET/cidoc-crm/core#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT DISTINCT ?loc { { ?s rdf:type lodac:Work . ?s crm:P55_has_current_location ?locres . ?locres rdfs:label ?loc . FILTER (isLiteral(?loc)) FILTER(regex(str(?loc), "神社")) } UNION { ?s rdf:type lodac:Work . ?s dc:references/crm:P55_has_current_location ?loc . FILTER (isLiteral(?loc)) FILTER(regex(str(?loc), "神社")) } } LIMIT 10000
PREFIX lodac: <http://lod.ac/ns/lodac#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dc: <http://purl.org/dc/terms/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?title ?imgUrl WHERE { ?work a lodac:Work; rdfs:label ?title; dc:references ?ref. ?ref foaf:depiction ?imgUrl. FILTER regex(str(?title), str("猫")) }
PREFIX lodac: <http://lod.ac/ns/lodac#> PREFIX dc: <http://purl.org/dc/terms/> PREFIX crm: <http://purl.org/NET/cidoc-crm/core#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?title ?loc WHERE { ?work a lodac:Work. ?work rdfs:label ?title. ?work dc:references/crm:P55_has_current_location ?loc . FILTER (isLiteral(?loc)) FILTER (regex(str(?loc), "神社$")) FILTER (regex(str(?title), "仏")) }
場所がリテラルでなくリソースの場合も対応
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX lodac: <http://lod.ac/ns/lodac#> PREFIX dc: <http://purl.org/dc/terms/> PREFIX crm: <http://purl.org/NET/cidoc-crm/core#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?title ?loc ?s ?so { { ?s rdf:type lodac:Work . ?s crm:P55_has_current_location ?locres . ?locres rdfs:label ?loc . ?s rdfs:label ?title . ?s dc:references/dc:source ?so . FILTER (isLiteral(?loc)) FILTER(regex(str(?loc), "神社")) FILTER (regex(str(?title), "仏|如来|釈迦|薬師|菩薩|観音|明王")) } UNION { ?s rdf:type lodac:Work . ?s dc:references/crm:P55_has_current_location ?loc . ?s rdfs:label ?title . ?s dc:references/dc:source ?so . FILTER (isLiteral(?loc)) FILTER(regex(str(?loc), "神社")) FILTER (regex(str(?title), "仏|如来|釈迦|薬師|菩薩|観音|明王")) } } LIMIT 10000
PREFIX lodacid: <http://lod.ac/id/> PREFIX lodac: <http://lod.ac/ns/lodac#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT DISTINCT ?p ?type WHERE { ?s a lodac:Work . ?s ?p ?o . ?o rdf:type ?type . } LIMIT 100
このlodac:Workを色々変えると、スキーマ構造を調べることができるが、 foaf:Organizationなどはレスポンスが返ってこない。 refの方も網羅的に調べたい場合は以下の通り(遅すぎて無理)
PREFIX dc: <http://purl.org/dc/terms/> PREFIX lodacid: <http://lod.ac/id/> PREFIX lodac: <http://lod.ac/ns/lodac#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT distinct ?predicate ?type_of_object WHERE { ?item rdf:type foaf:Organization . ?item dc:references ?ref . ?ref ?predicate ?o . ?o rdf:type ?type_of_object } LIMIT 100
?item rdf:type foaf:Organization を一旦取ってきて、それぞれに対し、以下のように投げることが考えられる。
PREFIX dc: <http://purl.org/dc/terms/> PREFIX lodacid: <http://lod.ac/id/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT distinct ?predicate ?type_of_object WHERE { lodacid:3172 dc:references ?ref . ?ref ?predicate ?o . ?o rdf:type ?type_of_object } LIMIT 100
※ここでは,出身地をlodac:currentLocationNameとしている.
※lodac:currentLocationNameをlodac:areaに変更してもOK.
PREFIX dc: <http://purl.org/dc/terms/> PREFIX lodac: <http://lod.ac/ns/lodac#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?location (COUNT(?location) AS ?locNum) WHERE{ { SELECT ?artist (COUNT(?work) AS ?workNum) WHERE { ?artist a foaf:Person; lodac:creates ?work; dc:references ?ref. ?ref lodac:area ?area. } GROUP BY ?artist HAVING (?workNum > 10) ORDER BY DESC(?workNum) } { ?artist dc:references/lodac:currentLocationName ?location } } GROUP BY ?location ORDER BY DESC(?locNum)
※ここではテンペラ作品を対象とする.
※int型へのキャストが実装されておらず,幅広さの算出がSPARQLで行えないため,各館のテンペラ作品制作年の最古と最新のものを列挙した.
PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX lodac: <http://lod.ac/ns/lodac#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dc: <http://purl.org/dc/terms/> PREFIX lodacid: <http://lod.ac/id/> SELECT ?museum (MIN(?created) as ?mincreated) (MAX(?created) as ?maxcreated) WHERE { ?museum a foaf:Organization; lodac:isProviderOf ?work. ?work dc:references/dc:medium ?medium; dc:references ?worklodacref. ?worklodacref a lodac:LODACReference; dc:created ?created. FILTER regex(str(?medium), str("テンペラ")) } GROUP BY ?museum
PREFIX lodac: <http://lod.ac/ns/lodac#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX lodacid: <http://lod.ac/id/> PREFIX dc: <http://purl.org/dc/terms/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?image ?url ?image_id WHERE { ?label rdfs:label "国立西洋博物館"@ja; lodac:isProviderOf ?resource . ?resource dc:references ?url . ?url foaf:depiction ?image . ?url dc:isReferencedBy ?image_id . } LIMIT 10
PREFIX dc: <http://purl.org/dc/terms/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX lodac: <http://lod.ac/ns/lodac#> PREFIX lodacid: <http://lod.ac/id/> SELECT DISTINCT ?label (COUNT(?label) AS ?countName) WHERE { ?work a lodac:Work; rdfs:label ?title; dc:references ?ref. ?ref dc:medium ?label. } GROUP BY ?label ORDER BY DESC(?countName) LIMIT 1000
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX rda2: <http://RDVocab.info/ElementsGr2/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dc: <http://purl.org/dc/terms/> PREFIX lodac: <http://lod.ac/ns/lodac#> PREFIX lodacid: <http://lod.ac/id/> SELECT ?work ?title ?creator ?creatorname ?age WHERE { lodacid:3172 lodac:isProviderOf ?work. ?work a lodac:Work; rdfs:label ?title; dc:creator ?creator; dc:references ?ref. ?ref a lodac:LODACReference; dc:created ?created. ?creator rdfs:label ?creatorname; dc:references/rda2:dateOfBirth ?dob. BIND((xsd:integer(?created)-xsd:integer(?dob)) AS ?age) FILTER(lang(?title)="ja") FILTER(?age >= 20) FILTER(?age < 30) } ORDER BY ?age
PREFIX crm: <http://purl.org/NET/cidoc-crm/core#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX rda2: <http://RDVocab.info/ElementsGr2/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dc: <http://purl.org/dc/terms/> PREFIX lodac: <http://lod.ac/ns/lodac#> PREFIX lodacid: <http://lod.ac/id/> SELECT ?work ?title ?creator ?creatorname ?museum ?museumname ?age WHERE { ?work a lodac:Work; rdfs:label ?title; dc:creator lodacid:510; crm:P55_has_current_location ?museum; dc:references ?ref. ?museum rdfs:label ?museumname. ?ref a lodac:LODACReference; dc:created ?created. lodacid:510 rdfs:label ?creatorname; dc:references/rda2:dateOfBirth ?dob. BIND((xsd:integer(?created)-xsd:integer(?dob)) AS ?age) } ORDER BY ?age
PREFIX dc: <http://purl.org/dc/terms/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX lodac: <http://lod.ac/ns/lodac#> PREFIX lodacid: <http://lod.ac/id/> SELECT DISTINCT ?label (COUNT(?label) AS ?countName) WHERE { ?work a lodac:Work; rdfs:label ?title; dc:references ?ref. ?ref dc:medium ?label. FILTER regex(str(?label), str("リトグラフ|Lithograph")) } GROUP BY ?label ORDER BY DESC(?countName) LIMIT 1000
PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX lodac: <http://lod.ac/ns/lodac#> SELECT (COUNT(DISTINCT ?org) AS ?countOrg) WHERE { ?org a foaf:Organization ; lodac:isProviderOf ?work . }
PREFIX dc: <http://purl.org/dc/terms/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX lodac: <http://lod.ac/ns/lodac#> PREFIX lodacid: <http://lod.ac/id/> SELECT DISTINCT ?label (COUNT(?label) AS ?countName) WHERE { ?work a lodac:Work; rdfs:label ?title; dc:references ?ref. ?ref dc:medium ?label. FILTER regex(str(?label), str("リトグラフ|Lithograph")) } GROUP BY ?label ORDER BY DESC(?countName) LIMIT 1000
PREFIX dcndl: <http://ndl.go.jp/dcndl/terms/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dc: <http://purl.org/dc/terms/> PREFIX lodacid: <http://lod.ac/id/> SELECT * WHERE { Graph <http://lod.ac/bdls/provenance/1> { ?s ?p ?o . } } LIMIT 100
- 地名で「東○○」「西○○」に当てはまる○○を列挙
- 【済】 作品が10個以上ある作者が一番多い出身地を抽出
- ○○という技法の作品の黎明期から現代まで幅広くおいているとこはどーこ?
- LODACに登録された作品のある博物館でも美術館でも神社でもないどこか
- プロパティはなんでもいいので,ある人物に関連する画像を列挙