【问题标题】:OpenCalais returns persons URI for Linked Data instead of actual person nameOpenCalais 返回链接数据的人员 URI,而不是实际的人名
【发布时间】:2014-09-17 21:58:55
【问题描述】:

我正在使用 OpenCalais Semantic Web 服务并收到对我提交的内容的“应用程序/JSON”响应。当我查看报价实体时,OpenCalais 正在发送人名,但人名不是人名,而是“链接数据”URI。 例如,对于一个名叫 Tayyip Erdogan 的人:

http://d.opencalais.com/pershash-1/a7077bd6-bcc9-3419-b75e-c44e1b2eb693

我需要人名,而不是 URI。 OpenCalais 也在 PersonCareer 实体中发送 URI 而不是人名。我不想阅读 URI 的 html DOM 并提取人名,因为它会减慢一切。有解决办法吗?

报价实体说明:http://www.opencalais.com/documentation/calais-web-service-api/api-metadata/entity-index-and-definitions#Quotation )

【问题讨论】:

    标签: php json uri opencalais


    【解决方案1】:

    事实证明,除了 HTML 之外,还有一种方法可以访问这些人员 URI;那是通过解析RDF。 OpenCalais 提供的任何指向关联数据资源的 URI 链接也可以用作 RDF。只需将 uri 从 .html 更改为 .rdf,您就会以 RDF 格式获得该资源的所有信息。

    例如,对于一个名叫 Tayyip Erdogan 的人:

    http://d.opencalais.com/pershash-1/a7077bd6-bcc9-3419-b75e-c44e1b2eb693.rdf

    以下代码使用 file_get_dom 库,您也可以使用任何本机函数来获取文件内容。这只是我用来从 Web 服务检索到的 RDF 内容中提取人名的一种方法。我相信你能想到一个更好的解决方案。

    public function get_persons_from_pershash($url)
    {   
        //Gets RDF of the person URI
        @$person_html = file_get_dom($url);
    
        if(!empty($person_html))
        {
            //Get position of name tag and extract the name
            $strpos_start = strpos($person_html, '<c:name>') + 8;
            $strpos_end = strpos($person_html, '</c:name>');
            $str_name_length = $strpos_end - $strpos_start;
            $extracted_name = trim(substr($person_html, $strpos_start, $str_name_length));
    
            return $extracted_name;
        }
        return '';      
    }
    

    当您将 URL 更改为 .rdf 时,系统会提示您保存一个 rdf 文件。

    我想以编程方式解析它,所以我就这样做了!

    希望有人觉得这很有帮助!

    干杯!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-23
      • 1970-01-01
      • 2021-12-18
      • 2022-01-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多