-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaggregation.php
More file actions
74 lines (64 loc) · 1.28 KB
/
aggregation.php
File metadata and controls
74 lines (64 loc) · 1.28 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
71
72
73
74
<?php
function aggregateResults($doc_list)
{
$_SESSION['ranked_list'] = removeDuplicates($doc_list);
$_SESSION['ranked_list'] = sortResults($_SESSION['ranked_list']);
}
//function to remove duplicate results
function removeDuplicates($array)
{
for ($i = 0; $i < count($array); $i++)
{
for ($j = $i+1; $j < count($array); $j++)
{
if (strcmp($array[$j][0],$array[$i][0]) === 0)
{
array_splice($array,$j, 1);
}
}
}
return $array;
}
//function to sort results, quicksort with Condorcet fuse
function sortResults($doc_list)
{
if(count($doc_list) <= 1)
return $doc_list;
//select and remove pivot
$pivot = $doc_list[round(count($doc_list)/2)];
unset($doc_list[round(count($doc_list)/2)]);
$low = $high = array();
foreach($doc_list as $key => $doc)
{
$count = 0;
//loop through each set of results
foreach ($_SESSION['results'] as $system)
{
foreach ($system as $result)
{
if ($result[0] == $doc[0])
{
$count++;
break;
}
if ($result[0] == $pivot[0])
{
$count--;
break;
}
}
}
//put doc in lower array
if($count > 0)
{
$low [] = $doc;
}
//put doc in higher array
else
{
$high[] = $doc;
}
}
return array_merge(sortResults($low), array($pivot), sortResults($high));
}
?>