【发布时间】:2015-06-10 11:07:36
【问题描述】:
我正在使用 Angular 来绑定 SPARQL 查询的结果。
在我尝试使用 SPARQL “STRAFTER” 或 “REPLACE” 函数(下面的代码)绑定从查询返回的数据之前,它运行良好,这些函数在 $scope 中返回空白数据。但是,如果我直接从 Fuseki 控制面板运行它并将输出设置为 json,则相同的查询可以正常工作。
我正在使用 Fuseki Server 1-1.1.2 端点 (SPARQL 1.1)。
这是在 Fuseki 服务器中返回预期数据的查询:
SELECT (strafter(str(?class),"#") AS ?className) (COUNT(?s) AS ?count )
{ ?s a ?class }
GROUP BY ?class ORDER BY DESC(?count)
这是在“$http.get”调用中使用相同查询的 HTML/angular 代码,响应以 angular 形式返回为空白:
<div ng-app="myApp" ng-controller="queryCtrl"><table>
<tr ng-repeat="x in results">
<td>{{x.class.value}}</td>
<td>{{x.count.value}}</td>
</tr>
</table></div>
<script>
var app = angular.module('myApp', []);
app.controller('queryCtrl', function($scope, $http) {
var query = encodeURIComponent("SELECT (strafter(str(?class), "#") AS ? className) (COUNT(?s) AS ?count) {?s a ?class} GROUP BY ?class ORDER BY DESC(? count)");
var endpoint = "http://localhost:3030/dataset/query";
$scope.results = [];
$http.get("http://localhost:3030/dataset/query? query="+query+"&output=json")
.success(function (response) {
$scope.results = response.results.bindings;
/* for debugging*/
if ( window.console && window.console.log ) {
// console is available, write message if something has happened
console.log(response.results);
}
});
});
</script>
请知道为什么会发生这种情况?
【问题讨论】: