1

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 method. How to use this method in my PHP files I want to know this. Thanks.

gencay
  • 609
  • 5
  • 14
  • 26
  • What *is* AlchemyAPI? Some links would probably be helpful. – Pekka May 21 '11 at 18:35
  • http://www.alchemyapi.com/ introduces API. It is an NLP project for information extraction. May be a better API suggested, I just found this one and basically it makes what i want – gencay May 21 '11 at 18:40

2 Answers2

3

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');
mhitza
  • 5,709
  • 2
  • 29
  • 52
  • That works really well for me. Just please be over here I can have several troubles about that api and will be pleased to get answer from you: ). Thanks!!! – gencay May 21 '11 at 19:32
  • @gencay I'm not sure I will be able to give you more information about the API because this is all I've used it for (maybe even tags if I remember well). – mhitza May 21 '11 at 19:52
1

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/

sapna
  • 11
  • 2