Provides read access wrappers to public semantic API services. Version 0.0.4
supports classification using the uClassify.com service and annotation
(enrichment) using Reuters OpenCalais API., (*1)
Visit OpenCalais and uClassify
homepages for more information about their services and to obtain an API key., (*2)
Features
- uClassify API reader enables use of all available public classifiers.
- OpenCalais API reader enables use of the powerful enrichment service from Reuters.
How-to & Examples
Below is a basic example, also available in examples/index.php file. For detailed options,
please see the API documentation., (*3)
Classification
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();
Prints:, (*4)
<?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>
Annotation
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());
Prints:, (*5)
...
Check out OpenCalais homepage for details on different response formats., (*6)
License
Copyright 2014 Vladimir StraÄkovski. MIT license. For more information please see
the license file included in this project., (*7)