一個非常幼稚的方法是去除常見stopwords從文本,讓你與像「標準」,「JSON」等更有意義的話,你仍然會得到大量的噪音,但是,這樣你就可以考慮像OpenCalais一個服務,可以做你的文字相當複雜的分析。
更新:
好吧,在我以前的答案的鏈接指向實現,但你問一個這麼簡單的一個是在這裏:
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, 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.";
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,而且可能更清潔的(雖然它可能是客戶端慢。)
感謝您的鏈接,我期待這樣的事情。我嘗試了YQL,但不知何故它並沒有認識到很多條款。找到這個名爲Zemanta的網站,這有點不錯,我打算使用這兩個網站併合並我的結果。 – sgomez 2011-01-29 17:42:26
這是我在互聯網上發現的最棒的東西,用了5年左右......謝謝 – AMB 2014-07-24 05:37:49