2017-05-24 15 views
0

私はセマンティックウェブとsparqlの新機能です。私はデータを管理するためにSmartLogicを使用する内部オントロジーを持っています。Sparql - 条件付き出力

私はいくつかの簡単な質問を書いています。


PREFIX skos: <http://www.w3.org/2004/02/skos/core#> # Simple Knowledge Organization System - https://www.w3.org/2004/02/skos/ 
PREFIX skosxl: <http://www.w3.org/2008/05/skos-xl#> 
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX rdfs: <https://www.w3.org/TR/rdf-schema/> 
prefix owl: <http://www.w3.org/2002/07/owl#> 
prefix ap: <http://cv.ap.org/ns> 

SELECT DISTINCT 
      ?subjectPrefLabel ?p ?o ?oL 

     WHERE { 

      { 
      ?subject skosxl:prefLabel ?subjectLabel . 
      ?subjectLabel skosxl:literalForm ?subjectPrefLabel . 
      ?subject ?p ?o . 
      OPTIONAL {?o skos:prefLabel ?oL} 

      } 

      FILTER regex(?subjectPrefLabel, "Trump", 'i') 


     } order by ?subjectPrefLabel 

のように見えるこのクエリ結果を返します:

enter image description here

それは場合にのみ存在し、?oフィールドを交換するように、私は、?o and ?oLフィールドをマージしようとしています有効な?oLフィールド

私はまだそれを把握することができませんでした。何か提案があれば教えてください。

答えて

1

クエリをテストするためのデータがない困難なビットが、SPARQL 1.1にあなたがBIND(IF(condition,then,else) as ?result)を使用することができます。

PREFIX skosxl: <http://www.w3.org/2008/05/skos-xl#> 
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX owl: <http://www.w3.org/2002/07/owl#> 
PREFIX skos: <http://www.w3.org/2004/02/skos/core#> 
PREFIX rdfs: <https://www.w3.org/TR/rdf-schema/> 
PREFIX ap: <http://cv.ap.org/ns> 

SELECT DISTINCT ?subjectPrefLabel ?p ?o 
WHERE 
    { ?subject skosxl:prefLabel ?subjectLabel . 
    ?subjectLabel 
       skosxl:literalForm ?subjectPrefLabel . 
    ?subject ?p     ?o_tmp 
    OPTIONAL 
     { ?o_tmp skos:prefLabel ?oL } 
    BIND(if(bound(?oL), ?oL, ?o_tmp) AS ?o) 
    FILTER regex(?subjectPrefLabel, "Trump", "i") 
    } 
ORDER BY ?subjectPrefLabel 
+0

が、これは動作し、私に新しい重要なメカニズムを教え、ありがとう:) – Busturdust

関連する問題