SPARQL 绑定 predicate/sub-property 不可变
SPARQL bind predicate/sub-property not variable
我想绑定 属性 而不是 sparql 中的任何变量。
根据 http://www.w3.org/TR/sparql11-query/#bind
我可以绑定任何变量,例如 BIND ( 42 AS ?price )
我的问题是我们可以定义这样的东西吗
BIND ( ?product rdf:price 42 )
要么
BIND ( ?product rdf:price ?price )
或者对我来说理想的情况是
BIND ( ?product ?property ?price ) // where ?property can be minPrice, maxPrice or avgPrice
我的用例是获取这种形式的信息。
SELECT * WHERE {
?product :title ?title; :brand ?brand; :id ?productID.
?product :totalOffers =(assign) {
select COUNT(?oid) WHERE {?oid :isOfferOf ?productID}
}
// or like this
?product (:totalOffers :minPrice :maxPrice ) =(assign) {
select COUNT(?oid) MIN(?price) MAX(?price) WHERE {?oid :isOfferOf ?productID. ?oid :price ?price }
}
}
谢谢
首先要了解的是 SPARQL 执行是自下而上的,因此将首先评估子查询。因此,如果你想分配一些值用于子查询,那么你需要在你的子查询中这样做。
要分配多个变量,您可以使用多个 BIND
语句,例如
BIND("foo" AS ?a)
BIND("bar" AS ?b)
# etc
或者您可以使用单个 VALUES
语句,例如
VALUES ( ?a ?b ) { ( "foo" "bar" ) }
因此您只需在查询中使用它,例如
SELECT * WHERE
{
{
SELECT
?product
(COUNT(?oid) AS ?offers)
(MIN(?price) AS ?minPrice)
(MAX(?price) AS ?maxPrice)
WHERE
{
VALUES ( ?product )
{
( <http://example.org/product> )
}
?product :id ?productID .
?oid :isOfferOf ?productID .
?oid :price ?price .
}
GROUP BY ?product
}
?product :title ?title ;
:brand ?brand .
}
我想绑定 属性 而不是 sparql 中的任何变量。
根据 http://www.w3.org/TR/sparql11-query/#bind
我可以绑定任何变量,例如 BIND ( 42 AS ?price )
我的问题是我们可以定义这样的东西吗
BIND ( ?product rdf:price 42 )
要么
BIND ( ?product rdf:price ?price )
或者对我来说理想的情况是
BIND ( ?product ?property ?price ) // where ?property can be minPrice, maxPrice or avgPrice
我的用例是获取这种形式的信息。
SELECT * WHERE {
?product :title ?title; :brand ?brand; :id ?productID.
?product :totalOffers =(assign) {
select COUNT(?oid) WHERE {?oid :isOfferOf ?productID}
}
// or like this
?product (:totalOffers :minPrice :maxPrice ) =(assign) {
select COUNT(?oid) MIN(?price) MAX(?price) WHERE {?oid :isOfferOf ?productID. ?oid :price ?price }
}
}
谢谢
首先要了解的是 SPARQL 执行是自下而上的,因此将首先评估子查询。因此,如果你想分配一些值用于子查询,那么你需要在你的子查询中这样做。
要分配多个变量,您可以使用多个 BIND
语句,例如
BIND("foo" AS ?a)
BIND("bar" AS ?b)
# etc
或者您可以使用单个 VALUES
语句,例如
VALUES ( ?a ?b ) { ( "foo" "bar" ) }
因此您只需在查询中使用它,例如
SELECT * WHERE
{
{
SELECT
?product
(COUNT(?oid) AS ?offers)
(MIN(?price) AS ?minPrice)
(MAX(?price) AS ?maxPrice)
WHERE
{
VALUES ( ?product )
{
( <http://example.org/product> )
}
?product :id ?productID .
?oid :isOfferOf ?productID .
?oid :price ?price .
}
GROUP BY ?product
}
?product :title ?title ;
:brand ?brand .
}