代码之家  ›  专栏  ›  技术社区  ›  vvffl

PHP EasyRDF:无法从构造查询获取图形

  •  0
  • vvffl  · 技术社区  · 6 年前

    我想找一个 EasyRdf_Graph 来自通过发送的查询的对象 EasyRdf_Sparql_Client::query

    EasyRDF doc says :

    SELECT ASK 查询将返回类型为的对象 EasyRdfSparqlResult .

    CONSTRUCT DESCRIBE EasyRdf\ U图 .

    <?php
    require APPPATH .'third_party/vendor/autoload.php';        
    $endpointUrl = "http://data.bnf.fr/sparql";        
    $dummyConstructQueryString = "construct { ?s ?q ?r } where { ?s ?p ?o . ?o ?q ?r } limit 1";        
    $endPoint = new EasyRdf_Sparql_Client($endpointUrl);
    $result = $endPoint->query($dummyConstructQueryString);                
    var_dump($result);
    echo $result;
    ?>
    

    这是输出,它是 EasyRdf_Sparql_Result 如你所见:

    object(**EasyRdf_Sparql_Result**)#47 (6) {
      ["type":"EasyRdf_Sparql_Result":private]=>
      string(8) "bindings"
      ["boolean":"EasyRdf_Sparql_Result":private]=>
      NULL
      ["ordered":"EasyRdf_Sparql_Result":private]=>
      NULL
      ["distinct":"EasyRdf_Sparql_Result":private]=>
      NULL
      ["fields":"EasyRdf_Sparql_Result":private]=>
      array(3) {
        [0]=>
        string(1) "s"
        [1]=>
        string(1) "p"
        [2]=>
        string(1) "o"
      }
      ["storage":"ArrayIterator":private]=>
      array(1) {
        [0]=>
        object(stdClass)#48 (3) {
          ["s"]=>
          object(EasyRdf_Resource)#49 (2) {
            ["uri":protected]=>
            string(56) "http://www.w3.org/ns/sparql-service-description#endpoint"
            ["graph":protected]=>
            NULL
          }
          ["p"]=>
          object(EasyRdf_Resource)#50 (2) {
            ["uri":protected]=>
            string(47) "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
            ["graph":protected]=>
            NULL
          }
          ["o"]=>
          object(EasyRdf_Resource)#51 (2) {
            ["uri":protected]=>
            string(42) "http://www.w3.org/2000/01/rdf-schema#Class"
            ["graph":protected]=>
            NULL
          }
        }
      }
    }
    +-------------+----------+------------+
    | ?s          | ?p       | ?o         |
    +-------------+----------+------------+
    | sd:endpoint | rdf:type | rdfs:Class |
    

    http://dbpedia.org/sparql http://localhost:3030/testFuseki )因为我看到了这个问题: https://github.com/njh/easyrdf/issues/226

    有关安装的信息

    • 随Composer一起安装的EasyRDF版本0.9.1

    • PHP版本7.0.30-0+deb9u1+Apache/2.4.25(Debian)


    编辑

    事实上 它与我在本地安装的Fuseki一起工作 . 自 http://data.bnf/fr/sparql 都是Virtuoso的端点,我想知道问题是否只存在于Virtuoso。

    2 回复  |  直到 6 年前
        1
  •  1
  •   TallTed    6 年前

    这个问题是由EasyRDF发出的HTTP请求头暴露出来的,并发布在您的答案中(所有这些额外的细节实际上都应该编辑到您的问题中)。

    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    

    text/html application/xhtml+xml ,然后更愿意 application/xml ,后跟 */* 或“任何媒体类型”。

    事实并非如此! 也不比 在这种情况下。

    文本/html ... EasyRDF不把它当作一个图来处理也就不足为奇了。

    application/n-quads ,它不是EasyRDF请求的任何特定MIME类型)

    EasyRDF公司 text/turtle , application/rdf+xml , application/trig , application/n-triples , application/ld+json , sparql-results+xml Accept: 标题)。EasyRDF还应该指出,这些(可能带有内部优先顺序)优先于任何非RDF MIME类型(包括EasyRDF当前请求的所有特定MIME类型)或通配符( */*

    这应该是 reported as a bug in EasyRDF @TallTed on github )在你的报告里。

        2
  •  0
  •   TallTed    6 年前

    a solution

    似乎返回的对象类型( EasyRdf_Graph / EasyRdf_Sparql_Result )视情况而定 Accept 标头的参数。我试图修改它(添加了中列出的不同内容类型) Virtuoso doc )通过Firebug重新发送请求,但没有收到任何请求 EasyRdf\ U图


    正如Ted所问,下面是请求头的相关部分(使用上面的php代码和EasyRDF 0.0.1):

    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3
    Accept-Encoding: gzip, deflate
    Connection: keep-alive
    

    print_r(get_headers($endpointUrl));
    

    下面是Fuseki的响应头(它给出了一个 对象):

    [0] => HTTP/1.1 200 OK
    [1] => Date: Tue, 11 Sep 2018 06:14:56 GMT
    [2] => Fuseki-Request-ID: 13
    [3] => Vary: Accept,Accept-Encoding,Accept-Charset
    [4] => Content-Type: application/n-quads
    [5] => Vary: User-Agent
    

    http://data.bnf.fr )

    [0] => HTTP/1.1 302 Found
    [1] => Date: Tue, 11 Sep 2018 06:12:29 GMT
    [2] => Server: Apache
    [3] => Location: http://data.bnf.fr/sparql/
    [4] => Content-Length: 210
    [5] => Content-Type: text/html; charset=iso-8859-1
    [6] => Vary: Accept-Encoding,User-Agent
    [7] => Connection: close
    [8] => HTTP/1.1 200 OK
    [9] => Date: Tue, 11 Sep 2018 06:12:29 GMT
    [10] => Server: Apache
    [11] => Last-Modified: Mon, 19 Feb 2018 10:34:21 GMT
    [12] => ETag: "200036-3a99-5658e3ca8a540"
    [13] => Accept-Ranges: bytes
    [14] => Content-Length: 15001
    [15] => Vary: Accept-Encoding,User-Agent
    [16] => Access-Control-Allow-Origin: *
    [17] => Content-Type: text/html
    [18] => Content-Language: fr
    [19] => Connection: close
    

    注:用于数据.bnf.fr代码是302(重定向),但似乎没有任何区别,请参阅dbpedia响应:

    [0] => HTTP/1.1 200 OK
    [1] => Date: Tue, 11 Sep 2018 07:17:23 GMT
    [2] => Content-Type: text/html; charset=UTF-8
    [3] => Content-Length: 14172
    [4] => Connection: close
    [5] => Vary: Accept-Encoding
    [6] => Server: Virtuoso/07.20.3229 (Linux) i686-generic-linux-glibc25-64  VDB
    [7] => Expires: Tue, 18 Sep 2018 07:17:23 GMT
    [8] => Cache-Control: max-age=604800
    [9] => Access-Control-Allow-Origin: *
    [10] => Access-Control-Allow-Credentials: true
    [11] => Access-Control-Allow-Methods: GET, POST, OPTIONS
    [12] => Access-Control-Allow-Headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Accept-Encoding
    [13] => Accept-Ranges: bytes
    

    使用新php代码和composer更新的解决方案

    1) 编辑编写器.json:

    {
        "require": {
            "easyrdf/easyrdf": "dev-master"
        }
    }
    

    php composer.phar update
    

    3) 重写php代码:

    require_once './third_party/vendor/autoload.php';
    $endpointUrl = "http://data.bnf.fr/sparql";        
    $dummyConstructQueryString = "construct { ?s ?q ?r } where { ?s ?p ?o . ?o ?q ?r } limit 1";        
    $endPoint = new \EasyRdf\Sparql\Client($endpointUrl); // <-- here use the namespace
    $result = $endPoint->query($dummyConstructQueryString);                
    var_dump($result);
    

    编辑

    EasyRdf\ U图 对象。以下是请求和响应的标头,带有更新的Easyrdf代码(“dev master”版本)。也许EasyRDF解析查询和结果来构建一个 EasyRdf\ U图

    •  Host: localhost
       User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0
       Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
       Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3
       Accept-Encoding: gzip, deflate
       DNT: 1
       Connection: keep-alive
       Upgrade-Insecure-Requests: 1
       Cache-Control: max-age=0
      
    • 回应 http://data.bnf.fr/sparql/ (通过以下方式获得) print_r(get_headers($endpointUrl));

       [0] => HTTP/1.1 302 Found
       [1] => Date: Wed, 12 Sep 2018 06:21:48 GMT
       [2] => Server: Apache
       [3] => Location: http://data.bnf.fr/sparql/
       [4] => Content-Length: 210
       [5] => Content-Type: text/html; charset=iso-8859-1
       [6] => Vary: Accept-Encoding,User-Agent
       [7] => Connection: close
       [8] => HTTP/1.1 200 OK
       [9] => Date: Wed, 12 Sep 2018 06:21:48 GMT
       [10] => Server: Apache
       [11] => Last-Modified: Mon, 19 Feb 2018 10:34:21 GMT
       [12] => ETag: "200036-3a99-5658e3ca8a540"
       [13] => Accept-Ranges: bytes
       [14] => Content-Length: 15001
       [15] => Vary: Accept-Encoding,User-Agent
       [16] => Access-Control-Allow-Origin: *
       [17] => Content-Type: text/html
       [18] => Content-Language: fr
       [19] => Connection: close