我是SWP的新手,我很困惑将从URL获取的参数传递给SPARQL查询,使其更具动态性。这是我正在使用的SWP文件:
<!-- 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="<http://topbraid.org/examples/kennedys>"
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 {
<http://topbraid.org/examples/kennedys#AlfredTucker> ?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 {
<http://topbraid.org/examples/kennedys#" + {= ?query} + "> ?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 :(得分: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="<http://topbraid.org/examples/kennedys>"
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>