Yokohama Art Spot meets SPARQL

6,102 views
6,006 views

Published on

Published in: Education, Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,102
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Yokohama Art Spot meets SPARQL

  1. 1. Yokohama Art Spot meets SPARQL7/23/2011 LinkedData.jp
  2. 2. ✦✦ twitter: @wintermelon✦ 2011 4✦✦ LODAC✦4 SPARQL
  3. 3. LODAC (Linked Open Data for ACademia)✦ http://lod.ac✦ Web✦ ✴ Linked Data(LOD) ✴ ✴✦ ✴ ✴ LODAC
  4. 4. LODAC Museum✦ ✴ LOD✦ ✴ RDF ✴ ✴ LOD ✴✦ ✴ ✴ LODAC
  5. 5. LODAC Museum✦ ✴ ✴ ✴ ✴ DBpedia Lite ✴ 15 → 70✦ 13035604✦ SPARQL http://lod.ac/sparql
  6. 6. Yokohama Art Spot✦ http://lod.ac/apps/yas/✦✦ LODAC × LOD✦ LODAC
  7. 7. Yokohama Art Spot
  8. 8. 1.2.3.1.2.3.
  9. 9. 1.2.3.1.2.3.
  10. 10. ✦ ID ✴ ✴ ✴ ✴ ✴ ✴
  11. 11. Yokohama Art Spot q_spt = """ 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(%(NE_lat)s %(NE_long)s %(SW_lat)s %(SW_long)s); geo:lat ?lat; geo:long ?long; dc:source <http://place.yafjp.org/rdf/>; vcard:postal-code ?postalcode; <http://ocdi.jp/ns/pi#address> ?address . OPTIONAL{ ?ref dc:abstract ?access . }
  12. 12. Step1 q_spt = """ 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(%(NE_lat)s %(NE_long)s %(SW_lat)s %(SW_long)s); geo:lat ?lat; geo:long ?long; dc:source <http://place.yafjp.org/rdf/>; vcard:postal-code ?postalcode; <http://ocdi.jp/ns/pi#address> ?address . OPTIONAL{ ?ref dc:abstract ?access . }
  13. 13. Step2 & q_spt = """ 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(%(NE_lat)s %(NE_long)s %(SW_lat)s %(SW_long)s); geo:lat ?lat; geo:long ?long; dc:source <http://place.yafjp.org/rdf/>; vcard:postal-code ?postalcode; <http://ocdi.jp/ns/pi#address> ?address . OPTIONAL{ ?ref dc:abstract ?access . }Python + SPARQLWrapper (http://sparql-wrapper.sourceforge.net/) from SPARQLWrapper import SPARQLWrapper, JSON sparql_wrapper = SPARQLWrapper(SPARQL URL) query = SPARQL sparql_wrapper.setQuery(query) sparql_wrapper.setReturnFormat(JSON) results = sparql_wrapper.query().convert() SPARQL
  14. 14. Step2-1 q_spt = """ 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(%(NE_lat)s %(NE_long)s %(SW_lat)s %(SW_long)s); geo:lat ?lat; geo:long ?long; dc:source <http://place.yafjp.org/rdf/>; vcard:postal-code ?postalcode; <http://ocdi.jp/ns/pi#address> ?address . OPTIONAL{ ?ref dc:abstract ?access . } } """ % locals()
  15. 15. 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#>PREFIX ?link <http://purl.org/dc/terms/references> ?ref . ?link dc:references ?ref .
  16. 16. q_spt = """ 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(%(NE_lat)s %(NE_long)s %(SW_lat)s %(SW_long)s); geo:lat ?lat; geo:long ?long; dc:source <http://place.yafjp.org/rdf/>; vcard:postal-code ?postalcode; <http://ocdi.jp/ns/pi#address> ?address . OPTIONAL{ ?ref dc:abstract ?access . } } """ % locals()
  17. 17. SELECT distinct ?link ?title ?lat ?long ?postalcode ?address ?accessWHERE { ?link rdf:type foaf:Organization; ? rdfs:label ?title; dc:references ?ref . ?ref omgeo:within(%(NE_lat)s %(NE_long)s %(SW_lat)s %(SW_long)s); geo:lat ?lat; geo:long ?long; ? ? ? ; dc:source <http://place.yafjp.org/rdf/>; ? ? ; vcard:postal-code ?postalcode; <http://ocdi.jp/ns/pi#address> ?address ? ? . . OPTIONAL{ ?ref dc:abstract ?access . }}
  18. 18. SELECT distinct ?link ?title ?lat ?long ?postalcode ?address ?accessWHERE { ?link rdf:type foaf:Organization; rdfs:label ?title; dc:references ?ref SELECT . ?link URI ?ref omgeo:within(%(NE_lat)s %(NE_long)s %(SW_lat)s %(SW_long)s); geo:lat ?lat; ?title geo:long ?long; ?lat dc:source <http://place.yafjp.org/rdf/>; vcard:postal-code ?postalcode; ?long <http://ocdi.jp/ns/pi#address> ?address ?postalcode . ?address OPTIONAL{ ?access ?ref dc:abstract ?access . }}
  19. 19. SELECT distinct ?link ?title ?lat ?long ?postalcode ?address ?accessWHERE { ?link rdf:type foaf:Organization; rdfs:label ?title; 1. dc:references ?ref ?link . ?ref omgeo:within(%(NE_lat)s %(NE_long)s2. ?link %(SW_lat)s %(SW_long)s); geo:lat ?lat; geo:long ?long; ?title dc:source <http://place.yafjp.org/rdf/>; ?ref vcard:postal-code ?postalcode; <http://ocdi.jp/ns/pi#address> ?address ※ LODAC ?link . 1 ?ref OPTIONAL{ ?ref dc:abstract ?access ?ref . }} 3. ?ref
  20. 20. LODAC 2 crm:P55_has_current_location dc:creator dc:references dc:references crm:P55_has_current_location crm:P55_has_current_location dc:references dc:references dc:creatordc:creator dc:references dc:references URI URI
  21. 21. LODAC 2 crm:P55_has_current_location dc:creator dc:references dc:references crm:P55_has_current_location crm:P55_has_current_location dc:references dc:references dc:creatordc:creator dc:references dc:references URI URI
  22. 22. SELECT distinct ?link ?title ?lat ?long ?postalcode ?address ?accessWHERE { ?link rdf:type foaf:Organization; rdfs:label ?title; dc:references ?ref . ?ref omgeo:within(%(NE_lat)s %(NE_long)s %(SW_lat)s %(SW_long)s); geo:lat ?lat; geo:long ?long; dc:source <http://place.yafjp.org/rdf/>; vcard:postal-code ?postalcode; GET <http://ocdi.jp/ns/pi#address> ?address . ?ref OPTIONAL{ ?ref dc:abstract ?access . }}
  23. 23. omgeo?✦ ?ref ?ref geo:lat ?lat; geo:long ?long. FILTER(?lat < 35.432916 && ?lat > 35.475012 && ?long < 139.608699 && ?long > 139.652644)✦ omgeo 1 ?ref omgeo:within(35.475012 139.652644 35.439216 139.608699). ✴ OWLIM virtuoso ✴ ●●km
  24. 24. SELECT distinct ?link ?title ?lat ?long ?postalcode ?address ?accessWHERE { ?link rdf:type foaf:Organization; rdfs:label ?title; dc:references ?ref . ?ref omgeo:within(%(NE_lat)s %(NE_long)s %(SW_lat)s %(SW_long)s); geo:lat ?lat; geo:long ?long; dc:source <http://place.yafjp.org/rdf/>; vcard:postal-code ?postalcode; <http://ocdi.jp/ns/pi#address> ?address . OPTIONAL{ ?ref dc:abstract ?access <http://place.yafjp.org/rdf/> . }} ?lat ?postalcode ?long ?address
  25. 25. SELECT distinct ?link ?title ?lat ?long ?postalcode ?address ?accessWHERE { ?link rdf:type foaf:Organization; rdfs:label ?title; dc:references ?ref . ?ref omgeo:within(%(NE_lat)s %(NE_long)s %(SW_lat)s %(SW_long)s); geo:lat ?lat; geo:long ?long; dc:source <http://place.yafjp.org/rdf/>;dc:abstract ?ref vcard:postal-code ?postalcode; ?access <http://ocdi.jp/ns/pi#address> ?address . OPTIONAL OPTIONAL{ ?ref dc:abstract ?access . }}
  26. 26. SPARQL JSON {"spt": {"head": {"vars": ["link", "title", "lat", "long", "postalcode", "address", "access"]}, "results": {"bindings": [{"title": {"xml:lang": "ja", "type": "literal", "value": "u6a2au6d5cu7f8eu8853u9928"}, "long": {"datatype": "http://www.w3.org/2001/XMLSchema#float", "type": "typed-literal", "value": "139.63044"}, "access": {"type": "literal", "value": "u685cu6728u753a u99c5(JR)u4e0bu8ecau3001u52d5u304f u6b69u9053u3092u5229u7528u5f92u6b6910u5206u3002u307fu306au3068u307f u3089u3044u99c5(u307fu306au3068u307fu3089u3044u7dda)u4e0bu8eca u3001u300cu7f8eu8853u9928u53e3u300du3092u51fa u3066u5f92u6b693u5206u3002"}, "postalcode": {"type": "literal", "value": "220-0012"}, "link": {"type": "uri", "value": "http://lod.ac/id/3172"}, "address": {"xml:lang": "ja", "type": "literal", "value": "u6a2au6d5c u5e02u897fu533au307fu306au3068u307fu3089u30443u4e01u76ee4-1"}, "lat": {"datatype": "http://www.w3.org/2001/XMLSchema#float", "type": "typed-literal", "value": "35.45722"}}, {"title": {"xml:lang": "ja", "type": "literal", "value": "u307fu306au3068u307fu3089u3044u30aeu30e3u30e9u30eau30fc"}, "long": {"datatype": "http://www.w3.org/2001/XMLSchema#float", "type": "typed-literal", "value": "139.6341"}, "postalcode": {"type": "literal", "value": "220-0012"}, "link": {"type": "uri", "value": "http://lod.ac/id/530977"}, "address": {"xml:lang": "ja", "type": "literal", "value": "u795eu5948u5dddu770cu6a2a u6d5cu5e02u897fu533au307fu306au3068u307fu3089u30442u4e01u76ee3-5"}, "lat": {"datatype": "http://www.w3.org/2001/XMLSchema#float", "type": "typed- …
  27. 27. SPARQL …
  28. 28. Step2-2✦ ?link ?link ical:dtstart ?dtstart ; ical:dtend ?dtend . FILTER ( (?dtstart > "%(dtstart)s"^^xsd:dateTime && ?dtstart < "%(dtend)s"^^xsd:dateTime) || (?dtend > "%(dtstart)s"^^xsd:dateTime && ?dtend < "%(dtend)s"^^xsd:dateTime) || (?dtstart < "%(dtstart)s"^^xsd:dateTime && ?dtend > "%(dtend)s"^^xsd:dateTime) )✦ … dateTime FILTER 0 Sesame
  29. 29. Step3 q_spt = """ 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(%(NE_lat)s %(NE_long)s %(SW_lat)s %(SW_long)s); geo:lat ?lat; geo:long ?long; dc:source <http://place.yafjp.org/rdf/>; vcard:postal-code ?postalcode; <http://ocdi.jp/ns/pi#address> ?address . OPTIONAL{ ?ref dc:abstract ?access . }1. 12. JSON3. JSON✦ or ON/OFF✦
  30. 30. SPARQL LOD✦ omgeo:within✦ Semantic Media Wiki → Wiki SPARQL✦ DBpedia GeoNames✦ dc:created 1990 [1980] 1990 c. 1990 1980-90 55

×