【问题标题】:AlchemyAPI UsageAlchemyAPI 使用
【发布时间】:2011-08-30 07:57:33
【问题描述】:

我正在搜索并尝试学习 Alchemy API。但是,我无法将该 API 与 PHP 一起使用。谁能告诉我如何使用这个 API?例如,我想对文本进行分类,所以我将使用 textGetCategory PHP 方法。如何在我的 PHP 文件中使用此方法我想知道这一点。 谢谢。

【问题讨论】:

  • 什么是 AlchemyAPI?一些链接可能会有所帮助。
  • alchemyapi.com 介绍 API。这是一个用于信息提取的 NLP 项目。可能是一个更好的 API 建议,我刚刚找到了这个,基本上它可以满足我的需求

标签: php nlp alchemyapi


【解决方案1】:

我对他们通过 PHP 类提供的 API 有一个简单的包装器,也许您可​​以从这段代码开始并添加您需要的方法。

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;
  }
}

只需更改 __construct 中的路径并添加您的 API 密钥,您就可以使用它了。

SimpleAlchemyAPI::getInstance()
  ->getTitle('http://stackoverflow.com/questions/6083656/alchemyapi-usage');

【讨论】:

  • 这对我来说非常有效。请到这里来,我可能对那个 api 有几个问题,很高兴得到你的回答:)。谢谢!!!
  • @gencay 我不确定能否为您提供有关 API 的更多信息,因为这就是我使用它的全部内容(如果我记得清楚的话,甚至可能是标签)。
【解决方案2】:

alchemy 提供了一个 api,可用于查找实体提取、文本或 html 的文本提取情感等。 http://www.alchemyapi.com/api/*在这里您可以找到与炼金术 api 相关的所有详细信息。 并且 php-sdk 在 *https://github.com/AlchemyAPI/alchemyapi_php/

上可用

【讨论】:

    猜你喜欢
    • 2012-07-19
    • 2015-09-11
    • 2014-08-06
    • 2016-07-23
    • 1970-01-01
    • 2017-03-16
    • 2015-02-19
    • 2011-12-08
    • 2016-11-12
    相关资源
    最近更新 更多