複雑な状況に対処しなければならない場合、私の提案は次のとおりです。まず探索的テストを試してください。例で見てみましょう:
ソース データ ファイルが次のとおり./table/table.csv
であるとします。
main index;web site;title, to translate
1;"ciao.ronda.com";"this is the first"
2;"miao.ronda.it";"this is the second"
3;"bao.ronda.uk";"this is the third"
step1: 探索的テスト クエリqstar.sparql
:
SELECT *
FROM <file:table.csv#delimiter=%3B;>
WHERE {}
LIMIT 100
ランチャーの例:
#!/bin/bash -
table=./data/table.csv
query=./data/qstar.sparql
./bin/tarql --test --delimiter \; --header-row --verbose ${query} ${table}
結果:
$ ./launcher0.sh
--------------------------------------------------------
| main_index | web_site | title,_to_translate |
========================================================
| "1" | "ciao.ronda.com" | "this is the first" |
| "2" | "miao.ronda.it" | "this is the second" |
| "3" | "bao.ronda.uk" | "this is the third" |
--------------------------------------------------------
これで、これらのオプションで計算された 3 番目の列変数名が次のようになることがわかりました。title,_to_translate
step2: BIND ステートメントの構文が、procedure 変数名でサポートされているかどうかをテストします (title,_to_translate
この例では)。
ここではBIND
、問題を理解するためにサンプル ベースのクエリが必要です。これが、次の名前の out フィールドを使用しようとするクエリであるとします。?title,_to_translate
SELECT ?homepage ?uri ?title_with_language_tag
WHERE {
BIND (?web_site AS ?homepage)
BIND (URI(CONCAT('http://website.com/ns#', ?main_index)) AS ?uri)
BIND (STRLANG(?title,_to_translate, 'en') AS ?title_with_language_tag)
}
結果:
$ ./launcher0.sh
com.hp.hpl.jena.query.QueryParseException: Lexical error at line 5, column 27. Encountered: "t" (116), after : "_"
at org.deri.tarql.TarqlParser.parse(TarqlParser.java:113)
つまり、このクエリには、サポートされていない字句エラーが含まれています。ena.query.QueryParser
このような場合、言語との戦いを続けるよりも、少し回避策を採用することを好みます
step3: 少し回避策のある解決策
-H --no-header-row CSV file has no header row; use variable names ?a, ?b, ...
オプションを活用して、簡単な解決策を楽しみましょう。必要なことは、ソース データ ファイルのコンテンツから最初の行を削除することだけです (これは、プロセスにパイプライン処理するか、好みの方法で行うことができる簡単な作業です) ./data/table0-noheader.csv
。
同じクエリがパーサーにとってより簡単になりました。
./data/query0.sparql
:
SELECT ?homepage ?uri ?title_with_language_tag
WHERE {
BIND (?a AS ?homepage)
BIND (URI(CONCAT('http://website.com/ns#', ?b)) AS ?uri)
BIND (STRLANG(?c, 'en') AS ?title_with_language_tag)
}
launcher-noheader.sh:
!/bin/bash -
table=./data/table0-noheader.csv
query=./data/query0.sparql
./bin/tarql --test --no-header-row --delimiter \; --header-row --verbose ${query} ${table}
結果:
$ ./launcher-noheader.sh
-------------------------------------------------------------------------------
| homepage | uri | title_with_language_tag |
===============================================================================
| "1" | <http://website.com/ns#ciao.ronda.com> | "this is the first"@en |
| "2" | <http://website.com/ns#miao.ronda.it> | "this is the second"@en |
| "3" | <http://website.com/ns#bao.ronda.uk> | "this is the third"@en |
-------------------------------------------------------------------------------
ノート
リファレンス ドキュメント:
Header row, delimiters, quotes and character encoding in CSV/TSV filesには、オプションを表現するためのすべての可能な方法と組み合わせが記載されています: は、読む価値があります。
別の有用なリファレンスは次のとおり
です。SPARQL 1.1 クエリ言語での変数の可能な名前