我正在使用OpenCalais语义Web服务,并接收对我提交的内容的"Application/JSON“响应。当我查看引号实体时,OpenCalais正在发送person引号,但是person名称不是该人的名称,而是一个“链接数据”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 )
发布于 2014-07-27 01:15:31
事实证明,除了HTML之外,还有一种访问这些person 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文件。
我想以编程的方式解析它,所以我就这样做了!
希望有人觉得这有帮助!
干杯!
https://stackoverflow.com/questions/24966025
复制相似问题