-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.php
57 lines (52 loc) · 1.24 KB
/
index.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
<?php
/**
* @file
* Test the Algorithm against the authoritative dataset.
*/
ini_set("display_errors", 1);
error_reporting(E_ALL | E_STRICT);
// Time the operation.
$start = microtime(TRUE);
require_once 'Porter2.php';
$dataset = (array) parse_ini_file('Datasets/full.ini', TRUE);
$count = 0;
$true = 0;
$results = array();
foreach ($dataset as $key => $value) {
$outcome = 'FAIL';
$stemmer = new porter2($key);
// Demonstrate passing custom exceptions to the instantiated object.
$stemmer->custom_exceptions = array('mexican' => 'mexic');
$stem = $stemmer->stem();
if ($stem == $value) {
$true++;
$outcome = 'PASS';
}
$count++;
$results[] = array($key, $value, $stem, $outcome);
}
echo $true / $count * 100 . '% accurate results.';
echo '
<table border=1>
<thead>
<tr>
<th>Word</th>
<th>Expected</th>
<th>Outcome</th>
<th>Result</th>
</tr>
</thead>
<tbody>';
foreach ($results as $result) {
if ($result[3] == 'FAIL') {
echo '<tr><td>' . $result[0] . '</td>';
echo '<td>' . $result[1] . '</td>';
echo '<td>' . $result[2] . '</td>';
echo '<td>' . $result[3] . '</td></tr>';
}
}
echo '
</tbody>
</table>';
echo (microtime(TRUE) - $start);
echo ' seconds to complete operation.';