2011-11-30 56 views
2

我有Schema.org的RDFa以下HTML:Schema.org價格和SPARQL

<li class="product" typeof="s:Product"> 
    <a href="item.php?id=227"> 
    <img property="s:img" src="http://www.test.com/pictures/227.jpg"></a> 
    <h2 property="s:name">Example name</h2> 
    <div property="s:brand">Examplebrand</div> 
    <div property="s:model">Examplemodel</div> 
    <div rel="s:offers"> 
    <div class="description" typeof="s:Offer"> 
     <div property="s:price">79,00</div> 
     <div property="s:priceCurrency" content="EUR"></div> 
    </div> 
    </div> 
    <div property="s:productID" content="NQ=="> 
    <div rel="s:seller"> 
     <div class="description" typeof="s:Organization"> 
     <div property="s:name">Shop1</div> 
     </div> 
    </div> 
    </div> 
</li> 

加載我想用SPARQL選擇所有這些都是(例如)>€70產品頁面後00。

但這只是還給NULL:

PREFIX s: <http://schema.org/> 
SELECT ?a ?price 
WHERE { 
    ?a s:price ?price. 
    FILTER (?price > 70). 
} 

我認爲這不是解釋的價格作爲價格/浮動。我究竟做錯了什麼?

+0

您的模型是否包含您查詢的數據?你可以部分打印出來嗎? –

+0

您是否嘗試過使用「79.00」作爲價格值?我猜測它可能取決於SPARQL實現或locale是否將「79,00」解釋爲float。 –

+0

重溫您的問題:其他查詢是否有效,即只有價格查詢無效? (你是否在RDFa中定義了前綴':'作爲'http:// schema.org /'?) –

回答

0

XHTML不足以讓我們從RDFa獲取相應的RDF數據。我已經將您的XHTML填入以下內容中。請注意,根據您的SPARQL查詢,我已將s前綴設爲http://schema.org/。但是,如果這些前綴不符合您的數據,那麼這將是一個容易讓事情崩潰的地方。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" 
     version="XHTML+RDFa 1.1" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:s="http://schema.org/" 
     xsi:schemaLocation="http://www.w3.org/1999/xhtml 
          http://www.w3.org/MarkUp/SCHEMA/xhtml-rdfa-2.xsd" 
     lang="en" 
     xml:lang="en"> 
    <head><title>Some title</title></head> 
    <body> 
    <li class="product" typeof="s:Product"> 
     <a href="item.php?id=227"> 
     <img property="s:img" src="http://www.test.com/pictures/227.jpg"/></a> 
     <h2 property="s:name">Example name</h2> 
     <div property="s:brand">Examplebrand</div> 
     <div property="s:model">Examplemodel</div> 
     <div rel="s:offers"> 
     <div class="description" typeof="s:Offer"> 
      <div property="s:price">79,00</div> 
      <div property="s:priceCurrency" content="EUR"></div> 
     </div> 
     </div> 
     <div property="s:productID" content="NQ=="> 
     <div rel="s:seller"> 
      <div class="description" typeof="s:Organization"> 
      <div property="s:name">Shop1</div> 
      </div> 
     </div> 
     </div> 
    </li> 
    </body> 
</html> 

把該進W3C's RDFa distiller,我們可以得到這樣的RDF:

<?xml version="1.0" encoding="utf-8"?> 
<rdf:RDF 
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
    xmlns:s="http://schema.org/" 
    xmlns:xhv="http://www.w3.org/1999/xhtml/vocab#" 
    xmlns:xml="http://www.w3.org/XML/1998/namespace" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
> 
    <rdf:Description rdf:about="http://www.test.com/pictures/227.jpg"> 
    <s:img xml:lang="en"></s:img> 
    </rdf:Description> 
    <s:Product> 
    <s:seller> 
     <s:Organization> 
     <s:name xml:lang="en">Shop1</s:name> 
     </s:Organization> 
    </s:seller> 
    <s:productID xml:lang="en">NQ==</s:productID> 
    <s:model xml:lang="en">Examplemodel</s:model> 
    <s:offers> 
     <s:Offer> 
     <s:priceCurrency xml:lang="en">EUR</s:priceCurrency> 
     <s:price xml:lang="en">79,00</s:price> 
     </s:Offer> 
    </s:offers> 
    <s:name xml:lang="en">Example name</s:name> 
    <s:brand xml:lang="en">Examplebrand</s:brand> 
    </s:Product> 
</rdf:RDF> 

望着RDF,很容易看到爲什麼價格被解釋爲一個字符串:

<s:price xml:lang="en">79,00</s:price> 

屬性值是一個字符串和一個帶有語言標籤的字符串!但是,您可以很容易地指定數據類型,通過添加命名空間和datatype屬性:

<html xmlns="http://www.w3.org/1999/xhtml" 
     version="XHTML+RDFa 1.1" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     ...> 
    ... 
    <div property="s:price" datatype="xsd:float">79,00</div> 
    ... 
</html> 

然而,逗號符號是不是爲xsd:float類型實際上合法的,所以你真的需要指定一個content屬性太,例如:

<div property="s:price" datatype="xsd:float" content="79.00">79,00</div> 

這些變化後,你會得到這個RDF:

<?xml version="1.0" encoding="utf-8"?> 
<rdf:RDF 
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
    xmlns:s="http://schema.org/" 
    xmlns:xhv="http://www.w3.org/1999/xhtml/vocab#" 
    xmlns:xml="http://www.w3.org/XML/1998/namespace" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
> 
    <s:Product> 
    <s:productID xml:lang="en">NQ==</s:productID> 
    <s:model xml:lang="en">Examplemodel</s:model> 
    <s:brand xml:lang="en">Examplebrand</s:brand> 
    <s:offers> 
     <s:Offer> 
     <s:priceCurrency xml:lang="en">EUR</s:priceCurrency> 
     <s:price rdf:datatype="http://www.w3.org/2001/XMLSchema#float">79.00</s:price> 
     </s:Offer> 
    </s:offers> 
    <s:name xml:lang="en">Example name</s:name> 
    <s:seller> 
     <s:Organization> 
     <s:name xml:lang="en">Shop1</s:name> 
     </s:Organization> 
    </s:seller> 
    </s:Product> 
    <rdf:Description rdf:about="http://www.test.com/pictures/227.jpg"> 
    <s:img xml:lang="en"></s:img> 
    </rdf:Description> 
</rdf:RDF> 

那些經過通道您的查詢工作得很好,沒有任何修改:

$ arq --data data3.rdf --query query.sparql 
------------------------------------------------------------ 
| a | price            | 
============================================================ 
| _:b0 | "79.00"^^<http://www.w3.org/2001/XMLSchema#float> | 
------------------------------------------------------------