【发布时间】:2015-09-12 12:37:42
【问题描述】:
我想通过 SPARQLs marmotta webservice 从 AngularJS 控制器执行示例 SPARQL 查询 apache marmotta。示例代码:
var url = "http://localhost:8080/marmotta/";
var query = "SELECT * WHERE { ?subject ?property ?object }"
$http.post(url+"sparql/select",{
'output': "json",
'query': query
} ).then(function(data){
$scope.hello = data;
}).catch(function(error){
alert(error);
});
我收到“不支持查询” 然后 500 语法错误:
SyntaxError: Unexpected token q at Object.parse (native) at fromJson (http://localhost:63342/ws/app/script/angular.js:1075:14) at defaultHttpResponseTransform (http://localhost:63342/ws/app/script/angular.js:8650:16) at http://localhost:63342/ws/app/script/angular.js:8735:12 at forEach (http://localhost:63342/ws/app/script/angular.js:326:20) at transformData (http://localhost:63342/ws/app/script/angular.js:8734:3) at transformResponse ( http://localhost:63342/ws/app/script/angular.js:9464:23) 在 processQueue (http://localhost:63342/ws/app/script/angular.js:13292:27) 在 http://localhost:63342/ws/app/script/angular.js:13308:27 在 Scope.$get.Scope.$eval (http://localhost:63342/ws/app/script/angular.js:14547:28)
或者当我使用这样的代码时:
var url = "http://localhost:8080/marmotta/";
var query = "SELECT * WHERE { ?subject ?property ?object }";
$http.get(url+"sparql/select/query="+query+"&output='json'")
.then(function(data){
$scope.hello = data;
}).catch(function(error){
$scope.hello = error.stack;
});
我得到一个 404。任何想法如何正确使用 SPARQL WS API?
【问题讨论】:
-
事实证明,可接受的语法是:$http.post(url+"sparql/select",query)。如果有人知道将 sparql Web 服务与 angular、jquery 或纯 javascript 一起使用的正确方法,请告诉我。
标签: angularjs sparql rdf semantic-web apache-marmotta