在 php 中使用 PorterStemmer 后的输入数组和不同的输出
Input array and different output after using PorterStemmer in php
我正在使用 PorterStemmer 来提取词干,就像 "working" 在调用 PorterStemmer class 之后它将是 "work",它对我有用。
但是我想截取一个句子,例如如果我把这句话加到我的代码中:
之前
"I'm playing football and working hard because I have powerful enough"
之后
"I'm play football and work hard because I have power enough"
我在 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);
我正在使用 PorterStemmer 来提取词干,就像 "working" 在调用 PorterStemmer class 之后它将是 "work",它对我有用。
但是我想截取一个句子,例如如果我把这句话加到我的代码中:
之前
"I'm playing football and working hard because I have powerful enough"
之后
"I'm play football and work hard because I have power enough"
我在 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);