我已经在 Web 应用程序(PHP 语言)上安装了 Carrot2。一切都很完美。现在我想更改结果的语言。我想把英语换成法语。我在网络上搜索了胡萝卜2 文档,但没有找到我想要的(这个链接很有用,但似乎 dcs 文件夹自这篇文章以来发生了变化http://carrot2-users-and-developers-forum.607571.n2.nabble.com/Change-Language-in-DCS-REST-PHP-td639270.html
)。无论如何,我用一个简单的形式(和不同的变量)传递我的参数(算法、查询、源等),然后用 curl 将它们(PHP)发送到carrot2的方法。我尝试了不同(奇怪或野蛮)的方式来发送法语:
$language = 'lang_fr'; // or $language = 'FRENCH'
$num = (isset($_GET["maxResult"])) ? $_GET["maxResult"] : "10";
$query = urlencode($_GET["query"]);
$source = "web";
$algorithm = "lingo";
$hierarchy = "max-hierarchy-depth";
$level_hierarchie= $_GET["deep"] ? $_GET["deep"] : "1";
$processor = new Carrot2Processor();
$job = new Carrot2Job();
$job->setSource($source);
$job->setQuery($query);
$job->setAlgorithm($algorithm);
$job->setAttribute("results", $num);
$job->setAttribute($hierarchy, $level_hierarchie);
我试图在 setAttribute() 函数中设置这样的语言,当然它不起作用。
$job->setAttribute("language", $language);
try {
$result = $processor->cluster($job);
} catch (Carrot2Exception $e) {
echo 'An error occurred during processing: ' . $e->getMessage();
exit(10);
}
我还尝试更改CURLOPT_HTTPHEADER
(添加' Accept-langugage: fr'
)。我看到了不同的响应,但仅适用于使用 java 的开发人员和使用 php 的我。是否可以使用 PHP 上的 setAttribute() 方法传递语言选择?有人知道这样做的方法吗?
提前谢谢你(我用的是carrot2-dcs-3.16)