我正在使用PorterStemmer来词干,就像“正在工作”一样,在调用PorterStemmer类后将“工作”,这对我有用。
但是我想保留一个句子,例如,如果我将此句子添加到我的代码中:
前
“我踢足球并努力工作是因为我有足够的力量”
后
“我踢足球,努力工作,因为我有足够的力量”
似乎我在php中使用“ foreach”循环有问题,因为我的代码仅是一个词。
我的代码:
$str=('I am playing football and working hard because I have powerful enough');
$parts = explode(' ', $str);
$word_to_stem = $str;
$stem = PorterStemmer::Stem($word_to_stem);
现在,将$parts
我的句子作为数组包含在内,我该如何词干每个单词,然后将新句子放入名为$str2
因此,如果您想阻止每个单词:
$str=('I am playing football and working hard because I have powerful enough');
$parts = explode(' ', $str);
$stemmed_parts = array();
foreach ($parts as $word) {
$stemmed_word = PorterStemmer::Stem($word);
$stemmed_parts[] = $stemmed_word;
}
echo implode(' ', $stemmed_parts);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句