Ejemplo n.º 1
0
//ћассив символов дл¤ чистки
$musor = array("\r", "\n", "\t", "\\", '%', '`', '#', '$', '^', '&', '(', ')', '@', '~', '*', '|', '/', '../', './', '[', ']', '{', '}', "\"", "'", '<', '>');
//удал¤ем мусор, замен¤ем пробелом
$text = str_replace($musor, ' ', $text);
//удал¤ем многие пробелы
$space_arr = array('   ', '  ');
$text = str_replace($space_arr, ' ', $text);
//преобразуем все символы окончани¤ предложени¤ в точку
$dot_arr = array('?', '!', '..', '...', ';', ':', '?..', '!..', '!!!');
$text = str_replace($dot_arr, '.', $text);
$text_arr = explode(".", $text);
foreach ($text_arr as $str) {
    if (strlen($str) > 80) {
        $result[] = strtolower(trim($str));
    }
}
$result = array_values(array_unique($result));
unset($text_arr);
$text = implode("|", $result);
unset($result);
$tags = array(array('dict/all/conj.txt', 'conj'), array('dict/all/int.txt', 'int'), array('dict/all/mod.txt', 'mod'), array('dict/all/num.txt', 'num'), array('dict/all/ord.txt', 'ord'), array('dict/all/part.txt', 'part'), array('dict/all/pn.txt', 'pn'), array('dict/all/pn_adj.txt', 'pn_adj'), array('dict/all/pron.txt', 'pron'), array('dict/all/prep.txt', 'prep'), array('dict/all/adv.txt', 'adv'), array('dict/' . $theme . '/noun.txt', 'noun'), array('dict/' . $theme . '/nouns.txt', 'nouns'), array('dict/' . $theme . '/adj.txt', 'adj'), array('dict/' . $theme . '/verb1.txt', 'verb1'), array('dict/' . $theme . '/verb2.txt', 'verb2'), array('dict/' . $theme . '/verb3.txt', 'verb3'), array('dict/' . $theme . '/verb4.txt', 'verb4'), array('dict/' . $theme . '/verb5.txt', 'verb5'), array('dict/all/verb6.txt', 'verb6'));
foreach ($tags as $tag_str) {
    $fname = $tag_str[0];
    $tag = $tag_str[1];
    $file = file($fname);
    $text = ins_tag2($file, $tag, $text);
    unset($file);
}
$text = implode(".\n", explode('|', $text));
file_put_contents('dict/' . $theme . '/base.txt', $text);
exit;
Ejemplo n.º 2
0
function create_base()
{
    global $theme;
    $base_text_fname = 'dict/' . $theme . '/base_text.txt';
    $text = file_get_contents($base_text_fname);
    //Массив символов для чистки
    $musor = array("\r", "\n", "\t", "\\", '%', '`', '#', '$', '^', '&', '(', ')', '@', '~', '*', '|', '/', '../', './', '[', ']', '{', '}', "\"", "'", '<', '>');
    //удаляем мусор, заменяем пробелом
    $text = str_replace($musor, ' ', $text);
    //удаляем многие пробелы
    $space_arr = array('   ', '  ');
    $text = str_replace($space_arr, ' ', $text);
    //преобразуем все символы окончания предложения в точку
    $dot_arr = array('?', '!', '..', '...', ';', ':', '?..', '!..', '!!!');
    $text = str_replace($dot_arr, '.', $text);
    $text_arr = explode(".", $text);
    foreach ($text_arr as $str) {
        if (strlen($str) > 80) {
            $result[] = strtolower(trim($str));
        }
    }
    $result = array_values(array_unique($result));
    unset($text_arr);
    $text = implode("|", $result);
    unset($result);
    $tags = array(array('dict/all/conj.txt', 'conj'), array('dict/all/int.txt', 'int'), array('dict/all/mod.txt', 'mod'), array('dict/all/num.txt', 'num'), array('dict/all/ord.txt', 'ord'), array('dict/all/part.txt', 'part'), array('dict/all/pn.txt', 'pn'), array('dict/all/pn_adj.txt', 'pn_adj'), array('dict/all/pron.txt', 'pron'), array('dict/all/prep.txt', 'prep'), array('dict/all/adv.txt', 'adv'), array('dict/' . $theme . '/noun.txt', 'noun'), array('dict/' . $theme . '/nouns.txt', 'nouns'), array('dict/' . $theme . '/adj.txt', 'adj'), array('dict/' . $theme . '/verb1.txt', 'verb1'), array('dict/' . $theme . '/verb2.txt', 'verb2'), array('dict/' . $theme . '/verb3.txt', 'verb3'), array('dict/' . $theme . '/verb4.txt', 'verb4'), array('dict/' . $theme . '/verb5.txt', 'verb5'), array('dict/all/verb6.txt', 'verb6'));
    foreach ($tags as $tag_str) {
        $fname = $tag_str[0];
        $tag = $tag_str[1];
        $file = file($fname);
        $text = ins_tag2($file, $tag, $text);
        unset($file);
    }
    $text = implode(".\n", explode('|', $text));
    file_put_contents('dict/' . $theme . '/base.txt', $text);
    exit;
}