我想使用php自動從孟加拉文本文件中提取關鍵字。我有用於閱讀孟加拉文本文件的代碼。如何使用PHP從孟加拉文本中提取關鍵字
<?php
$target_path = $_FILES['uploadedfile']['name'];
header('Content-Type: text/plain;charset=utf-8');
$fp = fopen($target_path, 'r') or die("Can't open CEDICT.");
$i = 0;
while ($line = fgets($fp, 1024))
{
print $line;
$i++;
}
fclose($fp) or die("Can't close file.");
我發現下面的代碼來提取最常見的10個關鍵字,但它不適用於孟加拉語文本。我應該做什麼改變?
function extractCommonWords($string){
$stopWords = array('i','a','about','an','and','are','as','at','be','by','com','de','en','for','from','how','in','is','it','la','of','on','or','that','the','this','to','was','what','when','where','who','will','with','und','the','www');
$string = preg_replace('/\s\s+/i', '', $string); // replace whitespace
$string = trim($string); // trim the string
$string = preg_replace('/[^a-zA-Z0-9 -]/', '', $string); // only take alphanumerical characters, but keep the spaces and dashes too…
$string = strtolower($string); // make it lowercase
preg_match_all('/\b.*?\b/i', $string, $matchWords);
$matchWords = $matchWords[0];
foreach ($matchWords as $key=>$item) {
if ($item == '' || in_array(strtolower($item), $stopWords) || strlen($item) <= 3) {
unset($matchWords[$key]);
}
}
$wordCountArr = array();
if (is_array($matchWords)) {
foreach ($matchWords as $key => $val) {
$val = strtolower($val);
if (isset($wordCountArr[$val])) {
$wordCountArr[$val]++;
} else {
$wordCountArr[$val] = 1;
}
}
}
arsort($wordCountArr);
$wordCountArr = array_slice($wordCountArr, 0, 10);
return $wordCountArr;
}
請幫助:(
你能解釋更多的',但它不工作孟加拉語texts'。什麼是確切的問題(你沒有得到10個單詞,或不適當的10個單詞或其他)? –
@ alexander.polomodov孟加拉語是一種語言,他無法獲得用孟加拉語寫成的文本。 –
@ alexander.polomodov喜歡英文示例文本「這是一些文字,這是一些文字,自動售貨機很棒。」它會給下面的輸出 - 一些文字,機,自動售貨機 但孟加拉語文字像 - 「টিপবোঝেনা,টোপবোঝেনা টিপবোঝেনা,কেমনবাপুলোক」輸出頁是空白 –