diff --git a/includes/playground/better-ajax.php b/includes/tools/better-ajax.php similarity index 97% rename from includes/playground/better-ajax.php rename to includes/tools/better-ajax.php index 5e80e0f..608d3f3 100644 --- a/includes/playground/better-ajax.php +++ b/includes/tools/better-ajax.php @@ -1,128 +1,128 @@ $value) { - $made_from_as_array[$key] = 0; -} - -# Funcion para buscar values que contengan una determinada string dentro de un array +} +mb_internal_encoding('UTF-8'); // Modo UTF-8 +$made_from = array_unique(mb_str_split($made_from)); +$made_from = array_flip($made_from); +ksort($made_from); +foreach ($made_from as $key => $value) { + $made_from_as_array[$key] = 0; +} + +# Funcion para buscar values que contengan una determinada string dentro de un array function my_array_find($needle, $haystack) { foreach ($haystack as $item) { if (strpos($item, $needle) !== FALSE) { return $item; break; - } + } } -} - -# Classe que hace toda la magia +} + +# Classe que hace toda la magia class textFilter -{ - private $max_words = 300; - private $full_text = array(); - private $madefrom_text = array(); - private $resulting_text = array(); - private $length; - private $occurences = array(); - +{ + private $max_words = 300; + private $full_text = array(); + private $madefrom_text = array(); + private $resulting_text = array(); + private $length; + private $occurences = array(); + function add_dictionary( $source_string ) { $source_string = preg_replace('/\s+/', ' ', trim($source_string)); $this->full_text = explode( ' ', $source_string ); $this->full_text = array_unique( $this->full_text ); return $this; - } - + } + function made_from($glypsh_string) { if ( !empty($glypsh_string) ) { - $this->occurences = $glypsh_string; - $glypsh_string = ''; - foreach ($this->occurences as $key => $value) { - $glypsh_string .= $key; - } + $this->occurences = $glypsh_string; + $glypsh_string = ''; + foreach ($this->occurences as $key => $value) { + $glypsh_string .= $key; + } $glypsh_string = preg_replace('/\s+/', '', trim($glypsh_string)); $regex = '/^['.$glypsh_string.']{4,12}$/u'; - $this->madefrom_text = array_slice(array_values(preg_grep($regex, $this->full_text)), 0); + $this->madefrom_text = array_slice(array_values(preg_grep($regex, $this->full_text)), 0); shuffle($this->madefrom_text); } return $this; - } - + } + function set_max_words($number) { if ( !empty($number) ) { $this->max_words = $number; } return $this; - } - + } + function add_initial_words_to_results() { - for ($i = 1; $i <= 5; $i++) { - $this->resulting_text[] = array_shift($this->madefrom_text); - } - # Actualiza Estadisticas - foreach ($this->occurences as $letra => $occurencias) { - $this->occurences[$letra] = substr_count(implode('', $this->resulting_text), $letra); - } - natsort($this->occurences); + for ($i = 1; $i <= 5; $i++) { + $this->resulting_text[] = array_shift($this->madefrom_text); + } + # Actualiza Estadisticas + foreach ($this->occurences as $letra => $occurencias) { + $this->occurences[$letra] = substr_count(implode('', $this->resulting_text), $letra); + } + natsort($this->occurences); return $this; - } - + } + function add_less_frequent_words_to_results() - { - list($pocas) = array_keys($this->occurences); - // echo '
Buscando: '.$pocas[0].' - '; - $new = my_array_find($pocas[0], $this->madefrom_text); - // echo 'Encontrado: '.$new.'
'; - if (!empty($new)) { - $this->resulting_text[] = $new; - if (($key = array_search($new, $this->madefrom_text)) !== false) { + { + list($pocas) = array_keys($this->occurences); + // echo 'Buscando: '.$pocas[0].' - '; + $new = my_array_find($pocas[0], $this->madefrom_text); + // echo 'Encontrado: '.$new.'
'; + if (!empty($new)) { + $this->resulting_text[] = $new; + if (($key = array_search($new, $this->madefrom_text)) !== false) { unset($this->madefrom_text[$key]); - } - } - # Actualiza Estadisticas - foreach ($this->occurences as $letra => $occurencias) { - $this->occurences[$letra] = substr_count(implode('', $this->resulting_text), $letra); - } - natsort($this->occurences); - return $this; - } - + } + } + # Actualiza Estadisticas + foreach ($this->occurences as $letra => $occurencias) { + $this->occurences[$letra] = substr_count(implode('', $this->resulting_text), $letra); + } + natsort($this->occurences); + return $this; + } + function analize_frequency() { return $this; - } - + } + function get_words() { - $this->add_initial_words_to_results(); - for ($i = 5; $i < $this->max_words; $i++) { - $this->add_less_frequent_words_to_results(); - } + $this->add_initial_words_to_results(); + for ($i = 5; $i < $this->max_words; $i++) { + $this->add_less_frequent_words_to_results(); + } return $this; - } - + } + function uppercase() { foreach ($this->resulting_text as $key => $resulting_text) { @@ -138,36 +138,36 @@ function sentencecase() } return $this; } - + function somesentence() { - $sentence_count = 1; + $sentence_count = 1; foreach ($this->resulting_text as $key => $value) { - if ($sentence_count % 6 == 1 ) { - $this->resulting_text[$key] = ucwords($this->resulting_text[$key]); - } - $sentence_count ++; + if ($sentence_count % 6 == 1 ) { + $this->resulting_text[$key] = ucwords($this->resulting_text[$key]); + } + $sentence_count ++; } return $this; - } - + } + function get_results() - { - shuffle($this->resulting_text); + { + shuffle($this->resulting_text); return $this->resulting_text; - } - + } + function get_occurences() { return $this->occurences; - } - -} - + } + +} + // Start Benchmark -$timer_start = microtime(true); - -// Adding Dictionaries +$timer_start = microtime(true); + +// Adding Dictionaries $text =''; if ( $_POST['better_eng_dict'] == "yes" ) { include ("../dictionaries/english.php"); @@ -176,27 +176,27 @@ function get_occurences() if ( $_POST['better_spa_dict'] == "yes" ) { include ("../dictionaries/spanish.php"); $text .= ' '.$spanish; -} - +} + $a = new textFilter(); -$a->add_dictionary($text)->made_from( $made_from_as_array )->set_max_words($max_words)->get_words(); -if ( $_POST['better_sentence'] == "yes" ) $a->sentencecase(); +$a->add_dictionary($text)->made_from( $made_from_as_array )->set_max_words($max_words)->get_words(); +if ( $_POST['better_sentence'] == "yes" ) $a->sentencecase(); if ( $_POST['better_somesentence'] == "yes" ) $a->somesentence(); if ( $_POST['better_uppercase'] == "yes" ) $a->uppercase(); -$resultados = $a->get_results(); - +$resultados = $a->get_results(); + // End Benchmark -$timer_end = microtime(true) - $timer_start; - -echo ''.count($resultados). ' Results ('.number_format($timer_end, 2).' seconds)
'; +$timer_end = microtime(true) - $timer_start; + +echo ''.count($resultados). ' Results ('.number_format($timer_end, 2).' seconds) set at '.$bettersize.'px
'; echo ''.implode(' ', $resultados).'
'; - -echo ''; -print_r( $a->get_occurences() ); -echo ''; -echo '
Improved Adhesion text having a high-frequency of low-frequency letters.
-'.str_word_count($analizerone).'
'; - echo '
'.$total_letters.'
'; - echo '
'.$letra.': -
'; - } else { - echo ''.$letra.': '.$cuenta.'
'; - } - } - echo '-
'; - } else { - $frequency = round($cuenta * 100 / $total_letters, 1); - if ($frequency < 1) { - echo ''.$frequency.'%
'; - } else { - echo ''.$frequency.'%
'; - } - } - } - echo ''; - print_r($made_from_as_array); - echo ''; - echo '
'.str_word_count($analizertwo).'
'; - echo '
'.$total_letters.'
'; - echo '
'.$letra.': -
'; - } else { - echo ''.$letra.': '.$cuenta.'
'; - } - } - echo '-
'; - } else { - $frequency = round($cuenta * 100 / $total_letters, 1); - if ($frequency < 1) { - echo ''.$frequency.'%
'; - } else { - echo ''.$frequency.'%
'; - } } - } - echo ''; - print_r($made_from_as_array); - echo ''; - echo '
'.$analizerone.'
'.$analizertwo.'
Words | '; + echo 'Letters | '; + echo 'Occurrences | '; + echo 'Frequency | '; + echo 'Ordenadas | '; + + echo 'Words | '; + echo 'Letters | '; + echo 'Occurrences | '; + echo 'Frequency | '; + echo 'Ordenadas | '; + echo '
';
+ echo ' '.str_word_count($analizerone).' '; + echo ' | ';
+
+ echo '';
+ $total_letters = strlen(str_replace(' ', '', $analizerone));
+ echo ' '.$total_letters.' '; + echo ' | ';
+
+ echo '';
+ $vocales = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
+ foreach ($vocales as $letra) {
+ $cuenta = substr_count($analizerone, $letra);
+ if ($cuenta == 0) {
+ echo ' '.$letra.': - '; + } else { + echo ''.$letra.': '.$cuenta.' '; + } + } + echo ' | ';
+
+ echo '';
+ $vocales = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
+ foreach ($vocales as $letra) {
+ $cuenta = substr_count($analizerone, $letra);
+ if ($cuenta == 0) {
+ echo ' - '; + } else { + $frequency = round($cuenta * 100 / $total_letters, 1); + if ($frequency < 1) { + echo ''.$frequency.'% '; + } else { + echo ''.$frequency.'% '; + } + } + } + echo ' | ';
+
+ echo '';
+ # Creo un Array limpito, con Frecuencia Zero
+ $made_from = array_unique(mb_str_split($analizerone));
+ $new = my_array_find(' ', $made_from);
+ if (($key = array_search($new, $made_from)) !== false) unset($made_from[$key]);
+ $made_from = array_flip($made_from);
+ ksort($made_from);
+ foreach ($made_from as $key => $value) {
+ $made_from_as_array[$key] = 0;
+ }
+ foreach ($made_from_as_array as $letra => $occurencias) {
+ $made_from_as_array[$letra] = substr_count($analizerone, $letra);
+ }
+ natsort($made_from_as_array);
+ echo ''; + print_r($made_from_as_array); + echo ''; + echo ' | ';
+
+ ####################
+
+ echo '';
+ echo ' '.str_word_count($analizertwo).' '; + echo ' | ';
+
+ echo '';
+ $total_letters = strlen(str_replace(' ', '', $analizertwo));
+ echo ' '.$total_letters.' '; + echo ' | ';
+
+ echo '';
+ $vocales = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
+ foreach ($vocales as $letra) {
+ $cuenta = substr_count($analizertwo, $letra);
+ if ($cuenta == 0) {
+ echo ' '.$letra.': - '; + } else { + echo ''.$letra.': '.$cuenta.' '; + } + } + echo ' | ';
+
+ echo '';
+ $vocales = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
+ foreach ($vocales as $letra) {
+ $cuenta = substr_count($analizertwo, $letra);
+ if ($cuenta == 0) {
+ echo ' - '; + } else { + $frequency = round($cuenta * 100 / $total_letters, 1); + if ($frequency < 1) { + echo ''.$frequency.'% '; + } else { + echo ''.$frequency.'% '; + } } + } + echo ' | ';
+
+ echo '';
+ # Creo un Array limpito, con Frecuencia Zero
+ $made_from = array_unique(mb_str_split($analizertwo));
+ $new = my_array_find(' ', $made_from);
+ if (($key = array_search($new, $made_from)) !== false) unset($made_from[$key]);
+ $made_from = array_flip($made_from);
+ ksort($made_from);
+ foreach ($made_from as $key => $value) {
+ $made_from_as_array[$key] = 0;
+ }
+ foreach ($made_from_as_array as $letra => $occurencias) {
+ $made_from_as_array[$letra] = substr_count($analizertwo, $letra);
+ }
+ natsort($made_from_as_array);
+ echo ''; + print_r($made_from_as_array); + echo ''; + echo ' | ';
+
+ echo '
'.$analizerone.' | ';
+ echo ''.$analizertwo.' | ';
+ echo '