我有一个SPARQL查询,它返回附表中显示的三元组。是否有可能根据“位置”值将“new_arg_val”的值分配给变量?arg1和?arg2?该位置来自rdf:Seq,它应该与rdf的任意长度一起工作:Seq。
修改 所以我正在研究一种方法来处理计算属性的推理,即。从其他属性的值派生的属性。我使用的是seas evaluation ontology,我的数据结构如下:
<resourceURI> seas:fluidTemperatureDiffeence <propertyURI> .
<propertyURI> seas:evaluation <evaluationURI> .
<evaluationURI> seas:evaluatedValue "33 Cel"^^cdt:ucum ;
prov:wasGeneratedAtTime "2017-06-13T21:51:26.706+02:00"^^xsd:dateTime ;
seas:calculation "abs(?arg1-?arg2)"^^xsd:string ;
prov:wasDerivedFrom _:c0 .
_:c0 a rdf:Seq ;
rdf:_1 <evaluationURIa> ;
rdf:_2 <evaluationURIb> .
属性可以具有多个评估,因为属性可以随时间变化。因此我也有几个计算。到目前为止,我的查询看起来像这样:
SELECT *
WHERE
{ #Get the time of the latest calculation
{ SELECT ?calculatedProperty (MAX(?_tc) AS ?tc)
WHERE
{ GRAPH ?g
{ ?resource seas:fluidTemperatureDifference/seas:evaluation _:b0 .
_:b0 ^seas:evaluation ?calculatedProperty .
_:b0 prov:wasGeneratedAtTime ?_tc
}
}
GROUP BY ?calculatedProperty
}
#Get calculation data
GRAPH ?gi
{ ?calculatedProperty
seas:evaluation _:b1 .
_:b1 prov:wasGeneratedAtTime ?tc ;
seas:calculation ?calc ;
seas:evaluatedValue ?old_res .
_:b1 (prov:wasDerivedFrom)+ _:b2 .
_:b2 ?position ?old_arg
}
#Get the time of the latest input values
{ SELECT ?old_arg (MAX(?_t) AS ?t)
WHERE
{ GRAPH ?g
{ ?old_arg ^seas:evaluation/seas:evaluation ?arg .
?arg prov:wasGeneratedAtTime ?_t
}
}
GROUP BY ?old_arg
}
#Get argument data
GRAPH ?g
{ ?old_arg ^seas:evaluation/seas:evaluation ?new_arg .
?new_arg prov:wasGeneratedAtTime ?t ;
seas:evaluatedValue ?new_arg_val
}
#Bind values to arguments (WIP)
BIND(IF(?position = rdf:_1, ?new_arg_val, "") AS ?arg1)
BIND(IF(?position = rdf:_2, ?new_arg_val, "") AS ?arg2)
#Should do the calculation based on ?calc
BIND(str("newResultHere") AS ?_res)
#Get datatype of existing result
BIND(datatype(?old_res) AS ?datatype)
#Get unit of existing result
BIND(strafter(str(?old_res), " ") AS ?unit)
#Define datatype and unit for result
BIND(strdt(concat(str(?_res), " ", ?unit), ?datatype) AS ?res)
#Make a guid (struuid() bug in stardog)
BIND(replace(str(uuid()), "urn:uuid:", "") AS ?guid)
BIND(uri(concat("https://host/proj", "/Evaluation/", ?guid)) AS ?evaluationURI)
BIND(now() AS ?now)
}
我想获得一个计算结果,这样我就可以构建新的三元组。