mbeurel / php-liblinear
使用PHP的liblinear库
0.1.4
2020-04-27 14:42 UTC
Requires
- php: ^7.1
- ext-json: *
- symfony/filesystem: 4.3.*
Requires (Dev)
- symfony/debug-pack: ^1.0.6
This package is auto-updated.
Last update: 2024-09-30 07:43:20 UTC
README
基于Liblinear的PHP简单、轻量级且高效的短文本分类工具。
受Python库 TextGrocery 的启发。
对于词形还原,使用了 php-lemmatizer
安装Liblinear库
Debian或Ubuntu
apt-get install liblinear-dev liblinear-tools liblinear3
其他发行版查看 仓库github
安装php-liblinear
您可以使用Composer安装它
composer require mbeurel/php-liblinear
示例
示例脚本位于独立的仓库中 php-liblinear/examples。
示例代码
include "vendor/autoload.php"; use PhpLiblinear\Classification\LibLinear; $data = [ ["French", "Ceci est un texte dans la langue française."], ["French", "Bonjour, comment allez vous ?"], ["French", "Bonjour, je m'appelle Jean !!!"], ["English", "This is a english language text."], ["English", "Hello, How are you ?"], ["English", "Hello, my name is Jean !!!"], ]; try { // Init library $libLinear = new LibLinear("instanceName", __DIR__."/var", array( "type" => 0, // Liblinear type, view the liblinear documentation "cost" => 1.0, "epsilon" => 0.1, "debug" => false ) ); // Liblinear train $libLinear->train($data); // Save model $libLinear->save(); // Load model $libLinear->load(); // Liblinear predict : String or Array parameters, to array => ["Bonjour, je m'appelle Louis", "Comment allez vous ?"] $result = $libLinear->predict("Bonjour, je m'appelle Louis"); // View result var_dump($result); // $result = array( // 0 => array( // "value" => "French", // "percentage" => 0.763259, // "percentages" => array( // "French" => 0.763259, // "English" => 0.236741 // ) // ) // ) } catch(\Exception $e) { echo $e; }
致谢
由 Matthieu Beurel 创建。由 Yipikai 赞助。