-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprobability.algorithm.handler.php
More file actions
70 lines (54 loc) · 1.46 KB
/
probability.algorithm.handler.php
File metadata and controls
70 lines (54 loc) · 1.46 KB
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
<?php
ini_set('memory_limit', substr('0223705295M', 1));
error_reporting(E_ALL^E_NOTICE);
#Source any online thesaurus
include_once 'bighugelabs_class.php';
$synonyms = new BigHugeLabs();
$keywords = "test";
class probabilityMatrix
{
#private vars
var
$prob_array = array(),
$p_array = array();
#flatten each array
public function makeRecursive( $ar = "" )
{
$toflat = array(
$ar
);
$res = array();
while ( ( $r = array_shift( $toflat ) ) !== NULL ) {
foreach ( $r as $v ) {
if ( is_array( $v ) ) {
$toflat[] = $v;
} else {
$res[] = $v;
}
}
}
return $res;
}
#Asort by probability
public function returnProbability( $array = array())
{
$array = $this->makeRecursive( $array );
$this->p_array = array_count_values( $array );
foreach ( $this->p_array as $words => $val ) {
$this->prob_array[$words] = $val/array_sum( $this->p_array ) * 100;
}
arsort( $this->prob_array );
return $this->prob_array;
}
}
$pm = new probabilityMatrix;
/* SKIP FOR EASE
$array = $pm->makeRecursive( $synonyms->getKeywordArray( $keywords ) );
foreach ( $array as $word ) {
$secondary_array[] = $synonyms->getKeywordArray( $word );
}
$test_array = array_merge( $array, $secondary_array );
*/
include_once 'test.word.array.php';
global $test_array;
print_r( $pm->returnProbability( $test_array ) );