第 3 章 Linked Data
3.6 SPARQL
43
44
3.6.2 述語の確認
Linked Data
のデータ構造を理解することで,SPARQL
により所望するリソースを得られるようになる.図
30
は,Linked Data
で使用されている述語の一覧を取得するためのク エリであり,図31
のように述語の使用回数が多い順で一覧を取得できる.“group by ?predicate
”により述語をグループ化でき,select
以降で“?predicate count(?predicate)
as ?total
”を指定することで,述語とその使用回数を取得できる.“as ?total
”は,処理結果を
?total
に格納することを意味しており,処理結果を変数として管理することで処理結果を別の処理に用いることができる.図
30
のクエリでは,?total
に格納された変数値に基づいて
order by
により降順に並び替えている.なお,昇順に並び替える場合は“asc(?total) ”
と記述する.
図
30
述語の一覧を取得predicate total
http://www.w3.org/2000/01/rdf-schema#label 1204636 http://purl.org/dc/terms/subject 985247 http://www.w3.org/1999/02/22-rdf-syntax-ns#type 910670 http://i-scover.ieice.org/terms/iscover#authorInfo 805829 http://www.w3.org/1999/02/22-rdf-syntax-ns#rest 805829 http://i-scover.ieice.org/terms/iscover#author 805829 http://www.w3.org/1999/02/22-rdf-syntax-ns#first 805829 http://i-scover.ieice.org/terms/iscover#affiliation 778985 http://purl.org/dc/terms/bibliographicCitation 551212 http://i-scover.ieice.org/terms/iscover#publicationType 523440
図
31 I-Scover
のLinked Data
で使用されている述語の例(
2017
年12
月5
日時点)select
?predicate
count(?predicate) as ?total where {
?subject
?predicate ?object.
} group by ?predicate
order by desc(?total)
45
3.6.3 クラスの確認
Linked Data
は,所望するリソースを正確に指定して得られるように,クラスによってリソースが分類されていることが一般的である.つまり,
SPARQL
により所望するリソー スを得るために,Linked Data
で定義されているクラスを理解する必要がある.図32
は,Linked Data
で使用されているクラスの一覧を取得するためのクエリであり,図33
のようにクラスの使用回数が多い順で一覧を取得できる.クラスの使用回数は,各クラスにおける 主語の件数を表しており,同図から
327,576
語の用語(Term)
が存在していることが分かる.また,
279,106
人の著者(Person)
が存在し,さらに243,133
件の文献(Article)
が存在して いることが分かる.図31
で1,204,636
件のrdfs:label
が定義されているが,クラスを指定 することでrdfs:label
のリソースを絞り込むことが可能である.図
32
クラスの一覧を取得class total
http://i-scover.ieice.org/terms/iscover#Term 327576 http://i-scover.ieice.org/terms/iscover#Person 279106 http://i-scover.ieice.org/terms/iscover#Article 243133 http://i-scover.ieice.org/terms/iscover#Organization 30651 http://i-scover.ieice.org/terms/iscover#Publication 18587 http://i-scover.ieice.org/terms/iscover#Event 11577 http://i-scover.ieice.org/terms/iscover#Multimedia 36 http://i-scover.ieice.org/terms/iscover#Online-Service 4 図
33 I-Scover
のLinked Data
で使用されているクラスの一覧(
2017
年12
月5
日時点)select ?class
count(?class) as ?total where {
?subject a ?class.
} group by ?class
order by desc(?total)
46
3.6.4 クラス内で使用されている述語の確認
Linked Data
のリソースを正確に取り扱うためには,クラスの理解とともに,そのクラス内で使用されている述語を理解する必要がある.図
34
は,人物(iscover:Person)
クラス の一覧を取得するためのクエリであり,図33
のように該当クラスにおける述語の使用回数 が多い順で一覧を取得できる.図34
における1
行目は,名前空間の略記を定義しており,略記を定義することで“
iscover:Person
”のように記述できる.“iscover:Person
”は,図33
に示した“http://i-scover.ieice.org/terms/iscover#Person
”と同一の存在である.SPARQL
は,1
つの主語に対して複数の述語と目的語の対を記述でき,検索対象を絞り込むことが可 能である.図
34 iscover:Person
のクラス内で使用されている述語の一覧を取得predicate total
http://www.w3.org/2000/01/rdf-schema#label 381358 http://xmlns.com/foaf/0.1/name 381358 http://www.w3.org/1999/02/22-rdf-syntax-ns#type 279106 http://www.w3.org/2006/vcard/ns#org 265777
図
35 iscover:Person
のクラス内で使用されている述語の一覧(
2017
年12
月5
日時点)prefix iscover:<http://i-scover.ieice.org/terms/iscover#>
select
?predicate
count(?predicate) as ?total where {
?subject
?predicate ?object;
a iscover:Person.
} group by ?predicate
order by desc(?total)
47
3.6.5 複数の triple を組み合わせた分析
Linked Data
におけるクラスは,MySQL
やOracle
などの一般的なリレーショナルデータベース
(RDB)
におけるテーブルと同様の役割を担っており,リレーショナルなリソースの取り扱いが可能である.図
36
は,学会誌や論文誌などの各出版物における文献数を取得 するクエリであり,図37
のような結果を得られる.“values
”は,変数に値を逐次的に代入 する関数であり,ここでは出版物の名称を記述している.出版物(iscover:Publication)
のタ イ ト ル(?title)
に 出 版 物 の 名 称(?publication)
が 部 分 的 に 一 致 す る 出 版 物 のURI (?publicationURI)
と,文献(iscover:Aritcle)
の出版物元を対応させて分析結果を得ている.図
36 triple
の組み合わせによるデータ分析publication numberOfArticles
"総合大会"@ja 38190
"技術研究報告"@ja 108353
"論文誌"@ja 39056
"ソサイエティ大会"@ja 22043
"FIT"@ja 22906
"学会誌"@ja 2479
図
37
各出版物における文献数(