elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
28 Mayo 2012, 13:09  


Tema destacado: Nueva página de elhacker.net en Google+ Google+

+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web
| | |-+  PHP
| | | |-+  Clase de auto keywords, acentos.
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Clase de auto keywords, acentos.  (Leído 262 veces)
Lightning


Desconectado Desconectado

Mensajes: 728


(ファイナルファンタジー


Ver Perfil WWW
Clase de auto keywords, acentos.
« en: 20 Julio 2011, 21:03 »

Tengo la siguiente clase: http://www.phpclasses.org/package/3245-PHP-Automatically-suggest-keywords-from-content-text.html

Código
<?php
class autokeyword {
 
//declare variables
//the site contents
var $contents;
var $encoding;
//the generated keywords
var $keywords;
//minimum word length for inclusion into the single word
//metakeys
var $wordLengthMin;
var $wordOccuredMin;
//minimum word length for inclusion into the 2 word
//phrase metakeys
var $word2WordPhraseLengthMin;
var $phrase2WordLengthMinOccur;
//minimum word length for inclusion into the 3 word
//phrase metakeys
var $word3WordPhraseLengthMin;
//minimum phrase length for inclusion into the 2 word
//phrase metakeys
var $phrase2WordLengthMin;
var $phrase3WordLengthMinOccur;
//minimum phrase length for inclusion into the 3 word
//phrase metakeys
var $phrase3WordLengthMin;
 
function autokeyword($params, $encoding)
{
 
//get parameters
$this->encoding = $encoding;
 
mb_internal_encoding($encoding);
 
$this->contents = $this->replace_chars($params['content']);
 
// single word
$this->wordLengthMin = $params['min_word_length'];
$this->wordOccuredMin = $params['min_word_occur'];
 
// 2 word phrase
$this->word2WordPhraseLengthMin = $params['min_2words_length'];
$this->phrase2WordLengthMin = $params['min_2words_phrase_length'];
$this->phrase2WordLengthMinOccur = $params['min_2words_phrase_occur'];
 
// 3 word phrase
$this->word3WordPhraseLengthMin = $params['min_3words_length'];
$this->phrase3WordLengthMin = $params['min_3words_phrase_length'];
$this->phrase3WordLengthMinOccur = $params['min_3words_phrase_occur'];
 
//parse single, two words and three words
 
}
 
function get_keywords()
{
$keywords = $this->parse_words().$this->parse_2words().$this->parse_3words();
return substr($keywords, 0, -2);
}
 
//turn the site contents into an array
//then replace common html tags.
function replace_chars($content)
{
//convert all characters to lower case
$content = mb_strtolower($content);
//$content = mb_strtolower($content, "UTF-8");
$content = strip_tags($content);
 
$punctuations = array(',', ')', '(', '.', "'", '"',
'<', '>', '!', '?', '&ldquo;', '&rdquo;', '/', '-',
'_', '[', ']', ':', ';', '+', '=', '#',
'$', '&quot;', '&copy;', '039;', 'nbsp;', 'nbsp',
'&aacute;', '&eacute;', '&bull;', 'bull;', 'aacute', 'eacute', 'uacute', 'ntilde', 'Ntilde', 'oacute', 'iacute', '&iacute;',
'&oacute;', '&uacute', '&nbsp;', '&iquest;', '&hellip;', 'hellip', '&iexcl;', 'iexcl;', 'iquest;', 'iquest', 'iexcl', 'nbsp;', '&ntilde', 'mdash;', '&mdash;', 'mdash', '&mdash', 'ldquo;', '&ldquo;', 'ldquo', '&ldquo', 'rdquo;', '&rdquo;', 'rdquo', '&rdquo', '&Ntilde', '&039;', '&', '&gt;', '&lt;',
chr(10), chr(13), chr(9));
 
$content = str_replace($punctuations, " ", $content);
// replace multiple gaps
$content = preg_replace('/ {2,}/si', " ", $content);
 
return $content;
}
 
//single words META KEYWORDS
function parse_words()
{
//list of commonly used words
// this can be edited to suit your needs
$common = array("m&aacute;s", "039;m");
//create an array out of the site contents
$s = split(" ", $this->contents);
//initialize array
$k = array();
//iterate inside the array
foreach( $s as $key=>$val ) {
//delete single or two letter words and
//Add it to the list if the word is not
//contained in the common words list.
if(mb_strlen(trim($val)) >= $this->wordLengthMin  && !in_array(trim($val), $common)  && !is_numeric(trim($val))) {
$k[] = trim($val);
}
}
//count the words
$k = array_count_values($k);
//sort the words from
//highest count to the
//lowest.
$occur_filtered = $this->occure_filter($k, $this->wordOccuredMin);
arsort($occur_filtered);
 
$imploded = $this->implode(", ", $occur_filtered);
//release unused variables
unset($k);
unset($s);
 
return $imploded;
}
function parse_2words()
{
//create an array out of the site contents
$x = split(" ", $this->contents);
//initilize array
 
//$y = array();
for ($i=0; $i < count($x)-1; $i++) {
//delete phrases lesser than 5 characters
if( (mb_strlen(trim($x[$i])) >= $this->word2WordPhraseLengthMin ) && (mb_strlen(trim($x[$i+1])) >= $this->word2WordPhraseLengthMin) )
{
$y[] = trim($x[$i])." ".trim($x[$i+1]);
}
}
 
//count the 2 word phrases
$y = @array_count_values($y);
 
$occur_filtered = $this->occure_filter($y, $this->phrase2WordLengthMinOccur);
//sort the words from highest count to the lowest.
arsort($occur_filtered);
 
$imploded = $this->implode(", ", $occur_filtered);
//release unused variables
unset($y);
unset($x);
 
return $imploded;
}
 
function parse_3words()
{
//create an array out of the site contents
$a = split(" ", $this->contents);
//initilize array
$b = array();
 
for ($i=0; $i < count($a)-2; $i++) {
//delete phrases lesser than 5 characters
if( (mb_strlen(trim($a[$i])) >= $this->word3WordPhraseLengthMin) && (mb_strlen(trim($a[$i+1])) > $this->word3WordPhraseLengthMin) && (mb_strlen(trim($a[$i+2])) > $this->word3WordPhraseLengthMin) && (mb_strlen(trim($a[$i]).trim($a[$i+1]).trim($a[$i+2])) > $this->phrase3WordLengthMin) )
{
$b[] = trim($a[$i])." ".trim($a[$i+1])." ".trim($a[$i+2]);
}
}
 
//count the 3 word phrases
$b = array_count_values($b);
//sort the words from
//highest count to the
//lowest.
$occur_filtered = $this->occure_filter($b, $this->phrase3WordLengthMinOccur);
arsort($occur_filtered);
 
$imploded = $this->implode(", ", $occur_filtered);
//release unused variables
unset($a);
unset($b);
 
return $imploded;
}
 
function occure_filter($array_count_values, $min_occur)
{
$occur_filtered = array();
foreach ($array_count_values as $word => $occured) {
if ($occured >= $min_occur) {
$occur_filtered[$word] = $occured;
}
}
 
return $occur_filtered;
}
 
function implode($gule, $array)
{
$c = "";
foreach($array as $key=>$val) {
@$c .= $key.$gule;
}
return $c;
}
}
?>

Lo que hace la clase es buscar palabras repetidas y mostrarlas
Tengo el siguiente texto
"La convocatoria de reuni&oacute;n es una notificaci&oacute;n. Reuni&oacute;n. Reuni&oacute;n. Reuni&oacute;n"
Deberia marcarme Reuni&oacute;n, pero lo que me marca es solamente reuni y se corta.

Alguien sabe a que se debe el problema, o como lo podria arreglar?

La palabra es reuni&oacute;n y no reunión solo

Gracias
Salu2


« Última modificación: 20 Julio 2011, 21:06 por Lightning » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Script que busque keywords??
Desarrollo Web
cybersersupremo 2 258 Último mensaje 1 Abril 2005, 09:26
por cybersersupremo
Generador de KeyWords « 1 2 »
Desarrollo Web
eLank0 16 1,583 Último mensaje 8 Enero 2006, 02:47
por imagehosting
keywords, meta tag, optimizacion
Desarrollo Web
camdark 3 511 Último mensaje 5 Noviembre 2006, 01:31
por Red Mx
[SOLUCIONADO] C++: una clase como campo private de otra clase « 1 2 3 »
Programación C/C++
^Winder^ 38 3,874 Último mensaje 6 Octubre 2009, 14:55
por Anibal784
Problema de interacion entre una clase Interfaz y la clase que la llama
Java
yeah69 4 1,031 Último mensaje 21 Mayo 2010, 06:30
por we4rt
Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines