gpt4 book ai didi

php - 统计与表中数据相同的单词数据

转载 作者:行者123 更新时间:2023-11-29 14:09:41 25 4
gpt4 key购买 nike

我有一个句子,我想分成单词,然后用停用词表中的数据检查它们。我想计算相同数据的数量(总数)。但是,总计并没有给我相同数据的总计。如何汇总我需要的数据?谢谢

$word ='temporal. the text mining in a evolutionary a theme patterns  theme threads  clustering'; 
$symbol = array(".", ",", "\\", "-", "\"", "(", ")", "<", ">", "?", ";", ":", "+", "%", "\r", "\t", "\0", "\x0B");
$cleanMeta = str_replace($symbol, " ", $word);
$key = strtolower($cleanMeta);
$key = explode(" ", trim($key));

foreach($key as $word_key){
$query = mysql_query ("SELECT COUNT(stoplist_word) AS total FROM tb_stopword WHERE stoplist_word = '$word_key'");
while ($row = mysql_fetch_array($query)) {
$row1 = $row['total'];
echo $row1;
}
}

最佳答案

考虑到您已经清理了输入字符串,您不需要对每个单词进行新查询的 foreach 。你可以这样做:

$word ='temporal. the text mining in a evolutionary a theme patterns  theme threads  clustering'; 
$symbol = array(".", ",", "\\", "-", "\"", "(", ")", "<", ">", "?", ";", ":", "+", "%", "\r", "\t", "\0", "\x0B");
$cleanMeta = str_replace($symbol, " ", $word);
$key = trim(strtolower($cleanMeta));
$key = str_replace("'","''",$key);
$keys = "'".str_replace(" ","', '", $key)."'";

$query = mysql_query ("SELECT COUNT(stoplist_word) AS total FROM tb_stopword WHERE stoplist_word IN ($keys)");
$row = mysql_fetch_array($query);
$total = $row['total'];

echo $total;

如果您确实想要使用 foreach:

$total = 0;
foreach($key as $word_key){
$query = mysql_query ("SELECT COUNT(stoplist_word) AS total FROM tb_stopword WHERE stoplist_word = '$word_key'");
while ($row = mysql_fetch_array($query)) {
$total += $row['total'];
}
}
echo $total;

关于php - 统计与表中数据相同的单词数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13719344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com