• 検索結果がありません。

講義概要 SPARQL とは? RDF ストア GraphDB による SPARQL 検索方法 Turtle 基本的なクエリ FILTER, OPTIONAL, DISTINCT, UNION, LIMIT, ORDER BY, GROUP BY, MAX, AVG, SUM, COUNT, リモー

N/A
N/A
Protected

Academic year: 2021

シェア "講義概要 SPARQL とは? RDF ストア GraphDB による SPARQL 検索方法 Turtle 基本的なクエリ FILTER, OPTIONAL, DISTINCT, UNION, LIMIT, ORDER BY, GROUP BY, MAX, AVG, SUM, COUNT, リモー"

Copied!
72
0
0

読み込み中.... (全文を見る)

全文

(1)

2016年度 春学期

Webインテリジェンス論

(2)

講義概要

▪ SPARQLとは?

▪ RDFストア

▪ GraphDBによるSPARQL検索方法

▪ Turtle

▪ 基本的なクエリ

– FILTER, OPTIONAL, DISTINCT, UNION, LIMIT,

ORDER BY, GROUP BY, MAX, AVG, SUM, COUNT,

リモートの

SPARQLエンドポイントへのクエリ

▪ DBpedia

▪ 演習問題1

▪ 演習問題2

(3)
(4)

SPARQLとは?

▪ RDFデータを検索するためのクエリ言語(RDBMS

における

SQLに相当)

– ver. 1.0(2008年1月にW3C勧告)

http://www.w3.org/TR/rdf-sparql-query/

http://www.asahi-net.or.jp/~ax2s-kmtn/internet/rdf/rdf-sparql-query.html

(日本語訳)

– ver. 1.1(2013年3月にW3C勧告)

http://www.w3.org/TR/sparql11-overview

http://www.asahi-net.or.jp/~ax2s-

kmtn/internet/rdf/REC-sparql11-query-20130321.html

(日本語訳)

(5)

RDFデータストア

▪ RDFデータを格納し,SPARQLによるクエリなどを可能にす

るアプリケーション

▪ SPARQLエンドポイントを提供

– queryパラメータ値にURLエンコードしたSPARQLクエリを与えること

で,結果を得ることができる

Web API

▪ 本講義ではGraphDBを利用

http://ontotext.com/products/graphdb/

▪ 以下のURLから本日の講義で説明するSPARQLクエリを実

行可能

– http://zest.comp.ae.keio.ac.jp/ – ID: wi2016 – パスワード: 講義中に提示します

(6)
(7)
(8)
(9)

Turtle

▪ RDFフォーマットの一種

▪ RDF/XML構文よりも簡潔にRDF文書を表現

可能

http://www.w3.org/TR/turtle/

▪ 本日の講義のサンプルRDF文書はTurtleで

記述

▪ SPARQLの構文はTurtleに類似

(10)

Turtle

<http://example.org/夏目漱石> <http:/example.org/代表作> <http://example.org/こころ> .

<主語URI> <述語URI> <目的語URI> .

@prefix ex: <http://example.org/> .

ex:夏目漱石 ex:代表作 ex:こころ .

1

2

(11)

Turtle

@prefix ex: <http://example.org/> .

ex:夏目漱石 ex:代表作 ex:こころ .

ex:夏目漱石

ex:誕生日 “1867年2月9日” .

3

;

(セミコロン)により,主語を省略可能

@prefix ex: <http://example.org/> .

ex:夏目漱石 ex:代表作 ex:こころ

;

(12)

Turtle

@prefix ex: <http://example.org/> .

ex:夏目漱石 ex:代表作 ex:こころ .

ex:夏目漱石 ex:代表作

ex:坊っちゃん .

4

,

(カンマ)により,主語と述語を省略可能

(目的語を複数列挙可能)

@prefix ex: <http://example.org/> .

(13)

Turtle

@prefix ex: <http://example.org/> .

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

ex:夏目漱石

rdf:type

ex:小説家 .

5

rdf:typeは「

a

」で表現可能

@prefix ex: <http://example.org/> .

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

ex:夏目漱石

a

ex:小説家 .

(14)

RDF文書: ex002.ttl

# filename: ex002.ttl

@prefix ab: <http://learningsparql.com/ns/addressbook#> .

ab:richard ab:homeTel "(229) 276-5135" .

ab:richard ab:email "[email protected]" .

ab:cindy ab:homeTel "(245) 646-5488" .

ab:cindy ab:email "[email protected]" .

ab:craig ab:homeTel "(194) 966-1505" .

ab:craig ab:email "[email protected]" .

(15)

SPARQLクエリ: ex003.rq

# filename: ex003.rq

PREFIX ab: <http://learningsparql.com/ns/addressbook#>

SELECT

?craigEmail

WHERE

{

Graph<http://zest.comp.ae.keio.ac.jp/ex002> {

ab:craig ab:email

?craigEmail

.

}

}

(16)

RDF文書: ex002.ttl

# filename: ex002.ttl

@prefix ab: <http://learningsparql.com/ns/addressbook#> .

ab:richard ab:homeTel "(229) 276-5135" .

ab:richard ab:email "[email protected]" .

ab:cindy ab:homeTel "(245) 646-5488" .

ab:cindy ab:email "[email protected]" .

ab:craig ab:homeTel "(194) 966-1505" .

ab:craig ab:email

"[email protected]"

.

(17)

SPARQLクエリ: ex008.rq

# filename: ex008.rq

PREFIX ab: <http://learningsparql.com/ns/addressbook#>

SELECT

?person

WHERE {

Graph<http://zest.comp.ae.keio.ac.jp/ex002> {

?person

ab:homeTel "(229) 276-5135" .

}

}

(18)

RDF文書: ex002.ttl

# filename: ex002.ttl

@prefix ab: <http://learningsparql.com/ns/addressbook#> .

ab:richard

ab:homeTel "(229) 276-5135" .

ab:richard ab:email "[email protected]" .

ab:cindy ab:homeTel "(245) 646-5488" .

ab:cindy ab:email "[email protected]" .

ab:craig ab:homeTel "(194) 966-1505" .

ab:craig ab:email "[email protected]" .

(19)

SPARQLクエリ: ex010.rq

# filename: ex010.rq

PREFIX ab: <http://learningsparql.com/ns/addressbook#>

SELECT

?propertyName ?propertyValue

WHERE {

Graph<http://zest.comp.ae.keio.ac.jp/ex002> {

ab:cindy

?propertyName ?propertyValue

.

}

}

(20)

RDF文書: ex002.ttl

# filename: ex002.ttl

@prefix ab: <http://learningsparql.com/ns/addressbook#> .

ab:richard ab:homeTel "(229) 276-5135" .

ab:richard ab:email "[email protected]" .

ab:cindy

ab:homeTel "(245) 646-5488"

.

ab:cindy

ab:email "[email protected]

" .

ab:craig ab:homeTel "(194) 966-1505" .

ab:craig ab:email "[email protected]" .

(21)

RDF文書: ex012.ttl

# filename: ex012.ttl @prefix ab: <http://learningsparql.com/ns/addressbook#> . @prefix d: <http://learningsparql.com/ns/data#> . d:i0432 ab:firstName "Richard" . d:i0432 ab:lastName "Mutt" . d:i0432 ab:homeTel "(229) 276-5135" . d:i0432 ab:email "[email protected]" . d:i9771 ab:firstName "Cindy" . d:i9771 ab:lastName "Marshall" . d:i9771 ab:homeTel "(245) 646-5488" . d:i9771 ab:email "[email protected]" . d:i8301 ab:firstName "Craig" . d:i8301 ab:lastName "Ellis" . d:i8301 ab:email "[email protected]" . d:i8301 ab:email "[email protected]" .

(22)

SPARQLクエリ: ex013.rq

# filename: ex013.rq

PREFIX ab: <http://learningsparql.com/ns/addressbook#>

SELECT

?craigEmail

WHERE {

Graph<http://zest.comp.ae.keio.ac.jp/ex012> {

?person

ab:firstName"Craig" .

?person

ab:email

?craigEmail

.

}

(23)

RDF文書: ex012.ttl

# filename: ex012.ttl @prefix ab: <http://learningsparql.com/ns/addressbook#> . @prefix d: <http://learningsparql.com/ns/data#> . d:i0432 ab:firstName "Richard" . d:i0432 ab:lastName "Mutt" . d:i0432 ab:homeTel "(229) 276-5135" . d:i0432 ab:email "[email protected]" . d:i9771 ab:firstName "Cindy" . d:i9771 ab:lastName "Marshall" . d:i9771 ab:homeTel "(245) 646-5488" . d:i9771 ab:email "[email protected]" . d:i8301 ab:firstName "Craig" . d:i8301 ab:lastName "Ellis" . d:i8301 ab:email "[email protected]" . d:i8301 ab:email "[email protected]" .

(24)

SPARQLクエリ: ex021.rq

# filename: ex021.rq

PREFIX ab: <http://learningsparql.com/ns/addressbook#>

SELECT

*

WHERE {

Graph<http://zest.comp.ae.keio.ac.jp/ex012> {

?s ?p ?o .

FILTER (regex(?o, "yahoo","i"))

}

}

iオプションをつけると 大文字・小文字を 区別しなくなる

(25)

RDF文書: ex012.ttl

# filename: ex012.ttl @prefix ab: <http://learningsparql.com/ns/addressbook#> . @prefix d: <http://learningsparql.com/ns/data#> . d:i0432 ab:firstName "Richard" . d:i0432 ab:lastName "Mutt" . d:i0432 ab:homeTel "(229) 276-5135" . d:i0432 ab:email "[email protected]" . d:i9771 ab:firstName "Cindy" . d:i9771 ab:lastName "Marshall" . d:i9771 ab:homeTel "(245) 646-5488" . d:i9771 ab:email "[email protected]" . d:i8301 ab:firstName "Craig" . d:i8301 ab:lastName "Ellis" . d:i8301 ab:email "[email protected]" . d:i8301 ab:email "[email protected]" .

(26)

SPARQL 演習問題1

1. ex012.ttl文書において,登録されている人物の名

(firstName)と苗字(lastName)を表示する

SPARQLクエリを作成せよ

2. ex012.ttl文書において,自宅の電話番号が

(245) 646-5488」である人物の名前と苗字を表

示する

SPARQLクエリを作成せよ

3. ex012.ttl文書において,「hotmail」を含むメール

アドレスを持つ人物の名前と苗字を表示する

SPARQLクエリを作成せよ

上記

1〜3で作成したクエリをSPARQLエンドポイント

http://zest.comp.ae.keio.ac.jp/sparql)上で実

行し,結果を確認せよ

(27)

RDF文書: ex054.ttl

# filename: ex054.ttl @prefix ab: <http://learningsparql.com/ns/addressbook#> . @prefix d: <http://learningsparql.com/ns/data#> . d:i0432 ab:firstName "Richard" . d:i0432 ab:lastName "Mutt" . d:i0432 ab:homeTel "(229) 276-5135" . d:i0432 ab:nick "Dick" . d:i0432 ab:email "[email protected]" . d:i9771 ab:firstName "Cindy" . d:i9771 ab:lastName "Marshall" . d:i9771 ab:homeTel "(245) 646-5488" . d:i9771 ab:email "[email protected]" . d:i8301 ab:firstName "Craig" . d:i8301 ab:lastName "Ellis" . d:i8301 ab:workTel "(245) 315-5486" . d:i8301 ab:email "[email protected]" . d:i8301 ab:email "[email protected]" .

(28)

SPARQLクエリ: ex057.rq

# filename: ex057.rq PREFIX ab: <http://learningsparql.com/ns/addressbook#> SELECT ?first ?last ?workTel WHERE { ?s ab:firstName ?first ; ab:lastName ?last . OPTIONAL { ?s ab:workTel ?workTel . } }

Graph IRI: http://zest.comp.ae.keio.ac.jp/ex054

?s ab:firstName ?first ; ab:lastName ?last ; ab:workTel ?workTel .

(29)

RDF文書: ex054.ttl

# filename: ex054.ttl @prefix ab: <http://learningsparql.com/ns/addressbook#> . @prefix d: <http://learningsparql.com/ns/data#> . d:i0432 ab:firstName "Richard" . d:i0432 ab:lastName "Mutt" . d:i0432 ab:homeTel "(229) 276-5135" . d:i0432 ab:nick "Dick" . d:i0432 ab:email "[email protected]" . d:i9771 ab:firstName "Cindy" . d:i9771 ab:lastName "Marshall" . d:i9771 ab:homeTel "(245) 646-5488" . d:i9771 ab:email "[email protected]" . d:i8301 ab:firstName "Craig" . d:i8301 ab:lastName "Ellis" . d:i8301 ab:workTel "(245) 315-5486" . d:i8301 ab:email "[email protected]" . d:i8301 ab:email "[email protected]" .

(30)

SPARQLクエリ: ex061.rq

# filename: ex061.rq PREFIX ab: <http://learningsparql.com/ns/addressbook#> SELECT ?first ?last ?workTel ?nick WHERE { ?s ab:firstName ?first ; ab:lastName ?last . OPTIONAL { ?s ab:workTel ?workTel . } OPTIONAL { ?s ab:nick ?nick . } }

Graph IRI: http://zest.comp.ae.keio.ac.jp/ex054

OPTIONAL { ?s ab:workTel ?workTel; ab:nick ?nick . }

(31)

RDF文書: ex054.ttl

# filename: ex054.ttl @prefix ab: <http://learningsparql.com/ns/addressbook#> . @prefix d: <http://learningsparql.com/ns/data#> . d:i0432 ab:firstName "Richard" . d:i0432 ab:lastName "Mutt" . d:i0432 ab:homeTel "(229) 276-5135" . d:i0432 ab:nick "Dick" . d:i0432 ab:email "[email protected]" . d:i9771 ab:firstName "Cindy" . d:i9771 ab:lastName "Marshall" . d:i9771 ab:homeTel "(245) 646-5488" . d:i9771 ab:email "[email protected]" . d:i8301 ab:firstName "Craig" . d:i8301 ab:lastName "Ellis" . d:i8301 ab:workTel "(245) 315-5486" . d:i8301 ab:email "[email protected]" . d:i8301 ab:email "[email protected]" .

(32)

SPARQLクエリ: ex067.rq

# filename: ex067.rq PREFIX ab: <http://learningsparql.com/ns/addressbook#> SELECT ?first ?last WHERE { ?s ab:firstName ?first ; ab:lastName ?last . FILTER NOT EXISTS { ?s ab:workTel ?workNum } }

Graph IRI: http://zest.comp.ae.keio.ac.jp/ex054

(33)

RDF文書: ex054.ttl

# filename: ex054.ttl @prefix ab: <http://learningsparql.com/ns/addressbook#> . @prefix d: <http://learningsparql.com/ns/data#> . d:i0432 ab:firstName "Richard" . d:i0432 ab:lastName "Mutt" . d:i0432 ab:homeTel "(229) 276-5135" . d:i0432 ab:nick "Dick" . d:i0432 ab:email "[email protected]" . d:i9771 ab:firstName "Cindy" . d:i9771 ab:lastName "Marshall" . d:i9771 ab:homeTel "(245) 646-5488" . d:i9771 ab:email "[email protected]" . d:i8301 ab:firstName "Craig" . d:i8301 ab:lastName "Ellis" . d:i8301 ab:workTel "(245) 315-5486" . d:i8301 ab:email "[email protected]" . d:i8301 ab:email "[email protected]" .

(34)

RDF文書: ex069.ttl

# filename: ex069.ttl @prefix ab: <http://learningsparql.com/ns/addressbook#> . @prefix d: <http://learningsparql.com/ns/data#> . # People d:i0432 ab:firstName "Richard" ; ab:lastName "Mutt" ; ab:email "[email protected]" . d:i9771 ab:firstName "Cindy" ; ab:lastName "Marshall" ; ab:email "[email protected]" . d:i8301 ab:firstName "Craig" ; ab:lastName "Ellis" ; ab:email "[email protected]" . # Courses

d:course34 ab:courseTitle "Modeling Data with OWL" .

d:course71 ab:courseTitle "Enhancing Websites with RDFa" . d:course59 ab:courseTitle "Using SPARQL with non-RDF Data" .

d:course85 ab:courseTitle "Updating Data with SPARQL" . # Who's taking which courses d:i8301 ab:takingCourse d:course59 . d:i9771 ab:takingCourse d:course34 . d:i0432 ab:takingCourse d:course85 . d:i0432 ab:takingCourse d:course59 . d:i9771 ab:takingCourse d:course59 .

(35)

SPARQLクエリ: ex070.rq

# filename: ex070.rq PREFIX ab: <http://learningsparql.com/ns/addressbook#> SELECT ?last ?first ?courseName WHERE { ?s ab:firstName ?first ; ab:lastName ?last ; ab:takingCourse ?course . ?course ab:courseTitle?courseName . }

Graph IRI: http://zest.comp.ae.keio.ac.jp/ex069

(36)

SPARQLクエリ: ex094.rq

# filename: ex094.rq

PREFIX ab: <http://learningsparql.com/ns/addressbook#> SELECT DISTINCT?first ?last

WHERE { ?s ab:takingCourse ?class ; ab:firstName ?first ; ab:lastName ?last . }

Graph IRI: http://zest.comp.ae.keio.ac.jp/ex069

SELECT ?first ?last

(37)

RDF文書: ex100.ttl

# filename: ex100.ttl

@prefix ab: <http://learningsparql.com/ns/addressbook#> .

@prefix d: <http://learningsparql.com/ns/data#> .

d:i0432 ab:firstName "Richard" ;

ab:lastName "Mutt" ;

ab:instrument"sax" ;

ab:instrument"clarinet" .

d:i9771 ab:firstName "Cindy" ;

ab:lastName "Marshall" ;

ab:instrument"drums" .

d:i8301 ab:firstName "Craig" ;

ab:lastName "Ellis" ;

ab:instrument"trumpet" .

(38)

SPARQLクエリ: ex103.rq

# filename: ex103.rq PREFIX ab: <http://learningsparql.com/ns/addressbook#> SELECT ?first ?last ?instrument WHERE { ?person ab:firstName?first ; ab:lastName?last ; ab:instrument?instrument . { ?person ab:instrument "sax" . } UNION { ?person ab:instrument "trumpet" . } }

Graph IRI: http://zest.comp.ae.keio.ac.jp/ex100

(39)

RDF文書: ex104.ttl

# filename: ex104.ttl

@prefix dm: <http://learningsparql.com/ns/demo#> .

@prefix d: <http://learningsparql.com/ns/data#> .

d:item432 dm:cost 8 ;

dm:location <http://dbpedia.org/resource/Boston> .

d:item857 dm:cost 12 ;

dm:location <http://dbpedia.org/resource/Montreal> .

d:item693 dm:cost 10 ;

dm:location "Heidelberg" .

d:item126 dm:cost 5 ;

dm:location <http://dbpedia.org/resource/Lisbon> .

(40)

SPARQLクエリ: ex105.rq

# filename: ex105.rq

PREFIX dm: <http://learningsparql.com/ns/demo#>

SELECT ?s ?cost

WHERE

{

?s dm:cost?cost .

FILTER (?cost < 10)

}

Graph IRI: http://zest.comp.ae.keio.ac.jp/ex104

(41)

RDF文書: ex104.ttl

# filename: ex104.ttl

@prefix dm: <http://learningsparql.com/ns/demo#> .

@prefix d: <http://learningsparql.com/ns/data#> .

d:item432 dm:cost 8

;

dm:location <http://dbpedia.org/resource/Boston> .

d:item857 dm:cost 12 ;

dm:location <http://dbpedia.org/resource/Montreal> .

d:item693 dm:cost 10 ;

dm:location "Heidelberg" .

d:item126 dm:cost 5

;

dm:location <http://dbpedia.org/resource/Lisbon> .

(42)

SPARQLクエリ: ex109.rq

# filename: ex109.rq PREFIX dm: <http://learningsparql.com/ns/demo#> PREFIX db: <http://dbpedia.org/resource/> SELECT ?s ?cost ?location WHERE { ?s dm:location ?location ; dm:cost ?cost . FILTER (?location IN (db:Montreal, db:Lisbon)) . }

Graph IRI: http://zest.comp.ae.keio.ac.jp/ex104

(43)

RDF文書: ex104.ttl

# filename: ex104.ttl

@prefix dm: <http://learningsparql.com/ns/demo#> .

@prefix d: <http://learningsparql.com/ns/data#> .

d:item432 dm:cost 8 ;

dm:location <http://dbpedia.org/resource/Boston> .

d:item857 dm:cost 12 ;

dm:location <http://dbpedia.org/resource/Montreal> .

d:item693 dm:cost 10 ;

dm:location "Heidelberg" .

d:item126 dm:cost 5 ;

dm:location <http://dbpedia.org/resource/Lisbon> .

(44)

SPARQLクエリ: ex112.rq

# filename: ex112.rq PREFIX dm: <http://learningsparql.com/ns/demo#> PREFIX db: <http://dbpedia.org/resource/> SELECT ?s ?cost ?location WHERE { ?s dm:location ?location ; dm:cost ?cost .

FILTER (?location NOT IN (db:Montreal, db:Lisbon)) . }

(45)

RDF文書: ex104.ttl

# filename: ex104.ttl

@prefix dm: <http://learningsparql.com/ns/demo#> .

@prefix d: <http://learningsparql.com/ns/data#> .

d:item432 dm:cost 8 ;

dm:location <http://dbpedia.org/resource/Boston> .

d:item857 dm:cost 12 ;

dm:location <http://dbpedia.org/resource/Montreal> .

d:item693 dm:cost 10 ;

dm:location "Heidelberg" .

d:item126 dm:cost 5 ;

dm:location <http://dbpedia.org/resource/Lisbon> .

(46)

RDF文書: ex115.ttl

# filename: ex115.ttl

@prefix d: <http://learningsparql.com/ns/data#> .

@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

d:one rdfs:label "one" .

d:two rdfs:label "two" .

d:three rdfs:label "three" .

d:four rdfs:label "four" .

d:five rdfs:label "five" .

d:six rdfs:label "six" .

(47)

SPARQLクエリ: ex116.rq

# filename: ex116.rq

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?label

WHERE

{ ?s rdfs:label ?label . }

LIMIT 2

Graph IRI: http://zest.comp.ae.keio.ac.jp/ex115

(48)

RDF文書: ex145.ttl

# filename: ex145.ttl @prefix e: <http://learningsparql.com/ns/expenses#> . @prefix d: <http://learningsparql.com/ns/data#> . d:m40392 e:description "breakfast" ; e:date "2011-10-14" ; e:amount 6.53 . d:m40393 e:description "lunch" ; e:date "2011-10-14" ; e:amount 11.13 . d:m40394 e:description "dinner" ; e:date "2011-10-14" ; e:amount 28.30 . d:m40395 e:description "breakfast" ; e:date "2011-10-15" ; e:amount 4.32 . d:m40396 e:description "lunch" ; e:date "2011-10-15" ; e:amount 9.45 . d:m40397 e:description "dinner" ; e:date "2011-10-15" ; e:amount 31.45 . d:m40398 e:description "breakfast" ; e:date "2011-10-16" ; e:amount 6.65 . d:m40399 e:description "lunch" ; e:date "2011-10-16" ; e:amount 10.00 . d:m40400 e:description "dinner" ; e:date "2011-10-16" ; e:amount 25.05 .

(49)

SPARQLクエリ: ex146.rq

# filename: ex146.rq

PREFIX e: <http://learningsparql.com/ns/expenses#>

SELECT ?description ?date ?amount

WHERE

{

?meal e:description ?description ;

e:date ?date ;

e:amount ?amount .

}

ORDER BY ?amount

Graph IRI: http://zest.comp.ae.keio.ac.jp/ex145

(50)
(51)

SPARQLクエリ: ex148.rq

# filename: ex148.rq

PREFIX e: <http://learningsparql.com/ns/expenses#>

SELECT ?description ?date ?amount

WHERE

{

?meal e:description ?description ;

e:date ?date ;

e:amount ?amount .

}

ORDER BY

DESC(?amount)

Graph IRI: http://zest.comp.ae.keio.ac.jp/ex145

(52)
(53)

SPARQLクエリ: ex149.rq

# filename: ex149.rq

PREFIX e: <http://learningsparql.com/ns/expenses#>

SELECT ?description ?date ?amount

WHERE

{

?meal e:description ?description ;

e:date ?date ;

e:amount ?amount .

}

ORDER BY ?description DESC(?amount)

Graph IRI: http://zest.comp.ae.keio.ac.jp/ex145

(54)
(55)

SPARQLクエリ: ex151.rq

# filename: ex151.rq

PREFIX e: <http://learningsparql.com/ns/expenses#>

SELECT ?description ?date ?amount

WHERE

{

?meal e:description ?description ;

e:date ?date ;

e:amount?amount .

}

ORDER BY DESC(?amount)

LIMIT 1

Graph IRI: http://zest.comp.ae.keio.ac.jp/ex145

(56)

SPARQLクエリ: ex153.rq

# filename: ex153.rq

PREFIX e: <http://learningsparql.com/ns/expenses#>

SELECT

(MAX(?amount) as ?maxAmount)

WHERE { ?meal e:amount ?amount . }

Graph IRI: http://zest.comp.ae.keio.ac.jp/ex145

(57)

SPARQLクエリ: ex156.rq

# filename: ex156.rq

PREFIX e: <http://learningsparql.com/ns/expenses#>

SELECT

(AVG(?amount) as ?avgAmount)

WHERE { ?meal e:amount ?amount . }

Graph IRI: http://zest.comp.ae.keio.ac.jp/ex145

(58)

SPARQLクエリ: ex160.rq

# filename: ex160.rq

PREFIX e: <http://learningsparql.com/ns/expenses#>

SELECT ?description

(SUM(?amount) AS ?mealTotal)

WHERE

{

?meal e:description ?description ;

e:amount ?amount .

}

GROUP BY ?description

Graph IRI: http://zest.comp.ae.keio.ac.jp/ex145

(59)
(60)

SPARQLクエリ: ex162.rq

# filename: ex162.rq

SELECT ?p

(COUNT(?p) AS ?pTotal)

WHERE {

Graph<http://zest.comp.ae.keio.ac.jp/ex145> {

?s ?p ?o .

}

}

GROUP BY ?p

Graph IRI: http://zest.comp.ae.keio.ac.jp/ex145

(61)
(62)

SPARQLクエリ: ex170.rq

# filename: ex170.rq PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?p ?o WHERE { SERVICE <http://ja.dbpedia.org/sparql> { <http://ja.dbpedia.org/resource/東京都> ?p ?o . } } limit 50

(63)

DBpedia (Japanese)

▪ WikipediaからRDFデータを生成し,公開す

るプロジェクト

http://wiki.dbpedia.org/

▪ 120言語以上のWikipediaを対象としており,

日本語版が

DBpedia Japanese

http://ja.dbpedia.org/

▪ SPARQLエンドポイントが提供されている

http://dbpedia.org/sparql

http://ja.dbpedia.org/sparql

(64)

DBpedia Japanese サンプルSPARQLクエリ (1)

東京都出身のアスリートを,身長の高い順にソートし

て,上位

10人の氏名と身長と概要を表示するクエリ

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dbpedia-ja: <http://ja.dbpedia.org/resource/> PREFIX dbpedia-owl: <http://dbpedia.org/ontology/> PREFIX prop-ja: <http://ja.dbpedia.org/property/> select ?name ?height ?abstract where { ?athlete dbpedia-owl:birthPlace dbpedia-ja:東京都 ; rdf:type dbpedia-owl:Athlete ; prop-ja:身長 ?height ; rdfs:label ?name ; dbpedia-owl:abstract ?abstract . } order by desc(?height) limit 10

(65)

DBpedia Japanese サンプルSPARQLクエリ (2)

JR山手線駅を,一日の最大乗降車数の多い順にソートし

て,駅名と一日の最大乗降車数を表示するクエリ

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

PREFIX dbpedia-ja: <http://ja.dbpedia.org/resource/>

PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>

PREFIX prop-ja: <http://ja.dbpedia.org/property/>

select ?station_name (max(?passengersPerDay)

as ?maxPassgenersPerDay)

where {

?station dbpedia-owl:servingRailwayLine dbpedia-ja:山手線 ;

rdfs:label ?station_name ;

dbpedia-owl:passengersPerDay?passengersPerDay.

}

group by ?station ?station_name

order by desc(?maxPassgenersPerDay)

(66)

DBpedia Japanese サンプルSPARQLクエリ (3)

住所に「京都府」が含まれるお寺を,お寺の名前の昇順に

ソートして,お寺の名前と住所を表示するクエリ

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

PREFIX dbpedia-ja: <http://ja.dbpedia.org/resource/>

PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>

PREFIX prop-ja: <http://ja.dbpedia.org/property/>

select ?temple_name ?address

where {

?temple rdf:type dbpedia-owl:Temple ;

rdfs:label ?temple_name ;

dbpedia-owl:address ?address .

filter (regex(?address, "京都府"))

}

order by ?temple_name

(67)

SPARQL 演習問題2

▪ 演習問題2−1,2−2,2−3について,DBpedia Japaneseの

SPARQLエンドポイントを利用して,クエリを作成せよ

– SPARQLエンドポイント:http://ja.dbpedia.org/sparql

▪ 接頭辞と名前空間

– rdf

• http://www.w3.org/1999/02/22-rdf-syntax-ns#

– rdfs

• http://www.w3.org/2000/01/rdf-schema#

– dbpedia-ja

• http://ja.dbpedia.org/resource/

– dbpedia-owl

• http://ja.dbpedia.org/ontology/

– prop-ja

• http://ja.dbpedia.org/property/

(68)

SPARQL 演習問題2−1

▪ 宮﨑駿の監督作品について,rdfs:labelプロ

パティ値を昇順でソートして,上位

10件表示

するクエリを作成せよ

– 宮崎駿リソース: dbpedia-ja:宮﨑駿

– 監督プロパティ: dbpedia-owl:director

(69)

SPARQL 演習問題2−2

▪ 夏目漱石の代表作とそのwikiPageLength

を,

wikiPageLengthで降順にソートして,上

5件を表示するクエリを作成せよ

– 夏目漱石リソース: dbpedia-ja:夏目漱石

– 代表作プロパティ:

dbpedia-owl:notableWork

– wikiPageLengthプロパティ:

dbpedia-owl:wikiPageLength

(70)

SPARQL 演習問題2−3

▪ 上映時間が80分未満の映画作品について,

上映時間の降順かつ監督名の昇順でソート

した上位

5件について,映画作品名,監督名,

上映時間を表示するクエリを作成せよ

– 映画作品クラス: dbpedia-owl:Film

– 上映時間プロパティ: prop-ja:上映時間

– 監督プロパティ:dbpedia-owl:director

(71)

3回レポート

1. DBpedia JapaneseのSPARQLエンドポイントを利用して,

興味のある分野について

1つクエリを作成せよ(リンクを1つ

以上たどることで必要な情報が得られるようにすること)

– SPARQLエンドポイント:

http://ja.dbpedia.org/sparql

2. DBpediaのSPARQLエンドポイントを利用して,興味のあ

る分野について

1つクエリを作成せよ(数値のソート,平均,

最大,合計などを含むクエリを作成できると良い)

SPARQLエンドポイント:

http://dbpedia.org/sparql

上記,

SPARQLクエリ,その説明,実行結果の説明,実行

結果のスクリーンショット(多い場合は一部)を

Word等の文

書ファイルに貼り付けて,

keio.jpから提出せよ

提出締切:

7月19日(火) 23:59

(72)

参考文献

▪ Bob DuCharme: "Learning SPARQL",

O'REILLY, ISBN: 1449306594

▪ オープンデータ時代の標準Web API

SPARQL, ISBN: 978-4802090438

▪ SPARQL Cheat Sheet:

http://www.iro.umontreal.ca/~lapal

参照

関連したドキュメント

や都市計画公園などからなる住宅 市街地です。その他の最寄り駅と して、JR埼京線 北赤羽駅が約 500m、都営三田線 志村坂上駅

前項においては、最高裁平成17年6月9日決定の概要と意義を述べてき

本検討で距離 900m を取った位置関係は下図のようになり、2点を結ぶ両矢印線に垂直な破線の波面

本文書の目的は、 Allbirds の製品におけるカーボンフットプリントの計算方法、前提条件、デー タソース、および今後の改善点の概要を提供し、より詳細な情報を共有することです。

FSIS が実施する HACCP の検証には、基本的検証と HACCP 運用に関する検証から構 成されている。基本的検証では、危害分析などの

日本フォーマットには現在、トルコの一般的な検体方法である、咽頭ぬぐいと鼻ぬぐいの混合 Combined Throat And Nose

電子式の検知機を用い て、配管等から漏れるフ ロンを検知する方法。検 知機の精度によるが、他