我想使用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喜欢英文示例文本“这是一些文字,这是一些文字,自动售货机很棒。”它会给下面的输出 - 一些文字,机,自动售货机 但孟加拉语文字像 - “টিপবোঝেনা,টোপবোঝেনা টিপবোঝেনা,কেমনবাপুলোক”输出页是空白 –