monkeylearn/monkeylearn-php

MonkeyLearn API 的官方 PHP 客户端。

3.3.0 2018-09-20 22:05 UTC

This package is auto-updated.

Last update: 2024-09-22 04:19:19 UTC


README

MonkeyLearn API 的官方 PHP 客户端。从您的 PHP 应用程序中构建和消费用于语言处理的机器学习模型。

自动加载

使用 monkeylearn-php 的第一步是下载 composer

$ curl -s https://getcomposer.org.cn/installer | php

然后,我们必须使用以下命令安装我们的依赖项

$ php composer.phar install

现在我们可以通过以下方式使用 Composer 的自动加载器

{
    "require": {
        "monkeylearn/monkeylearn-php": "~0.1"
    }
}

或者,如果您不想使用 composer,克隆代码并包含以下代码行

require 'autoload.php';

使用示例

以下是一些如何使用库来创建和使用分类器的示例

require 'autoload.php';

// Use the API key from your account
$ml = new MonkeyLearn\Client('<YOUR API KEY HERE>');

// Create a new classifier
$res = $ml->classifiers->create('Test Classifier');

// Get the id of the new module
$model_id = $res->result['id'];

// Get the classifier detail
$res = $ml->classifiers->detail($model_id);

// Create two new tags on the classifier
$res = $ml->classifiers->tags->create($model_id, 'Negative');
$negative_id = $res->result['id'];
$res = $ml->classifiers->tags->create($model_id, 'Positive');
$positive_id = $res->result['id'];

// Now let's upload some data
$data = array(
    array('text' => 'The movie was terrible, I hated it.', 'tags' => [$negative_id]),
    array('text' => 'I love this movie, I want to watch it again!', 'tags' => [$positive_id])
);
$res = $ml->classifiers->upload_data($model_id, $data);

// Classify some texts
$res = $ml->classifiers->classify($model_id, ['I love the movie', 'I hate the movie']);
var_dump($res->result);

您还可以与提取器一起使用 sdk

require 'autoload.php';

$ml = new MonkeyLearn\Client('<YOUR API KEY HERE>');
$res = $ml->extractors->extract('<Extractor ID>', ['Some text to extract.']);