caw*_*caw 6 tags twitter spelling
Twitter的趋势主题通常不仅仅包含一个词.但对于复合术语,通常有不同的拼写方式,例如:
"混血王子"/"混血王子"
要查找提及趋势主题的所有更新,您需要所有拼写方式.Twitter这样做:
Twitter的趋势主题管理员http://i26.tinypic.com/hu4uw1.png
您在左侧有主题名称,在右侧有不同的拼写方式.你认为这是手动还是自动完成的?是否可以自动执行此操作?如果是的话:怎么样?
我希望你能帮助我.提前致谢!
我认为Soundex算法正是您所需要的.它可用于根据字符串的声音来比较字符串.或者像维基描述:
Soundex是一种用于通过声音索引名称的语音算法,如英语中所述.目标是将同音异义词编码为相同的表示形式,以便尽管拼写上存在细微差别,但它们可以匹配.
和:
使用该算法[编辑:即用字母和三位数"评级"单词],"Robert"和"Rupert"都返回相同的字符串"R163",而"Rubin"产生"R150"."Ashcraft"收益率为"A261".
祝好运.
我将尝试根据Broken Link的评论回答我自己的问题(谢谢你):
您已从文档数据库中提取包含1到3个单词的短语.在这些引用的短语中有以下短语:
对于每个短语,您将删除所有特殊字符和空格并将字符串设为小写:
$ phrase ='混血王子'; $ phrase = preg_replace('/ [^ az]/i','',$ phrase); $ phrase = strtolower($ phrase); //结果是"halfbloodprince"
当你这样做时,所有3个短语(见上文)都有一个共同的拼写:
所以"halfbloodprince"是父母的短语.您将两者都插入数据库,普通短语和父短语.
要显示像Twitter这样的"趋势主题管理员",请执行以下操作:
// first select the top 10 parent phrases
$sql1 = "SELECT parentPhrase, COUNT(*) as cnt FROM phrases GROUP BY parentPhrase ORDER BY cnt DESC LIMIT 0, 10";
$sql2 = mysql_query($sql1);
while ($sql3 = mysql_fetch_assoc($sql2)) {
$parentPhrase = $sql3['parentPhrase'];
$childPhrases = array(); // set up an array for the child phrases
$fifthPart = round($sql3['cnt']*0.2);
// now select all child phrases which make 20% of the parent phrase or more
$sql4 = "SELECT phrase FROM phrases WHERE parentPhrase = '".$sql3['parentPhrase']."' GROUP BY phrase HAVING COUNT(*) >= ".$fifthPart;
$sql5 = mysql_query($sql4);
while ($sql6 = mysql_fetch_assoc($sql5)) {
$childPhrases[] = $sql3['phrase'];
}
// now you have the parent phrase which is on the left side of the arrow in $parentPhrase
// and all child phrases which are on the right side of the arrow in $childPhrases
}
Run Code Online (Sandbox Code Playgroud)
这是你想到的,Broken Link?这会有用吗?
归档时间: |
|
查看次数: |
1124 次 |
最近记录: |