-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNubeAnalizer.php
88 lines (67 loc) · 1.69 KB
/
NubeAnalizer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace Nube;
class NubeAnalizer {
private $_txtToAnalize;
private $_words = array();
private $min = 0;
private $max = 0;
private $_analizedWords = array();
public function __construct($strTextToAnalize)
{
$this->_txtToAnalize = preg_replace(
"/[^\w\séóíúáñü]/",
"",
strtolower($strTextToAnalize)
);
$this->_words = explode(" ", $this->_txtToAnalize);
}
public function analizar()
{
$tmpArrPalabrasFreq = array();
foreach ( $this->_words as $palabra ) {
if (isset($tmpArrPalabrasFreq[$palabra])) {
$tmpArrPalabrasFreq[$palabra] ++;
} else {
$tmpArrPalabrasFreq[$palabra] = 1;
}
}
asort($tmpArrPalabrasFreq);
foreach ($tmpArrPalabrasFreq as $palabra=>$freq) {
$this->min = $freq;
break;
}
arsort($tmpArrPalabrasFreq);
foreach ($tmpArrPalabrasFreq as $palabra => $freq) {
$this->max = $freq;
break;
}
$this->_analizedWords = $tmpArrPalabrasFreq;
}
public function obtenerPalabras()
{
return array(
"min"=>$this->min,
"max"=>$this->max,
"words"=> $this->_analizedWords
);
}
/*
a, b, c, a, d, e, f
$alpha
foreach ( $alpha as $item) {
echo $item;
}
// a
// b
// c
// a
// d
// e
// f
*/
public function __toString()
{
return "Palabras: " . count($this->_words) . "<br/>" . implode(", ", $this->_words);
}
}
?>