我正在对Mysql数据执行数学运算。
给定标记w
的单词c
的概率等式是这样的
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 w
,其中tag ='marketting'且pos包含单词w
答案 0 :(得分:0)
获取带有所需标签的pos:
SELECT pos FROM table WHERE tag = "tag_you_want"
然后在PHP中计算一个特定的单词:
echo substr_count($string, 'word');
统计pos中的所有单词:
echo count(str_word_count($string));