【发布时间】:2018-11-21 06:04:46
【问题描述】:
我正在使用名为 Freeling 的语言分析工具。对于语言识别,我在 Linux 控制台中使用analyzer 命令:
analyzer -f /usr/share/freeling/config/ident.cfg --outlv ident --fidn /usr/share/freeling/common/lang_ident/ident.dat
当我执行此命令时,它会等待文本条目(句子)并确定它们使用的语言。 当我用西班牙语写一行文本时:“la casa es azul”并按回车键返回 ES,这意味着它是用西班牙语写的。如果我写“房子是蓝色的”,它会返回 EN,表示英语。要中断其执行,请按 Ctrl + C。
当我在 Linux 控制台中执行此命令时,第一句需要一些时间来响应,而其他时间响应很快。
我使用这段代码来执行这个 php 命令,但是返回结果需要很多秒:
<?php
$cmd = "analyzer -f /usr/share/freeling/config/ident.cfg --outlv ident --fidn /usr/share/freeling/common/lang_ident/ident.dat";
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w"),
);
$process = proc_open($cmd, $descriptorspec, $pipes);
$oracion[0]="we are the word";
$oracion[1]="somos el mundo";
if (is_resource($process)) {
fwrite($pipes[0], $oracion[0]);
fwrite($pipes[0], $oracion[1]);
fclose($pipes[0]);
while($pdf_content = fgets($pipes[1]))
{
echo $pdf_content . "<br>";
}
fclose($pipes[1]);
$return_value = proc_close($process);
}
?>
如何提高响应时间?
【问题讨论】:
-
你不应该在每个句子中至少发送一个换行符吗?并在每个之后立即阅读语言响应? (而不是先发送两个句子。在命令行上不就是这样吗?)
-
尝试分析执行或至少在每个重要行上打印时间差,以了解瓶颈在哪里。
-
马里奥,你在他所说的句子末尾的换行符 (\n) 上是对的。我已经这样做了,而且它继续缓慢。我也尝试发送句子然后读取结果,执行仍然很慢。