支持URI解析和多进程的WebSocket服务器

v0.1.1 2021-03-17 14:47 UTC

This package is auto-updated.

Last update: 2024-09-04 20:09:11 UTC


README

安装

首选安装方式是使用Composer。

在shell中执行以下命令

 composer require nocodeapidotnet/php_sdk

或者

只需将以下内容添加到项目的composer.json中。

"require": {
  "nocodeapidotnet/php_sdk": ">=0.1"
}

配置

use NoCodeApi\Client;
use NoCodeApi\ClientConfig;

$config = new ClientConfig($_ENV['NOCODEAPI_JWT_TOKEN']);

$this->client = new Client($config);

关键词提取API

/** @var \NoCodeApi\Component\KeyPhrases $keyPhrases */
$keyPhrases = $this->client->getKeyPhrases("Now, as a nation, we don't promise equal outcomes, but we were founded on the idea everybody should have an equal opportunity to succeed. No matter who you are, what you look like, where you come from, you can make it. That's an essential promise.");

$keyPhrases->getKeyPhrases();

// Data returned by getKeyPhrases() method example
/**
    [
        {
            "Text": "promise equal outcomes",
            "Score": 8,
            "BeginOffset": 27,
            "EndOffset": 49
        },
        {
            "Text": "equal opportunity",
            "Score": 4.5,
            "BeginOffset": 108,
            "EndOffset": 125
        },
        {
            "Text": "essential promise",
            "Score": 4.5,
            "BeginOffset": 229,
            "EndOffset": 246
        },
        {
            "Text": "nation",
            "Score": 1,
            "BeginOffset": 10,
            "EndOffset": 16
        },
        {
            "Text": "founded",
            "Score": 1,
            "BeginOffset": 63,
            "EndOffset": 70
        },
        {
            "Text": "idea",
            "Score": 1,
            "BeginOffset": 78,
            "EndOffset": 82
        },
        {
            "Text": "succeed",
            "Score": 1,
            "BeginOffset": 129,
            "EndOffset": 136
        },
        {
            "Text": "matter",
            "Score": 1,
            "BeginOffset": 141,
            "EndOffset": 147
        },
        {
            "Text": "make",
            "Score": 1,
            "BeginOffset": 210,
            "EndOffset": 214
        },
        {
            "Text": "america",
            "Score": 1,
            "BeginOffset": false,
            "EndOffset": 7
        },
        {
            "Text": "start",
            "Score": 1,
            "BeginOffset": 269,
            "EndOffset": 274
        },
        {
            "Text": "determine",
            "Score": 1,
            "BeginOffset": 286,
            "EndOffset": 295
        },
        {
            "Text": "end",
            "Score": 1,
            "BeginOffset": 306,
            "EndOffset": 309
        },
        {
            "Text": "read",
            "Score": 1,
            "BeginOffset": false,
            "EndOffset": 4
        }
    ]
**/

语言检测API

/** @var NoCodeApi\Entity\Language $lang */
$lang = $this->client->getLanguageDetection('Policjanci otrzymali zgłoszenie w tej sprawie po godz 9. Do wypadku doszło na ul. Kolonia Krakowskie Przedmieście.');

$lang->getLanguageCode(); // pl
$lang->getLanguage(); // Poland
$lang->getScore(); // 1

情感分析API

/** @var NoCodeApi\Component\Emotions $emotions */
$emotions = $this->client->getEmotions('Genuine leather is the best production for bags imho, but I would not recommend this particular product.');

$emotions->getPositive(); // 0.12
$emotions->getNegative(); // 0.14
$emotions->getNeutral(); // 9.74
$emotions->getMixed(); // 9.97

自定义分类API

// Create by adding classification text and it's label
$this->client->createClassification('foo_bar_baz', 'It was actually different, but the most profitable part was at start'); // true/false

// Update 
$this->client->updateClassification('foo_bar_baz', 'It was actually different, but the most profitable part was at start and in the end of a journey'); // true/false

// Classify the text
/** @var NoCodeApi\Entity\Classification $classification */ 
$classification = $this->client->getClassification('profitable part');

$classification->getLabel(); // getting the label of that successfully classified text

// Deleting classification
$this->client->deleteClassification('foo_bar_baz'); // true/false

命名实体识别

$namedEntities = $this->client->getNamedEntities('Linus Torvalds is one of the best programmers in USA, Finland Helsinki and in the world');

$namedEntities->getEntitiesCount(); // 3

$namedEntities->getNamedEntities(); 
/**
[
    [
        "Text" => "Linus Torvalds",
        "Label" => "PERSON"
    ],
    [
        "Text" => "USA",
        "Label" => "GPE"
    ],
    [
        "Text" => "Finland Helsinki",
        "Label" => "GPE"
    ],
]
**/