这是我的最低数据:
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有一个值。
我给你提供了所需的最低数据,你可以根据需要在SPARQL商店上传数据,它只是4行的rdf
答案 0 :(得分: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)
}
}
问题是 values 子句在上面的子句中而不是bind,把它们放在同一个子句中解决了我的问题