0
http://www.example.com/teach.rdfs/John   http://www.example.com/teach.rdfs#position "Full Professor"        

http://www.example.com/teach.rdfs/John   http://www.example.com/teach.rdfs#course"Math"

http://www.example.com/teach.rdfs/John   http://www.example.com/teach.rdfs#student"Undergraduate"

http://www.example.com/teach.rdfs/Arthur http://www.example.com/teach.rdfs#position "Assistant Professor"

http://www.example.com/teach.rdfs/Arthur http://www.example.com/teach.rdfs#course"Web Engineering"

http://www.example.com/teach.rdfs/Arthur http://www.example.com/teach.rdfs#student"Graduate"

これらがトリプルで、大学院を教える助教授を探したい場合

 Lecturer       Position

 Arthur         Assistant Professor 

SPARQLを使用して上記の日付を抽出する方法

4

1 に答える 1

4

あなたのデータは、私が知っている合法的な RDF シリアライゼーションにはありませんが、N3 シリアライゼーションに入れるのはかなり簡単です。同じドキュメントでhttp://.../teach.rdfs#との両方が接頭辞として使用されているのは、かなり珍しいことです。http://.../teach.rdfs/どちらか一方が表示されるのが一般的ですが、両方が表示されるわけではありません。ただし、違法ではないので、私たちはそれを扱うことができます。N3 形式のファイルとしてのデータは次のdata.n3とおりです。

@prefix teach1: <http://www.example.com/teach.rdfs/> .
@prefix teach2: <http://www.example.com/teach.rdfs#> .

teach1:John teach2:position "Full Professor" .
teach1:John teach2:course "Math" .
teach1:John teach2:student "Undergraduate" .
teach1:Arthur teach2:position "Assistant Professor" .
teach1:Arthur teach2:course "Web Engineering" .
teach1:Arthur teach2:student "Graduate" .

クエリも非常に単純です。これは、というファイルとして次のquery.sparqlとおりです。

PREFIX teach1: <http://www.example.com/teach.rdfs/>
PREFIX teach2: <http://www.example.com/teach.rdfs#>

SELECT ?lecturer ?position WHERE {
  VALUES ?position { "Assistant Professor" }
  ?lecturer teach2:position ?position ;
            teach2:student "Graduate" .
}

このクエリで少し変わっているのは、VALUES ?position { "Assistant Professor" }. このフォームを使用した理由VALUESは、希望する結果に"Assistant Professor"出力に含まれていたからです。その部分を除外するとVALUES ...、パターンを次のように書き換えることができます。

  ?lecturer teach2:position "Assistant Professor" ;
            teach2:student "Graduate" .

それでも同じ?lecturers が見つかりますが、 にバインドされた変数はありません"Assistant Professor"。データとクエリが手元にあるので、Jena の ARQ コマンド ライン ツールを使用して、データに対してクエリを実行できます。

$ arq --query query.sparql --data data.n3 
-----------------------------------------
| lecturer      | position              |
=========================================
| teach1:Arthur | "Assistant Professor" |
-----------------------------------------
于 2013-06-20T12:08:17.743 に答える