这是一个基本的文本分类问题。有很多关于如何确定某些文本是否是垃圾邮件/非垃圾邮件的文章,如果您真的想深入了解细节,我建议您深入研究。对于您需要在此处执行的操作而言,其中很多内容可能都过分了。
当然,一种方法是评估为什么你要求人们输入更长的简历,但我假设你已经决定强迫人们输入更多的文本是要走的路。
以下是我将要执行的操作的概述:
- 为输入字符串构建单词出现的直方图
- 研究一些有效和无效文本的直方图
- 想出一个公式,用于将直方图分类为有效与否
这种方法需要您弄清楚两组之间有什么不同。直观地说,我希望垃圾邮件显示较少的唯一单词,如果您绘制直方图值,则曲线下方的较高区域将集中在顶部单词上。
下面是一些示例代码,可帮助您继续学习:
$str = 'Love a and peace love a and peace love a and peace love a and peace love a and peace love a and peace';
// Build a histogram mapping words to occurrence counts
$hist = array();
// Split on any number of consecutive whitespace characters
foreach (preg_split('/\s+/', $str) as $word)
{
// Force all words lowercase to ignore capitalization differences
$word = strtolower($word);
// Count occurrences of the word
if (isset($hist[$word]))
{
$hist[$word]++;
}
else
{
$hist[$word] = 1;
}
}
// Once you're done, extract only the counts
$vals = array_values($hist);
rsort($vals); // Sort max to min
// Now that you have the counts, analyze and decide valid/invalid
var_dump($vals);
当您对某些重复字符串运行此代码时,您将看到差异。下面是您给出的示例字符串中的数组图:$vals
将其与维基百科中马丁·路德·金传记的前两段进行比较:
长尾巴表示许多独特的单词。仍然有一些重复,但一般的形状显示出一些变化。
仅供参考,PHP有一个统计包,如果你要做很多数学运算,如标准偏差,分布建模等,你可以安装。