-
Notifications
You must be signed in to change notification settings - Fork 1
/
read.php
242 lines (230 loc) · 5.83 KB
/
read.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
#echo "Running output";
#$output = shell_exec("sh script.sh");
#echo "Ran output";
#print $output;
#$cmd = escapeshellcmd('python sts1.py');
#$output = shell_exec($cmd);
#echo $output;
#echo $f1;
function clean($string) {
$string = str_replace('[', '', $string); // Replaces all spaces with hyphens.
$string = str_replace(']', '', $string);
return $string;
#return preg_replace('/[^A-Za-z0-9\-\ ]/', '', $string); // Removes special chars.
}
$f1 = fopen('f1', "r") or die("Unable to open feature 1 file!");
$f1_read = fread($f1, filesize('f1'));
$f2 = fopen('f2', "r") or die("Unable to open feature 2 file!");
$f2_read = fread($f2, filesize('f2'));
$result = fopen('result_text', "r") or die("Unable to open result file!");
$result_read = fread($result, filesize('result_text'));
$sentences = fopen('sentence', "r") or die("Unable to open sentences file!");
$sentence_read = fread($sentences, filesize("sentence"));
#echo "hey";
#$f1_read = clean($f1_read);
#$f2_read = clean($f2_read);
#$result_read = clean($result_read);
#$sentence_read = clean($sentence_read);
$f1_read = explode("start", $f1_read);
$f2_read = explode("start", $f2_read);
$result_read = explode("\n", $result_read);
$sentence_read = explode("\n", $sentence_read);
#print_r($f1_read);
#echo "<br> Sentence2 <br>";
#print_r($f1_read);
#print_r($result_read);
#print_r($sentence_read);
#Splitting arrays:
#Sentence 1
#echo "<br>Sentence1<br>";
for($i = 0; $i < count($f1_read); $i++){
#Word POS Tagging
if ($i == 1){
$temp = explode(";", $f1_read[$i]);
array_pop($temp);
#print_r($temp);
$sentence_1_word_type = [];
for($j = 1; $j < count($temp); $j++){
$temp2 = explode(",", $temp[$j]);
$sentence_1_word_type[$temp2[0]] = $temp2[1];
}
#print_r($sentence_1_word_type);
#print_r($temp);
}
#Word Alignment Score
if ($i == 2){
$temp = explode(";", $f1_read[$i]);
array_pop($temp);
#echo "<br> sentenc2 <br>";
#print_r($temp);
$sentence_1_word_align = [];
#echo "<br> result 1<br>";
for($j = 1; $j < count($temp); $j++){
#echo "<br>Value sentence 1<br>";
#print_r($temp[$j]);
$temp2 = explode(",", $temp[$j]);
#print_r($temp2);
$sentence_1_word_align[$temp2[0]] = [$temp2[1], $temp2[2]];
}
#print_r($sentence_1_word_align);
#print_r($temp);
}
#Information Content Score
if ($i == 3){
$temp = explode(";", $f1_read[$i]);
array_pop($temp);
$sentence_1_info_content = [];
for($j = 1; $j < count($temp); $j++){
$temp2 = explode(",", $temp[$j]);
$sentence_1_info_content[$temp2[0]] = $temp2[3];
}
#print_r($sentence_1_info_content);
}
}
#Sentence 2
#echo "<br>Sentence 2<br>";
for($i = 0; $i < count($f2_read); $i++){
#Word POS Tagging
if ($i == 1){
$temp = explode(";", $f2_read[$i]);
array_pop($temp);
#print_r($temp);
$sentence_2_word_type = [];
for($j = 1; $j < count($temp); $j++){
$temp2 = explode(",", $temp[$j]);
$sentence_2_word_type[$temp2[0]] = $temp2[1];
}
#print_r($sentence_2_word_type);
#print_r($temp);
}
#Word Alignment Score
if ($i == 2){
$temp = explode(";", $f2_read[$i]);
array_pop($temp);
#echo "<br> sentenc2 <br>";
#print_r($temp);
$sentence_2_word_align = [];
#echo "<br> result 1<br>";
for($j = 1; $j < count($temp); $j++){
#echo "<br>Value sentence 1<br>";
#print_r($temp[$j]);
$temp2 = explode(",", $temp[$j]);
#print_r($temp2);
$sentence_2_word_align[$temp2[0]] = [$temp2[1], $temp2[2]];
}
#print_r($sentence_2_word_align);
#print_r($temp);
}
#Information Content Score
if ($i == 3){
$temp = explode(";", $f2_read[$i]);
array_pop($temp);
$sentence_2_info_content = [];
for($j = 1; $j < count($temp); $j++){
$temp2 = explode(",", $temp[$j]);
$sentence_2_info_content[$temp2[0]] = $temp2[3];
}
#print_r($sentence_2_info_content);
}
}
#print_r($result_read);
#print_r($sentence_read);
?>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Table Style</title>
<meta name="viewport" content="initial-scale=1.0; maximum-scale=1.0; width=device-width;">
</head>
<body>
<div class="table-title">
<table border = 1 class="table-fill">
<thead>
<tr>
<th class="text-left">Name</th>
<th class="text-left">Sentence 1</th>
<th class="text-left">Sentence 2</th>
</tr>
</thead>
<tbody class="table-hover">
<tr>
<td class="text-left">Input Sentences</td>
<td class="text-left"><?php
echo $sentence_read[0];
?>
</td>
<td class="text-left"><?php
echo $sentence_read[1];
?>
</td>
</tr>
<tr>
<td class="text-left">POS Tagging</td>
<td class="text-left">
<?php
#print_r($sentence_1_word_type);
foreach ($sentence_1_word_type as $key => $value){
echo $key, "=>", $value, "<br>";
}
?>
</td>
<td class="text-left">
<?php
#print_r($sentence_1_word_type);
foreach ($sentence_2_word_type as $key => $value){
echo $key, "=>", $value, "<br>";
}
?>
</td>
</tr>
<tr>
<td class="text-left">Word Align and Score</td>
<td class="text-left">
<?php
foreach ($sentence_1_word_align as $key => $value){
echo $key, "=>", $value[0], " (Score:", $value[1], ")<br>";
}
?>
</td>
<td class="text-left">
<?php
foreach ($sentence_2_word_align as $key => $value){
echo $key, "=>", $value[0], " (Score:", $value[1], ")<br>";
}
?>
</td>
</tr>
<tr>
<td class="text-left">Information Content</td>
<td class="text-left"><?php
foreach ($sentence_1_info_content as $key => $value){
echo $key, "=>", $value, "<br>";
}
?>
</td>
<td class="text-left">
<?php
foreach ($sentence_2_info_content as $key => $value){
echo $key, "=>", $value, "<br>";
}
?>
</td>
</tr>
<tr>
<td class="text-left">Accuracy</td>
<td class="text-left">
<?php
echo $result_read[2], " (Author's method)";
?>
</td>
<td class="text-left">
<?php
echo $result_read[3], " (Our proposed method)";
?>
</td>
</tr>
</tbody>
</table>