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

PowerPoint プレゼンテーション

N/A
N/A
Protected

Academic year: 2021

シェア "PowerPoint プレゼンテーション"

Copied!
56
0
0

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

全文

(1)
(2)
(3)

SPARQLとは?

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

RDBMSにおけるSQLに相当)

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

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

(日本語訳)

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

▪ ver.1.0は2008年1月にW3C勧告

▪ ver.1.1は2013年3月にW3C勧告

(4)

RDFデータストア

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

るアプリケーション

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

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

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

▪ 本講義ではVirtuosoを利用

http://virtuoso.openlinksw.com

– フリーソフトウェアのため各自ダウンロードしてインストールすることも

可能

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

行可能

http://j-its.com:8890/sparql/

– 2014年7月末まではアクセス可能

(5)

Turtle

▪ RDFフォーマットの一種

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

可能

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

▪ 以下のサンプルRDF文書はTurtleで記述

(6)

SPARQL Query Syntax

Select ?x ?y (値を返す変数)

(From データセット)

Where { 検索条件}

(出力書式)

Construct (テンプレート内の変数を具象化し

RDF を返す)

Describe(条件部を含むRDFを返す)

Ask(RDFグラフの有無 true/false)

(7)

練習問題

▪ SPARQL

– サンプルRDF文書

• ex002.ttl, ex012.ttl, ex054.ttl, ex069.ttl, ex100.ttl, ex104.ttl, ex115.ttl, ex145.ttl

– 基本的なクエリ

• ex003.rq, ex008.rq, ex010.rq, ex013.rq, ex070.rq

– FILTER(文字列値,数値などの制限)

• ex021.rq, ex067.rq, ex105.rq, ex109.rq, ex112.rq

– OPTIONAL(オプション) • ex057.rq, ex061.rq – DISTINCT(重複を除去) • ex094.rq – UNION(代替グラフパターンマッチ) • ex103.rq – LIMIT(表示結果数の上限を指定) • ex116.rq – ORDER BY(ソート)

• ex146.rq, ex148.rq, ex149.rq, ex151.rq

– GROUP BY, MAX, AVG, SUM, COUNT(グループ化,最大,平均,合計,個数を数える)

• ex153.rq, ex156.rq, ex160.rq, ex162.rq

– リモートのSPARQLエンドポイントへのクエリ

• ex170.rq, ex172.rq

▪ 演習問題1, 演習問題2 ▪ レポート演習問題

(8)

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]" .

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

(9)

SPARQLクエリ: ex003.rq

# filename: ex003.rq

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

SELECT

?craigEmail

WHERE

{ ab:craig ab:email

?craigEmail

. }

Graph IRI: http://j-its.com:8890/ex002

(10)

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]"

.

(11)

SPARQLクエリ: ex008.rq

# filename: ex008.rq

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

SELECT

?person

WHERE

{

?person

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

Graph IRI: http://j-its.com:8890/ex002

(12)

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]" .

(13)

SPARQLクエリ: ex010.rq

# filename: ex010.rq

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

SELECT

?propertyName ?propertyValue

WHERE

{ ab:cindy

?propertyName ?propertyValue

. }

Graph IRI: http://j-its.com:8890/ex002

(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)

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]" .

(16)

SPARQLクエリ: ex013.rq

# filename: ex013.rq

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

SELECT

?craigEmail

WHERE

{

?person

ab:firstName "Craig" .

?person

ab:email

?craigEmail

.

}

Graph IRI: http://j-its.com:8890/ex012

(17)

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]" .

(18)

SPARQLクエリ: ex021.rq

# filename: ex021.rq

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

SELECT

*

WHERE

{

?s ?p ?o .

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

}

Graph IRI: http://j-its.com:8890/ex012

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

(19)

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]" .

(20)

演習問題1

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

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

SPARQLクエリを作成せよ

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

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

示する

SPARQLクエリを作成せよ

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

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

SPARQLクエリを作成せよ

上記

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

http://j-its.com:8890/sparql)上で実行し,結果

を確認せよ

(21)

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]" .

(22)

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://j-its.com:8890/ex054

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

ab:workTel ?workTel .

(23)

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]" .

(24)

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://j-its.com:8890/ex054

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

(25)

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]" .

(26)

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://j-its.com:8890/ex054

(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]" .

(28)

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 .

(29)

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://j-its.com:8890/ex069

(30)

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://j-its.com:8890/ex069

SELECT ?first ?last WHERE { ?s ab:takingCourse ?class ; ab:firstName ?first ; ab:lastName ?last . } 講義概要

(31)

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" .

(32)

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://j-its.com:8890/ex100

(33)

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> .

講義概要

(34)

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://j-its.com:8890/ex104

(35)

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> .

(36)

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://j-its.com:8890/ex104

(37)

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> .

(38)

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)) . }

Graph IRI: http://j-its.com:8890/ex104

(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)

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" .

(41)

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://j-its.com:8890/ex115

(42)

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 . 講義概要

(43)

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://j-its.com:8890/ex145

(44)

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://j-its.com:8890/ex145

(45)

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://j-its.com:8890/ex145

(46)

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://j-its.com:8890/ex145

(47)

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://j-its.com:8890/ex145

(48)

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://j-its.com:8890/ex145

(49)

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://j-its.com:8890/ex145

(50)

SPARQLクエリ: ex162.rq

# filename: ex162.rq

SELECT ?p

(COUNT(?p) AS ?pTotal)

WHERE

{ ?s ?p ?o . }

GROUP BY ?p

Graph IRI: http://j-its.com:8890/ex145

(51)

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#> PREFIX gp: <http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/people/> SELECT ?p ?o WHERE { SERVICE <http://wifo5-04.informatik.uni-mannheim.de/gutendata/sparql> { gp:Hocking_Joseph ?p ?o . } }

Graph IRI: 空にする

講義概要

(52)

SPARQLクエリ: ex172.rq

# filename: ex172.rq

PREFIX cat: <http://dbpedia.org/resource/Category:> PREFIX foaf: <http://xmlns.com/foaf/0.1/>

PREFIX gp: <http://wifo5-04.informatik.uni-mannheim.de/gutendata/resource/people/> PREFIX owl: <http://www.w3.org/2002/07/owl#>

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

SELECT ?dbpProperty ?dbpValue ?gutenProperty ?gutenValue WHERE

{

SERVICE <http://DBpedia.org/sparql> {

<http://dbpedia.org/resource/Joseph_Hocking> ?dbpProperty ?dbpValue . }

SERVICE <http://wifo5-04.informatik.uni-mannheim.de/gutendata/sparql> {

gp:Hocking_Joseph ?gutenProperty ?gutenValue . }

}

Graph IRI: 空にする

(53)

演習問題2

▪ 日本語Wikipediaオントロジー(JWO)のSPARQLエンドポイントを利用して,以 下のクエリを作成せよ – 検索:http://www.wikipediaontology.org/search.html – SPARQLエンドポイント:http://www.wikipediaontology.org/query/ 1. 日本映画クラスのインスタンスについて,rdfs:labelプロパティ値を昇順でソー トして,10件表示するクエリを作成せよ – LIMITはフォーム上から入力すること – JWOのクラス,プロパティ,インスタンスの名前空間は以下を利用 • PREFIX jwo-class:<http://www.wikipediaontology.org/class/> • PREFIX jwo-prop:<http://www.wikipediaontology.org/property/> • PREFIX jwo-instance:<http://www.wikipediaontology.org/instance/> 2. 夏目漱石インスタンスの代表作を昇順でソートして表示するクエリを作成せよ 3. 自動車を会社名に含むインスタンスについて,会社名,代表者名,従業員数を, 会社名を昇順にソートして表示するクエリを作成せよ – 代表者と従業員数はオプションとする

– 会社のインスタンスは,「?company jwo:hyper ?jwo-class:会社 .」により取得 – PREFIX jwo:<http://www.wikipediaontology.org/vocabulary#>

(54)

レポート演習問題

1. 日本語Wikipediaオントロジー(JWO)のSPARQLエンドポイントを利用

して,興味のある分野について

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

どることで必要な情報が得られると良い)

– 検索:http://www.wikipediaontology.org/search.html – SPARQLエンドポイント:http://www.wikipediaontology.org/query/

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

いて

1つクエリを作成せよ(数値のソート,平均,最大,合計などを含む

クエリを作成できると良い)

– SPARQLエンドポイント:http://dbpedia.org/sparql – 参考クエリ:http://wiki.dbpedia.org/OnlineAccess#h28-6

上記,クエリと実行結果のスクリーンショット(多い場合は一部)をWord

等の文書ファイルに貼り付けて,授業支援システムから提出せよ

提出締切:7月25日(金) 16:50

(55)

DBpediaのクエリのサンプル

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

select ?book_name ?author_name ?date ?isbn ?influenced_person_name where {

?book rdf:type dbpedia-owl:Book . ?book rdfs:label ?book_name .

?book dbpedia-prop:author ?author . ?author rdfs:label ?author_name .

?author dbpedia-owl:influenced ?influenced_person . ?influenced_person rdfs:label ?influenced_person_name . ?book dbpedia-prop:releaseDate ?date .

?book dbpedia-prop:isbn ?isbn . FILTER (lang(?book_name) = "en") FILTER (lang(?author_name) = "en")

FILTER (lang(?influenced_person_name) = "en") FILTER (isNumeric(?date)) } order by desc(?date) Bookクラスのインスタンスについて,書籍名,著者名,出版年,ISBN,著者が影響を 受けた人物の一覧を出版年の降順でソートして表示するクエリ. 出版年は数値のみ,書籍名,著者名,影響を受けた人物は英語文字列のみを表示.

(56)

参考文献

▪ Bob DuCharme: "Learning SPARQL",

O'REILLY, ISBN: 1449306594

▪ SPARQL Cheat Sheet:

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

参照

関連したドキュメント

転送条件 を変更せ ず転送を

地域の名称 文章形式の表現 卓越もしくは変化前 断続現象 変化後 地域 風向 風向(数値) 風速 風力 起時

(注)本報告書に掲載している数値は端数を四捨五入しているため、表中の数値の合計が表に示されている合計

ヒット数が 10 以上の場合は、ヒットした中からシステムがランダムに 10 問抽出して 出題します。8.

変更条文 変更概要 関連する法令/上流文書 等 説明事項抽出結果

(注)本報告書に掲載している数値は端数を四捨五入しているため、表中の数値の合計が表に示されている合計

内 容 受講対象者 受講者数 研修月日 アンケートに基づく成果の検証

内 容 受講対象者 受講者数 研修月日 アンケートに基づく成果の検証.