合并在此示例中不起作用 [英] coalesce not working in this example
本文介绍了合并在此示例中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的最低数据:
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)
}
}
这是结果;
看看resultForMe,它没有任何值,为什么?这是我的问题,尽管defaultMatchedTemporalContext具有值.
Look at the resultForMe, it doesn't have any values, why? this is my question though the defaultMatchedTemporalContext has a value.
我给了您所需的最低数据,您可以根据需要将数据上传到SPARQL存储中,它只是rdf的4行
I gave you the so minimum data required, you can upload the data on your SPARQL store if you want, it is just 4 lines of rdf
推荐答案
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)
}
}
问题在于, values 子句位于绑定中的上述子句中,将它们放在同一子句中可以解决我的问题
The problem was that the values clause was in above clause than the bind, putting them in the same clause solves my problem
这篇关于合并在此示例中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文