2013-10-25 57 views
3

我對SWP非常陌生,我對將從URL獲取的參數傳遞到SPARQL查詢以使其更加動態化非常困惑。這是SWP文件我的工作:如何將參數傳遞到SPARQL Web頁面查詢

<!-- Navigate to http://localhost:8083/tbl/tutorial.swp?test=Mate in a web browser --> 
<ui:setContext 
     xmlns:kennedys="http://topbraid.org/examples/kennedys#" 
     ui:queryGraph="&lt;http://topbraid.org/examples/kennedys&gt;" 
     let:query = "{= ui:param('test', xsd:string)}" 
     let:helloThere = "{= xsd:string('hello')}" 
    > 
    <h1>G'day, {= ?helloThere}!</h1> 


    <table> 
     <thead> 
      <tr> 
       <th data-field="propertyID"> 
        Property ID 
       </th> 
       <th data-field="property"> 
        Property 
       </th> 
       <th data-field="valueID"> 
        Value ID 
       </th> 
       <th data-field="value"> 
        Value 
       </th> 
      </tr> 
     </thead> 

     <ui:forEach ui:resultSet="{# 
       SELECT * 
       WHERE { 
        &lt;http://topbraid.org/examples/kennedys#AlfredTucker&gt; ?property ?value . 
       } 
       }"> 
      <tr> 
       <td>{= xsd:string(?property) }</td> 
       <td>{= ui:label(?property) }</td> 
       <td>{= xsd:string(?value) }</td> 
       <td>{= ui:label(?value) }</td> 
      </tr> 

     </ui:forEach> 

    </table> 


</ui:setContext> 

這一切工作正常和花花公子,但我想在一個變量傳遞到SPARQL查詢。我試過這樣的事情:

<ui:forEach ui:resultSet="{# 
      SELECT * 
      WHERE { 
       &lt;http://topbraid.org/examples/kennedys#" + {= ?query} + "&gt; ?property ?value . 
      } 
      }"> 
     <tr> 
      <td>{= xsd:string(?property) }</td> 
      <td>{= ui:label(?property) }</td> 
      <td>{= xsd:string(?value) }</td> 
      <td>{= ui:label(?value) }</td> 
     </tr> 

    </ui:forEach> 

不幸的是,這是行不通的。我想知道如何將變量傳遞到SPARQL查詢中。

+0

「這不起作用」是有點不明確的。第二種情況下你得到了什麼結果? –

+1

Topbraid支持只是回覆並提供給我一個解決方案!感謝您的幫助 –

+0

感謝您發佈解決方案!不要忘記[接受它](http://meta.stackexchange.com/q/5234/225437)! (在Stack Overflow上接受你自己的答案是完全可以接受的;畢竟,你最清楚哪個答案適合你!) –

回答

3

我聯繫了TopBraid支持,他們解決了我的問題!這是有效的解決方案:

<!-- Navigate to http://localhost:8083/tbl/dummy.swp?name=AlfredTucker in a web browser --> 
<ui:setContext 
     xmlns:kennedys="http://topbraid.org/examples/kennedys#" 
     ui:queryGraph="&lt;http://topbraid.org/examples/kennedys&gt;" 
     let:name="{= ui:param('name', xsd:string) }"> 

    <data let:personURI="{= IRI(CONCAT('http://topbraid.org/examples/kennedys#', ?name))}"> 
     <ui:forEach ui:resultSet="{# 
       SELECT * 
       WHERE { 
        ?personURI ?property ?value . 
       } ORDER BY ui:label(?person) }"> 
      <entry> 
       <property>{= ui:label(?property) }</property> 
       <value>{= ui:label(?value)}</value> 
      </entry> 
     </ui:forEach> 
    </data> 

</ui:setContext>