大佬教程收集整理的这篇文章主要介绍了php – 从文本块中提取相关标记/关键字,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想要做的是自动选择相关的关键字并创建标签/关键字,因此对于上面的文本,相关的标签应该是:MysqL,PHP,json,jquery,版本控制,oop,web2.0,javascript
更新:
好的,我之前回答中的链接指向了实现,但是你要求一个,所以这里有一个简单的:
function stopWords($text,$stopwords) { // Remove line breaks and spaces from stopwords $stopwords = array_map(function($X){return trim(strtolower($X));},$stopwords); // replace all non-word chars with comma $pattern = '/[0-9\W]/'; $text = preg_replace($pattern,',$text); // Create an array from $text $text_array = explode(",",$text); // remove whitespace and lowercase words in $text $text_array = array_map(function($X){return trim(strtolower($X));},$text_array); foreach ($text_array as $term) { if (!in_array($term,$stopwords)) { $keywords[] = $term; } }; return array_filter($keywords); } $stopwords = file('stop_words.txt'); $text = "requirements - Working kNowledge,on LAMP Environment using Linux,MysqL 5 and PHP 5,- KNowledge of Web 2.0 Standards - Comfortable with JSON - Hands on Experience on working with Frameworks,OOPs - Cross Browser JavascripTing,JQuery etc. - KNowledge of Version Control Software such as sub-version will be preferable."; print_r(stopWords($text,$stopwords));
你可以在这个Gist中看到这个,以及stop_word.txt的内容.
Array ( [0] => requirements [4] => linux [6] => apache [10] => MysqL [13] => PHP [25] => json [28] => frameworks [30] => zend [34] => browser [35] => javascripTing [37] => jquery [38] => etc [42] => software [43] => preferable )
所以,就像我说的那样,这有些天真并且可以使用更多的优化(加上它很慢),但它会从文本中提取更相关的关键字.您还需要对停用词进行一些微调.捕获像Web 2.0这样的术语将非常困难,所以我认为你最好使用像OpenCalais这样可以理解文本并返回实体和引用列表的严肃服务. DocumentCloud依靠这项服务从文件中收集信息.
此外,对于客户端实现,您可以使用JavaScript执行几乎相同的操作,并且可能更清晰(尽管对于客户端来说可能会很慢).
以上是大佬教程为你收集整理的php – 从文本块中提取相关标记/关键字全部内容,希望文章能够帮你解决php – 从文本块中提取相关标记/关键字所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。