2016-08-15 48 views
0

這是我最小的數據:合併本例中沒有工作

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
    PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 
    PREFIX rs: <http://www.SemanticRecommender.com/rs#> 
    PREFIX mo: <http://www.musicontology.com/mo#> 
    PREFIX : <http://www.musicsemanticontology.com/mso#> 

    mo:5th_symphony_for_beethoven a mo:GermanSymphony . 
    :symphonyFestival2016 a rs:TemporalContext ; rs:appliedOnItems mo:GermanSymphony ; rs:canBeRecommendedFrom "2016-07-01T00:00:00-00:00"^^xsd:dateTime ; rs:canBeRecommendedUntil "2016-09-01T00:00:00-00:00"^^xsd:dateTime . 

這是我的查詢:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 
PREFIX rs: <http://www.SemanticRecommender.com/rs#> 
PREFIX mo: <http://www.musicontology.com/mo#> 
PREFIX : <http://www.musicsemanticontology.com/mso#> 

    SELECT ?item ?resultForMe ?matchedWeight ?defaultMatchedTemporalContext 
    WHERE 
     { 
    values ?item {mo:5th_symphony_for_beethoven} 
      VALUES (?defaultMatchedTemporalContext ?defaultNotMatchedTemporalContext ?defaultNoTemporalContext) {(2 0.5 1)} 
      ?temporalContext 
         rdf:type   rs:TemporalContext ; rs:appliedOnItems ?itemClass . 
         OPTIONAl {  ?item  rdf:type   ?itemClass 
      OPTIONAL { ?temporalContext rs:canBeRecommendedFrom ?fromLimit } 
      OPTIONAL { ?temporalContext rs:canBeRecommendedUntil ?untilLimit } 
      OPTIONAL { ?temporalContext rs:hasWeightIfContextMatched ?matchedWeight } 
      OPTIONAL { ?temporalContext rs:hasWeightIfContextDoesNotMatch ?unmatchedWeight } 
    BIND(if(((?fromLimit <= now()) && (now() <= ?untilLimit)) , coalesce (?matchedWeight, ?defaultMatchedTemporalContext),2) as ?resultForMe) 
    } 
} 

這是結果;

enter image description here

看那resultForMe,它沒有任何價值,爲什麼呢?這是我的問題雖然defaultMatchedTemporalContext有一個值。

我給你需要的,你可以上傳數據上你的SPARQL商店,如果你想要的,它僅僅是4 RDF的線

+0

問題將是1)你的'IF'表達式是否工作 - >看起來對我和2)首先評估什麼,'VALUES'或'BIND'。 – AKSW

+0

順便說一句,爲了簡單起見,我會刪除所有可選的東西 – AKSW

+0

@AKSW感謝您的評論1)是的IF是真實的,如果你想確定,用任何值替換合併,例如3,你會得到3.2)值在綁定之前,所以應該先評估它。 (至少到我的新手知識) –

回答

1
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 
PREFIX rs: <http://www.SemanticRecommender.com/rs#> 
PREFIX mo: <http://www.musicontology.com/mo#> 
PREFIX : <http://www.musicsemanticontology.com/mso#> 

    SELECT ?item ?resultForMe ?matchedWeight ?defaultMatchedTemporalContext 
    WHERE 

{ 
    VALUES ?item {mo:5th_symphony_for_beethoven} 
    VALUES ?defaultNoTemporalContext { 1 } 
    VALUES ?defaultMatchedTemporalContext { 2 } 
    VALUES ?defaultNotMatchedTemporalContext { 0.5 } 
    ?temporalContext 
         rdf:type   rs:TemporalContext ; rs:appliedOnItems ?itemClass . 
         OPTIONAl {  ?item  rdf:type   ?itemClass. 
VALUES ?defaultMatchedTemporalContext { 2 } 

      OPTIONAL { ?temporalContext rs:canBeRecommendedFrom ?fromLimit } 
      OPTIONAL { ?temporalContext rs:canBeRecommendedUntil ?untilLimit } 
      OPTIONAL { ?temporalContext rs:hasWeightIfContextMatched ?matchedWeight } 
      OPTIONAL { ?temporalContext rs:hasWeightIfContextDoesNotMatch ?unmatchedWeight } 
    BIND(if(((?fromLimit <= now()) && (now() <= ?untilLimit)) , coalesce (?matchedWeight, ?defaultMatchedTemporalContext) ,2) as ?resultForMe) 
    } 
} 

的問題是,條款是如此最小數據在上面的子句比綁定,把他們在同一個條款解決我的問題

+0

看到我的答案在下面...我不認爲你想擁有可選的嵌套,對吧? – AKSW

+0

@AKSW的確我想這樣做。我確實有一個複雜的塞納里奧,我已經向你展示了一點。 +1的幫助,我感謝它 –

+0

好吧,我不知道有更多的東西綁定到'rdf:type'三重模式。然後我可以刪除我的答案。所以問題在於VALUES子句的範圍 – AKSW