SPARQLthon33/VirtuosoBadKnowhow
提供:TogoWiki
目次 |
バージョン
- stable版 (7.2.0.1) はよさそう
- その後のdevelopment版は、評判が良くなかった
- 追記:stable版 7.2.1 が出た(2015/6/24)
- これ以降あまり確認できていない
- v 7.2.0.1 から v 7.2.2.1 にしてみたが、逆に応答が遅くなった
- データを virtuoso にロードした直後だと VALUES で変なバグが出るが、virtuoso を再起動すると正常になる再現性のある現象を確認(v7.2.4)
VALUESのバグ
1つの変数しか値をbindできない(下の例だと、変数 ?direction が空のまま) (もとの例)
PREFIX dm: <http://learningsparql.com/ns/demo#>
SELECT * WHERE {
VALUES (?color ?direction) {
( dm:red "north" )
( dm:blue "west" )
}
}
ただし、複数変数でも、値が一組だけだと問題が起きない
PREFIX dm: <http://learningsparql.com/ns/demo#>
SELECT * WHERE {
VALUES (?color ?direction) {
( dm:red "north" )
}
}
あるいは、変数を5個以上にすると複数組でも問題が起きない。変数名、値ともダミーを入れる
PREFIX dm: <http://learningsparql.com/ns/demo#>
SELECT * WHERE {
VALUES (?color ?direction ?dummy1 ?dummy2 ?dummy3 ) {
( dm:red "north" "dummy value1" "dummy value2" "dummy value3")
( dm:blue "west" "dummy value1" "dummy value2" "dummy value3" )
}
}
- Virtuoso 7.0 ではこのバグはなかった?
- Virtuoso 7.1 でバグが入った?
- Virtuoso 7.2 で直った
- テスト環境:Virtuoso 7.2.0.1 http://sparql.nibb.ac.jp/sparql
- 関連:RDFを virtuoso に import 直後の状態で、VALUES で変数代入の挙動がおかしくなる現象(代入されない)(SPARQLthon66 より)
- 解決法:virtuoso 再起動で正常になる
BINDのバグ
SPARQLのWHERE内でトリプルパターンの順序を変えても、基本的には結果に影響しないはず。
しかし、BINDの記述位置を変えると、結果が返ってこなかったりエラーになるケースがある。
- OKケース
SELECT ?label2
WHERE
{
?s rdfs:label ?label .
BIND (REPLACE(?label, "hoge", "") AS ?label2)
}
- NGケース
SELECT ?label2
WHERE
{
BIND (REPLACE(?label, "hoge", "") AS ?label2)
?s rdfs:label ?label .
}
COUNTのバグ
SELECT (COUNT(DISTINCT *) AS ?count) が通らない
property path のバグ
一つのクエリの中で * や + を複数使うと、おかしな結果になることがある
- 一箇所でもおかしい例
- query: DEFINE sql:select-option "order" 行の有無で結果がかわる
- DEFILE 行ある方が正しい
- プロパティ・パス(rdfs:subClassOf アスタリスク)が悪さしてるもよう
- アスタリスクの前で括弧のプロパティ・パスを使っているので、アスタリスクが複数回に展開されるのかも
- subClassOf は片方にしか掛からないので、 .../(jpo:disease/rdfs:subClassOf*|jpo:diseaseClass) ?disease に書き直すとおかしくならない
- query: DEFINE sql:select-option "order" 行の有無で結果がかわる
## endpoint https://tools.jpostdb.org/sparql
DEFINE sql:select-option "order"
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX jpo: <http://rdf.jpostdb.org/ontology/jpost.owl#>
PREFIX obo: <http://purl.obolibrary.org/obo/>
PREFIX ncit: <http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#>
PREFIX sio: <http://semanticscience.org/resource/>
PREFIX : <http://rdf.jpostdb.org/entry/>
SELECT DISTINCT ?dataset ?project
WHERE {
VALUES ?organ { ncit:C54189 }
VALUES ?disease { obo:DOID_162 }
?dataset a jpo:Dataset ;
dct:identifier ?dataset_id ;
sio:SIO_000216 [ a jpo:NumOfLeadingProteins ;
sio:SIO_000300 ?protein_count ] ;
sio:SIO_000216 [ a jpo:NumOfSpectra ;
sio:SIO_000300 ?spectrum_count ] .
?project jpo:hasDataset ?dataset ;
dct:identifier ?project_id ;
dct:title ?project_title ;
dct:date ?project_date .
?dataset jpo:hasProfile/jpo:hasSample/jpo:organ ?organ .
?dataset jpo:hasProfile/jpo:hasSample/(jpo:disease|jpo:diseaseClass)/rdfs:subClassOf* ?disease .
}
ORDER BY ASC(?project_id) ASC(?dataset_id)
ORDER BY のバグ
ORDER BYすると、結果がおかしくなることがある
- 特に、リテラルを保持している変数についてORDER BYしたとき?
デフォルトで入っているグラフについて
デフォルトで、下記の5つのグラフが入っており、計5,819トリプルある。(調査環境:Virtuoso 7.2.0.1)
- http://localhost:8890/sparql
- ここに収まっている情報は、エンドポイントのURLにアクセスしたときに、service descriptionとして返される。
- http://localhost:8890/DAV/
- http://www.w3.org/2002/07/owl#
- OWL2ではない。OWL1?
- ルールとして登録されている(ルール名 http://www.w3.org/2002/07/owl#)
- このルールおよびグラフを消しても owl:sameAs や owl:SymmetricPropertyは効いた
- http://www.openlinksw.com/schemas/virtrdf#
- グラフを削除してみたが、再起動すると復活した
- http://www.w3.org/ns/ldp#
- 7.2で追加されていたグラフ
- グラフを削除してみたが、再起動すると復活した
- ルールとして登録されている(ルール名 ldp)
- ルールを削除してみたが、再起動するとルールが復活していた
- グラフの内容は、以下の3トリプルのみ
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix ldb: <http://www.w2.org/ns/ldp#> . ldb:DirectContainer rdfs:subClassOf ldb:Container . ldb:BasicContainer rdfs:subClassOf ldb:Container . ldb:IndirectContainer rdfs:subClassOf ldb:Container .
OPTIONAL + DISTINCT のバグ
- query: OPTIONAL で入れた変数を DISTINCT したとき、重複が取り除かれない(SPARQLthon66 より)
- 解決法:もう一度 SELECT で囲む => query
## endpoint http://tools.jpostdb.org/proxy/sparql
DEFINE sql:select-option "order"
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX jpo: <http://rdf.jpostdb.org/ontology/jpost.owl#>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX faldo: <http://biohackathon.org/resource/faldo#>
PREFIX : <http://rdf.jpostdb.org/entry/>
SELECT DISTINCT ?modification ?position
WHERE {
:DS201_1 jpo:hasProtein/jpo:hasPeptideEvidence/jpo:hasPeptide/jpo:hasPsm ?psm .
?psm dct:identifier ?psm_id .
?psm jpo:hasModification ?mod_blank .
?mod_blank a ?mod .
OPTIONAL { ?mod_blank faldo:location/faldo:position ?position . }
FILTER (?mod != jpo:Modification)
?mod rdfs:label ?modification .
}
ORDER BY ?modification
OFFSET 0
LIMIT 100
## endpoint http://tools.jpostdb.org/proxy/sparql
DEFINE sql:select-option "order"
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX jpo: <http://rdf.jpostdb.org/ontology/jpost.owl#>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX faldo: <http://biohackathon.org/resource/faldo#>
PREFIX : <http://rdf.jpostdb.org/entry/>
SELECT DISTINCT ?modification ?position
WHERE {
{
SELECT DISTINCT ?modification ?position
WHERE {
:DS201_1 jpo:hasProtein/jpo:hasPeptideEvidence/jpo:hasPeptide/jpo:hasPsm ?psm .
?psm dct:identifier ?psm_id .
?psm jpo:hasModification ?mod_blank .
?mod_blank a ?mod .
OPTIONAL { ?mod_blank faldo:location/faldo:position ?position . }
FILTER (?mod != jpo:Modification)
?mod rdfs:label ?modification .
}
}
}
ORDER BY ?modification
OFFSET 0
LIMIT 100
他に気付いたこと
- virtuoso.dbにパスワードも保存されているようだ
- isqlの方がカウントが速い
- dbディレクトリに以下のファイルが生成されていた
- virtuoso.cpt
- checkpoint_in_progress
- virtuoso-temp.db や virtuoso.pxa の役割は何?
- なぜ > を >= にしたら IF の3段入れ子が動かない?
- HAVINGのうれしさは何なのか
グラフ名
- グラフ名の指定で、どの程度パフォーマンスが改善するのか?
- Virtuoso6では、グラフのリストを出すと、大文字が小文字に変わって表示される?
- グラフ名の最後が/でないとき、prefixを使った省略ができる
SPARQL Service Description [1]
- curl http://mbgd.genome.ad.jp:7051/sparql で返ってきた結果の末尾
<div xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:sd="http://www.w3.org/ns/sparql-service-description#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
style="display:none">
<div class="description" about="" typeof="sd:Service">
<div rel="sd:endpoint" resource="http://mbgd.genome.ad.jp:7051/sparql"/>
<div rel="sd:feature"
resource="http://www.w3.org/ns/sparql-service-description#UnionDefaultGraph"/>
<div rel="sd:feature"
resource="http://www.w3.org/ns/sparql-service-description#DereferencesURIs"/>
<div rel="sd:resultFormat" resource="http://www.w3.org/ns/formats/RDF_XML"/>
<div rel="sd:resultFormat" resource="http://www.w3.org/ns/formats/Turtle"/>
<div rel="sd:resultFormat"
resource="http://www.w3.org/ns/formats/SPARQL_Results_CSV"/>
<div rel="sd:resultFormat" resource="http://www.w3.org/ns/formats/N-Triples"/>
<div rel="sd:resultFormat" resource="http://www.w3.org/ns/formats/N3"/>
<div rel="sd:resultFormat"
resource="http://www.w3.org/ns/formats/SPARQL_Results_JSON"/>
<div rel="sd:resultFormat" resource="http://www.w3.org/ns/formats/RDFa"/>
<div rel="sd:resultFormat"
resource="http://www.w3.org/ns/formats/SPARQL_Results_XML"/>
<div rel="sd:supportedLanguage"
resource="http://www.w3.org/ns/sparql-service-description#SPARQL10Query"/>
<div rel="sd:url" resource="http://mbgd.genome.ad.jp:7051/sparql"/>
</div>
</div>
- HTMLの一部として返すんじゃなくて、RDFのみを返すには、どうすればいいのかな。(EBI RDFみたいに)
- 変数の数が多いと Stack overflow する