“Requirements
– Working knowledge,on LAMP Environment using Linux,Apache 2,
MySQL 5 and PHP 5,
– Knowledge of Web 2.0 Standards
– Comfortable with JSON
– Hands on Experience on working with Frameworks,Zend,OOPs
– Cross Browser Javascripting,JQuery etc.
– Knowledge of Version Control Software such as sub-version will be
preferable.”
我想要做的是自动选择相关的关键字并创建标签/关键字,因此对于上面的文本,相关的标签应该是:MysqL,PHP,json,jquery,版本控制,oop,web2.0,javascript
我怎样才能在PHP / Javascript等中做到这一点?一个headstart真的很有帮助.
更新:
好的,我之前回答中的链接指向了实现,但是你要求一个,所以这里有一个简单的:
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执行几乎相同的操作,并且可能更清晰(尽管对于客户端来说可能会很慢).