操纵数组并获取单词出现次数

时间:2014-06-24 12:05:57

标签: php mysql sql

我正在对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进行单词计数。

我需要帮助
  1. 如何计算pos中tag = t
  2. 的不同字词
  3. 如何计算pos中tag = t
  4. 的所有单词
  5. 如何从pos中计算单词w,其中tag ='marketting'且pos包含单词w

1 个答案:

答案 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));