11

DBpedia から映画に関するデータを取得する必要があります。

http://dbpedia-live.openlinksw.com/sparqlで次のように SPARQL クエリを使用します。

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT ?subject ?label ?released WHERE {
  ?subject rdf:type <http://dbpedia.org/ontology/Film>.
  ?subject rdfs:label ?label.
  ?subject <http://dbpedia.org/ontology/releaseDate> ?released.
  FILTER(xsd:date(?released) >= "2000-01-01"^^xsd:date).
} ORDER BY ?released
LIMIT 20

2000 年 1 月 1 日以降にリリースされた映画を取得しようとしました。しかし、エンジンは次のように答えます。

Virtuoso 22007 Error DT006: Cannot convert 2009-06-31 to datetime : 
Too many days (31, the month has only 30)

SPARQL query:
define sql:big-data-const 0 
#output-format:text/html
define sql:signal-void-variables 1 define input:default-graph-uri <http://dbpedia.org> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT ?subject ?label ?released WHERE {
  ?subject rdf:type <http://dbpedia.org/ontology/Film>.
  ?subject rdfs:label ?label.
  ?subject <http://dbpedia.org/ontology/releaseDate> ?released.
  FILTER(xsd:date(?released) >= "2000-01-01"^^xsd:date).
} ORDER BY ?released
LIMIT 20

私が理解できる限り、DBpedia のデータにはいくつかのエラーがあり、エンジンは設定した日付と比較するために文字列データを日付型に変換できません。そして、エンジンはクエリの実行を中断します。

問題は、エラーのあるデータをすべてスキップして、処理可能なすべてのデータを返すようにエンジンに指示する方法はありますか?

4

3 に答える 3

3

COALESCE関数を使用して、無効な日付のデフォルトの日付を定義できます。

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT ?subject ?label ?released ?released_fixed WHERE {
  ?subject rdf:type <http://dbpedia.org/ontology/Film>.
  ?subject rdfs:label ?label.
  ?subject <http://dbpedia.org/ontology/releaseDate> ?released.
  bind ( coalesce(xsd:datetime(?released), '1000-01-01') as ?released_fixed)
  FILTER(xsd:date(coalesce(xsd:datetime(?released), '1000-01-01')) >= "2000-01-01"^^xsd:date).
} ORDER BY ?released
LIMIT 20

このクエリは、DbPedia Live Endpoint で次の SPARQL 結果を提供します。

bind コンストラクトは、'1000-01-01' に設定され、変数?release_fixedに格納されている固定日付を表示するためだけのものです。バインドはクエリには必要なく、SELECT 句の?release_fixedと一緒に省略できます。

于 2013-10-03T21:19:56.373 に答える