簡體   English   中英

SPARQL綁定謂詞/子屬性不變

[英]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 .
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM