AlchemyAPI Usage
I am searching and trying to learn Alchemy API. However, I am not able to use that API with PHP. Can anybody tell me how to use this API? For instance I would like to categorize the text so I will use textGetCategory PHP meth开发者_如何学JAVAod. How to use this method in my PHP files I want to know this. Thanks.
I have a simple wrapper around the APIs they provide via their PHP classes, maybe you can start from this code and add the methods that you require.
class SimpleAlchemyAPI {
protected static $instance = null;
public static function getInstance() {
if(is_null(self::$instance)) {
$class = __CLASS__;
self::$instance = new $class;
}
return self::$instance;
}
public $api = null;
protected function __construct() {
require_once('./AlchemyAPI.php');
require_once('./AlchemyAPIParams.php');
$this->api = new AlchemyAPI;
$this->api->setAPIKey("your_api_key");
}
public function getTitle($url) {
$result = json_decode($this->api->URLGetTitle($url, 'json'), true);
return $result['status'] == 'OK' ? $result['title'] : null;
}
public function getContent($url) {
$result = json_decode($this->api->URLGetText($url, 'json'), true);
return $result['status'] == 'OK' ? $result['text'] : null;
}
}
Just change the paths in the __construct
as well as adding your API key and you're set to use it.
SimpleAlchemyAPI::getInstance()
->getTitle('http://stackoverflow.com/questions/6083656/alchemyapi-usage');
alchemy provides an api which can be used to find entity extraction , text extraction sentiment of a text or html and so on. http://www.alchemyapi.com/api/*here you can find all the details related to alchemy api. and the php-sdk is available on *https://github.com/AlchemyAPI/alchemyapi_php/
精彩评论