【问题标题】:How to use Apache Marmotta SPARQL webservice api with AngularJS?如何将 Apache Marmotta SPARQL webservice api 与 AngularJS 一起使用?
【发布时间】: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


【解决方案1】:

因为 SPARQL 端点实际上位于 http://localhost:8080/marmotta/sparql/select

您应该在 Marmotta 的 SPARQL 模块中拥有该文档。

【讨论】:

    【解决方案2】:

    我之前也遇到过同样的问题。但实际上我通过检查 apache marrmotta Web 应用程序生成的 ajax 请求找到了解决方案。 这是适合我的示例请求

    var settings = {
      "async": true,
      "crossDomain": true,
      "url": "http://localhost:8080/marmotta/sparql/select",
      "method": "POST",
      "headers": {
        "content-type": "application/sparql-query;charset=UTF-8",
        "accept": "application/sparql-results+json"
      },
      "data": "SELECT * WHERE { ?s ?p ?o } LIMIT 10"
    }
    
    $.ajax(settings).done(function (response) {
      console.log(response);
    });
    

    我认为主要问题是标题。

    【讨论】:

      【解决方案3】:

      在流星平台上它可以工作,使用包“http”并调用 Apache Marmotta 的 Web 服务。

      HTTP.call("GET", "http://IP:8080/sparql/select", {
          params: {
              "query": "select * where {?s ?p ?o } limit 10",
              "output": "xml"
          }
      }, function(error, result) {
          console.log(result);
      });

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-12
        • 1970-01-01
        • 2015-01-14
        • 1970-01-01
        相关资源
        最近更新 更多