nv/semtools

基于公开的语义API服务对英语文本进行分类和丰富化的工具。

0.0.4 2014-08-12 23:29 UTC

This package is not auto-updated.

Last update: 2024-09-24 03:13:12 UTC


README

提供对公共语义API服务的读写访问包装器。版本0.0.4支持使用uClassify.com服务进行分类,以及使用路透社OpenCalais API进行标注(丰富化)。

访问 OpenCalaisuClassify 主页了解更多关于它们服务的详情,并获取API密钥。

功能

  • uClassify API阅读器允许使用所有可用的公共分类器。
  • OpenCalais API阅读器允许使用路透社强大的丰富化服务。

如何使用 & 示例

以下是基本示例,也位于examples/index.php文件中。对于详细选项,请参阅API文档

分类

use nv\semtools\Classifiers\uClassify;

header('Content-type: text/xml');

// Instantiate the reader with your API key (provided by uClassify)
$classifier = new uClassify\UclassifyReader('YOUR_API_KEY');

// Create a new request with the text to be classified and the classifier to use
$classifierRequest = new uClassify\UclassifyRequest(
    'My happy text',
    'prfekt/Myers Briggs Attitude'
);

// Execute and return the request
$classifierResponse = $classifier->read($classifierRequest);
echo $classifierResponse->getResponse();

打印

<?xml version="1.0" encoding="UTF-8" ?>
<uclassify xmlns="http://api.uclassify.com/1/ResponseSchema" version="1.01">
	<status success="true" statusCode="2000"/>
	<readCalls>
	<classify id="cls1">
		<classification textCoverage="1">
			<class className="Extraversion" p="0.99998"/>
			<class className="Introversion" p="2.0456e-005"/>
		</classification>
	</classify>
	</readCalls>
</uclassify>

标注

use nv\semtools\Annotators\OpenCalais;

// The content to process
$content = '';
// Instantiate a new annotator instance with your API key (provided by OpenCalais)
$annotator = new OpenCalais\OpenCalaisReader('YOUR_API_KEY');

// Create a new request with passing the content as parameter
$annotatorRequest = new OpenCalais\OpenCalaisRequest($content);

// Execute request, recieve response
$annotatorResponse = $annotator->read($annotatorRequest);

// To get the raw response
$annotatorResponse->getResponse();

// To get the response parsed to php array
print_r($annotatorResponse->getEntities());

打印

...

有关不同响应格式的详细信息,请参阅OpenCalais主页

许可证

版权所有2014年Vladimir Stračkovski。MIT许可证。更多信息请参阅此项目中的许可证文件。