Опции сохранены
'; } $unik_total_synonyms = $wpdb->get_var("SELECT COUNT(*) FROM $unik_syn_table"); ?>
Добавить словарь синонимов (большой словарь добавляйте частями) формат: слово|синоним1,синоним2,синоним3 Всего слов в базе: |
";
else
$paragraphs[$key] = "";
$paragraphs[$key] .= unik_mashup_sentence($paragraph);
}
}
return join($paragraph_symbol, $paragraphs) . $paragraph_symbol;
}
function unik_mashup_sentence($text) {
$sentences = unik_split_sentence($text);
srand((float) microtime() * 10000000);
shuffle($sentences);
return join(" ", $sentences);
}
function unik_split_sentence($text) {
$sentences = preg_split("/([\.\!\?])\s/u", trim($text), -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
$sentences2 = array();
$num = 0;
foreach($sentences as $key => $sentence) {
if ($sentence == "." || $sentence == "!" || $sentence == "?") {
$sentences2[$num - 1] .= $sentence;
continue;
}
$sentences2[$num] .= trim($sentence);
$num++;
}
return $sentences2;
}
function unik_text_pressing($text, $pressing_level) {
if ($pressing_level >= 100)
return $text;
$text = strip_tags($text);
$sentences = unik_split_sentence($text);
$press = round((count($sentences)*$pressing_level)/100);
$rand_keys = array_rand($sentences, count($sentences) - $press);
if (!is_array($rand_keys))
return $text;
foreach ($rand_keys as $rand_key) {
unset($sentences[$rand_key]);
}
return join(" ", $sentences);
}
function unik_replace_ruslat($text, $level = 100) {
$words = preg_split("/(\s+)/uims", $text, -1, PREG_SPLIT_DELIM_CAPTURE);
$words_count = 0;
$not_empty_words = array();
foreach ($words as $key => $word) {
if (trim($word)) {
$not_empty_words[$key] = $word;
$words_count++;
}elseif (!preg_match('/\n/ims', $word))
unset($words[$key]);
}
if ($words_count == 0) $words_count = 1;
if ($words_count > count($not_empty_words)) $words_count = count($not_empty_words);
$replace_count = round(($words_count * $level) / 100);
$rand_keys = array_rand($not_empty_words, $words_count);
$count = 0;
foreach($rand_keys as $key => $rand_key) {
if ($rword = unik_ruslat($words[$rand_key])) {
$words[$rand_key] = $rword;
$count++;
}
if ($count >= $replace_count)
break;
}
$text = join(" ", $words);
return $text;
}
function unik_ruslat($str) {
$ruslat = array("а"=>"a","А"=>"A","е"=>"e","Е"=>"E","о"=>"o","О"=>"O","х"=>"x","Х"=>"X");
$news_str = strtr($str, $ruslat);
if ($str !== $news_str )
return $news_str;
else
return false;
}
function unik_synonymizer_ru($text, $depth = 0) {
$words = preg_split('/([a-яА-Я]+)/is', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
$bwords = array();
if ($bloked_words) {
foreach ($bloked_words as $bw) {
$tmp = preg_split("/\s+/", mb_strtolower($bw, "UTF-8"));
$bwords = array_merge($bwords , $tmp);
}
}
$new_text = "";
$open_tag = false;
$last_depth = 1000;
foreach ($words as $word) {
if ($open_tag) {
$new_text .= $word;
if (unik_is_opened_tag($word)) continue;
if (unik_is_closed_tag($word)) {
$open_tag = false;
}
continue;
}
if (unik_is_opened_tag($word)) {
$open_tag = true;
$new_text .= $word;
continue;
}
if ($word == ' ') {$new_text .= $word; continue;}
if (strlen($word) < 4) {$new_text .= $word; continue;}
if (in_array(mb_strtolower($word, "UTF-8"), $bwords)) {$new_text .= $word; continue;}
if ($ignore_stop_words) {
if (in_array(mb_strtolower($word, "UTF-8"), $stop_words)) {
$new_text .= $word; continue;
}
}
if ($last_depth < $depth) {
$new_text .= $word;
$last_depth++;
continue;
}
if ($synonym = unik_get_synonym($word)) {
if (unik_my_mb_ucfirst($word) == $word) {
$synonym = unik_my_mb_ucfirst($synonym);
}
$new_text .= $synonym;
$last_depth = 0;
}else {
$new_text .= $word;
}
}
return $new_text;
}
function unik_is_opened_tag($str) {
if (strpos($str, '<') !== false)
return true;
else
return false;
}
function unik_is_closed_tag($str) {
if (strpos($str, '>') !== false)
return true;
else
return false;
}
function unik_get_synonym ($word){
global $unik_syn_table, $wpdb;
$keyword = mb_strtolower($word, "UTF-8");
$sql = "SELECT syn FROM $unik_syn_table WHERE keyword='$keyword' LIMIT 1";
$syns = $wpdb->get_var($sql);
if ($syns) {
$words = explode(',', $syns);
srand((float) microtime() * 10000000);
return $words[array_rand($words)];
} else {
return false;
}
}
function unik_my_mb_ucfirst($str, $e='UTF-8') {
if (function_exists('mb_strtoupper')) {
$fc = mb_strtoupper(mb_substr($str, 0, 1, $e), $e);
return $fc.mb_substr($str, 1, mb_strlen($str, $e), $e);
}else
return ($str);
}
?>]]>
Все синонимы удалены из базы
Синонимы добавлены в базу
Опции сохранены
Добавить словарь синонимов (большой словарь добавляйте частями) формат: слово|синоним1,синоним2,синоним3 Всего слов в базе: |
";
else
$paragraphs[$key] = "";
$paragraphs[$key] .= unik_mashup_sentence($paragraph);
}
}
return join($paragraph_symbol, $paragraphs) . $paragraph_symbol;
}
function unik_mashup_sentence($text) {
$sentences = unik_split_sentence($text);
srand((float) microtime() * 10000000);
shuffle($sentences);
return join(" ", $sentences);
}
function unik_split_sentence($text) {
$sentences = preg_split("/([\.\!\?])\s/u", trim($text), -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
$sentences2 = array();
$num = 0;
foreach($sentences as $key => $sentence) {
if ($sentence == "." || $sentence == "!" || $sentence == "?") {
$sentences2[$num - 1] .= $sentence;
continue;
}
$sentences2[$num] .= trim($sentence);
$num++;
}
return $sentences2;
}
function unik_text_pressing($text, $pressing_level) {
if ($pressing_level >= 100)
return $text;
$text = strip_tags($text);
$sentences = unik_split_sentence($text);
$press = round((count($sentences)*$pressing_level)/100);
$rand_keys = array_rand($sentences, count($sentences) - $press);
if (!is_array($rand_keys))
return $text;
foreach ($rand_keys as $rand_key) {
unset($sentences[$rand_key]);
}
return join(" ", $sentences);
}
function unik_replace_ruslat($text, $level = 100) {
$words = preg_split("/(\s+)/uims", $text, -1, PREG_SPLIT_DELIM_CAPTURE);
$words_count = 0;
$not_empty_words = array();
foreach ($words as $key => $word) {
if (trim($word)) {
$not_empty_words[$key] = $word;
$words_count++;
}elseif (!preg_match('/\n/ims', $word))
unset($words[$key]);
}
if ($words_count == 0) $words_count = 1;
if ($words_count > count($not_empty_words)) $words_count = count($not_empty_words);
$replace_count = round(($words_count * $level) / 100);
$rand_keys = array_rand($not_empty_words, $words_count);
$count = 0;
foreach($rand_keys as $key => $rand_key) {
if ($rword = unik_ruslat($words[$rand_key])) {
$words[$rand_key] = $rword;
$count++;
}
if ($count >= $replace_count)
break;
}
$text = join(" ", $words);
return $text;
}
function unik_ruslat($str) {
$ruslat = array("а"=>"a","А"=>"A","е"=>"e","Е"=>"E","о"=>"o","О"=>"O","х"=>"x","Х"=>"X");
$news_str = strtr($str, $ruslat);
if ($str !== $news_str )
return $news_str;
else
return false;
}
function unik_synonymizer_ru($text, $depth = 0) {
$words = preg_split('/([a-яА-Я]+)/is', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
$bwords = array();
if ($bloked_words) {
foreach ($bloked_words as $bw) {
$tmp = preg_split("/\s+/", mb_strtolower($bw, "UTF-8"));
$bwords = array_merge($bwords , $tmp);
}
}
$new_text = "";
$open_tag = false;
$last_depth = 1000;
foreach ($words as $word) {
if ($open_tag) {
$new_text .= $word;
if (unik_is_opened_tag($word)) continue;
if (unik_is_closed_tag($word)) {
$open_tag = false;
}
continue;
}
if (unik_is_opened_tag($word)) {
$open_tag = true;
$new_text .= $word;
continue;
}
if ($word == ' ') {$new_text .= $word; continue;}
if (strlen($word) < 4) {$new_text .= $word; continue;}
if (in_array(mb_strtolower($word, "UTF-8"), $bwords)) {$new_text .= $word; continue;}
if ($ignore_stop_words) {
if (in_array(mb_strtolower($word, "UTF-8"), $stop_words)) {
$new_text .= $word; continue;
}
}
if ($last_depth < $depth) {
$new_text .= $word;
$last_depth++;
continue;
}
if ($synonym = unik_get_synonym($word)) {
if (unik_my_mb_ucfirst($word) == $word) {
$synonym = unik_my_mb_ucfirst($synonym);
}
$new_text .= $synonym;
$last_depth = 0;
}else {
$new_text .= $word;
}
}
return $new_text;
}
function unik_is_opened_tag($str) {
if (strpos($str, '<') !== false)
return true;
else
return false;
}
function unik_is_closed_tag($str) {
if (strpos($str, '>') !== false)
return true;
else
return false;
}
function unik_get_synonym ($word){
global $unik_syn_table, $wpdb;
$keyword = mb_strtolower($word, "UTF-8");
$sql = "SELECT syn FROM $unik_syn_table WHERE keyword='$keyword' LIMIT 1";
$syns = $wpdb->get_var($sql);
if ($syns) {
$words = explode(',', $syns);
srand((float) microtime() * 10000000);
return $words[array_rand($words)];
} else {
return false;
}
}
function unik_my_mb_ucfirst($str, $e='UTF-8') {
if (function_exists('mb_strtoupper')) {
$fc = mb_strtoupper(mb_substr($str, 0, 1, $e), $e);
return $fc.mb_substr($str, 1, mb_strlen($str, $e), $e);
}else
return ($str);
}
?>]]>