我正在对 Mysql 数据进行数学运算。
对于给定标签c
,单词w
的概率方程如下
P(w/c) = count of words w where tag is c / (total count of words where tag is c + distinct words from all tags)
我可以从表中检索值,但问题在于计算单词数。
记录是这样的(pos是词性,即名词形容词)
seq hash post pos tag cat
1 78bb622642f6a28681ca15676045cabd Marketing in every web application is essential no... web, application, essential, big, SEO, full, stack... marketing Discussion
2 ec31a76d380590fff71cf7b10db0f084 I have just launched my new startup on web analyti... new, startup, web, expert, SEO, digital marketing Discussion
我不熟悉 php + mysql 的字数统计。我需要帮助
- 如何计算
pos
中不同的单词,其中 tag = t - 如何计算
pos
中 tag = t 的所有单词 - 如何从 pos 中计算单词
w
,其中 tag = 'marketting' 并且 pos 包含单词w
最佳答案
获取带有所需标签的 pos:
SELECT pos FROM table WHERE tag = "tag_you_want"
然后在 PHP 中计算一个特定的单词:
echo substr_count($string, 'word');
统计 pos 中的所有单词:
echo count(str_word_count($string));
关于php - 操作数组并获取单词出现次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24386214/