我有一个类使用自然语言处理的正则表达式和处理大量的数据,它喂养的时间看起来并不乐观。需要指导扩大在php
我正在寻求扩大规模,并行做事的手段,我还没有任何经验。
我希望有人能够解释我在搞什么,利弊如何在php中做到这一点。此外,如果你可以提供一般的缩放比例或者更好的缩放比例。谢谢。
编辑:
foreach ($sentences as $sentence) {
// for each sentence check if a keyword or any of its synonyms
// appear together with any sentiment applicable to the keyword
foreach ($this->keywords as $keyword => $synonyms) {
foreach ($this->sentiments[$keyword] as $sentiment => $weight) {
$match = $this->check($sentence, $synonyms, $sentiment);
}
}
}
// regex part of the code
$keywords = implode('|', $keywords);
$pattern = "/(\b$sentiment\b(.*|\s)\b($keywords)\b|\b($keywords)\b(.*|\s)\b$sentiment\b)/i";
preg_match_all($pattern, $sentence, $matches);
如果你发布了一些代码,你将会有更多的运气。无论如何,对你的代码运行一个分析器来查看哪些部分花费的时间最长是个好主意。 – 2011-06-11 04:48:52