commit | author | age
|
8bd4d9
|
1 |
<?php |
JK |
2 |
include('../../classes/funcs.php'); |
|
3 |
$plik = file('./thesaurus.txt'); |
|
4 |
|
|
5 |
$sqlite = sqlite_open('thesaurus.sqlite') or die(sqlite_error_string(sqlite_last_error($sqlite))); |
|
6 |
|
|
7 |
sqlite_query($sqlite, 'CREATE TABLE thesaurus (slowo varchar(255), podobne TEXT)') or die(sqlite_error_string(sqlite_last_error($sqlite))); |
|
8 |
|
|
9 |
$len = $rows = 0; |
|
10 |
|
|
11 |
foreach($plik as $line) { |
|
12 |
if(substr($line, 0, 1) == '#') { |
|
13 |
continue; |
|
14 |
} |
|
15 |
|
|
16 |
$line = explode(';', iconv('ISO-8859-2', 'UTF-8', rtrim($line))); |
|
17 |
foreach($line as $words) { |
|
18 |
$similar = array(); |
|
19 |
foreach($line as $word) { |
|
20 |
if($word == $words) { |
|
21 |
continue; |
|
22 |
} |
|
23 |
$similar[] = $word; |
|
24 |
} |
|
25 |
$similar = implode(', ', $similar); |
|
26 |
$len = max($len, strlen($words) + strlen($similar) + 1); |
|
27 |
$rows++; |
|
28 |
sqlite_query($sqlite, 'INSERT INTO thesaurus (slowo, podobne) VALUES (\''.funcs::utfToAscii($words).'\', \''.$similar.'\')') or die(sqlite_error_string(sqlite_last_error($sqlite))); |
|
29 |
} |
|
30 |
} |
|
31 |
|
|
32 |
unset($plik); |
|
33 |
|
|
34 |
$fp = fopen('thesaurus.res', 'w'); |
|
35 |
fwrite($fp, $rows.'x'.$len."\n"); |
|
36 |
|
|
37 |
$data = sqlite_unbuffered_query($sqlite, 'SELECT * FROM thesaurus ORDER BY slowo ASC'); |
|
38 |
|
|
39 |
while($en = sqlite_fetch_array($data, SQLITE_ASSOC)) { |
|
40 |
fwrite($fp, str_pad($en['slowo'].';'.$en['podobne'], $len, "\0")); |
|
41 |
} |
|
42 |
|
|
43 |
fclose($fp); |
|
44 |
?> |