sjaakmoes / elasticsearch-langdetect-php
Elasticsearch-PHP 的 Langdetect 命名空间
1.0.0
2015-09-30 09:03 UTC
Requires
- php: >=5.4.0
- elasticsearch/elasticsearch: ~1.0
This package is not auto-updated.
Last update: 2024-09-18 10:53:03 UTC
README
此模块在您使用 elasticsearch-langdetect 插件时,向 Elasticsearch-PHP 库添加端点。
安装
您可以使用 Composer 安装此模块。将 elasticsearch-langdetect-php 包添加到您的 composer.json 文件中
{
"require": {
"sjaakmoes/elasticsearch-langdetect-php": "~1.0"
}
}
通过 composer 安装模块后,我们需要将此模块注入到 Elasticsearch-PHP 库
$params = [ 'host' => ['localhost:9200'], 'customNamespaces' => [ 'langdetect' => 'Langdetect\LangdetectNamespace' ] ]; $client = new Elasticsearch\Client($params);
使用
语言检测
// Detect $params = [ 'content' => 'This is a sample text.' ]; $response = $client->langdetect()->detect($params);
$response 包含一个类似如下结构的数组
Array
(
[profile] => /langdetect/
[languages] => Array
(
[0] => Array
(
[language] => en
[probability] => 0.9999959428847
)
)
)