-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess.php
91 lines (80 loc) · 1.91 KB
/
process.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
89
90
91
<?php
/**
* process.php
*
* Damien Palacio
* Geocomputation - UZH
* 2016
*
**/
require_once('header.php');
$action = null;
if(isset($_GET['action'])) {
$action = $_GET['action'];
}
$file = null;
if(isset($_GET['f'])) {
$file = $_GET['f'];
}
$error = '';
function process($file) {
global $_upload, $_dir_out, $error;
// check it exists
if(!file_exists($_upload.$file)) {
$error = "File doesn't exists";
} else {
// TODO: we don't submit to systems but we convert to TREC eval format --> use RulesEval.
// Then run through Trec_Eval
// $dir_out instead of $_dir_out TEMP
$dir_out = "applis/";
$fileRes = "logs.txt";
$command = /*$dir_out.*/"trec_eval.exe -c ".$dir_out."qrels.txt ".$dir_out."results/input/input.clavin2 > ".$dir_out.$fileRes;
//$command = str_replace(" ", "\ ", $command);
//$command = str_replace("/", "\\", $command);
echo $command;
echo exec($command); //shell_exec
// http://localhost/snerbm/process.php?f=examples.txt
return $fileRes;
}
}
function loadResults($res_file) {
$data = array();
// check it exists
$dir_out = "applis/";
if(!file_exists($dir_out.$res_file)) {
$error = "File doesn't exists";
} else {
$file = fopen($dir_out.$res_file, 'r');
if($file) {
while (!feof($file)) {
$line = fgets($file);
if(!empty($line)) {
$parts = preg_split("/[\t]/", $line);
$data[$parts[0]] = $parts[2];
}
}
}
}
return $data;
}
// Step 2 : Display results
if($action == 'res') {
// Verification of existance of the results
$fileName = checkResults($_results.$file);
$_smarty->assign('error',$error);
if(!empty($error)) {
$tpl = 'process_results.tpl';
}else{
$_smarty->assign('filename',$fileName);
$tpl = 'process.tpl';
}
// Else Step 1 : Process file
}else{
$fileRes = process($file);
$data = loadResults($fileRes);
$_smarty->assign("data", $data);
$tpl = 'process.tpl';
}
$title = 'Process file';
include('footer.php');
?>