commit | author | age
|
8bd4d9
|
1 |
<?php |
JK |
2 |
class synonimy implements module { |
|
3 |
static function register_cmd() { |
|
4 |
return array( |
|
5 |
'synonimy' => 'cmd_synonimy', |
|
6 |
'synonim' => 'cmd_synonimy', |
|
7 |
'syn' => 'cmd_synonimy', |
|
8 |
's' => 'cmd_synonimy', |
|
9 |
); |
|
10 |
} |
|
11 |
|
|
12 |
static function help($cmd = NULL) { |
|
13 |
if($cmd === NULL) { |
|
14 |
GGapi::putRichText('synonimy ', TRUE); |
|
15 |
GGapi::putRichText('słowo', FALSE, TRUE); |
|
16 |
GGapi::putRichText("\n".' Synonimy słowa '); |
|
17 |
GGapi::putRichText('słowo'."\n", FALSE, TRUE); |
|
18 |
} |
|
19 |
else |
|
20 |
{ |
|
21 |
GGapi::putRichText('synonimy ', TRUE); |
|
22 |
GGapi::putRichText('słowo', FALSE, TRUE); |
|
23 |
GGapi::putRichText(' (aliasy: '); |
|
24 |
GGapi::putRichText('s, syn, synonim', TRUE); |
|
25 |
GGapi::putRichText(')'."\n".' Podaje synonimy słowa '); |
|
26 |
GGapi::putRichText('słowo'."\n\n", FALSE, TRUE); |
|
27 |
GGapi::putRichText('Przykład', FALSE, FALSE, TRUE); |
|
28 |
GGapi::putRichText("\n".'synonimy abecadło'."\n".'synonimy wyspa'); |
|
29 |
} |
|
30 |
} |
|
31 |
|
|
32 |
static function cmd_synonimy($nazwa, $args) { |
|
33 |
if(!$args) { |
|
34 |
GGapi::putText('Funkcja '); |
|
35 |
GGapi::putRichText('synonimy', TRUE); |
|
36 |
GGapi::putRichText(' wymaga argumentu '); |
|
37 |
GGapi::putRichText('słowo'."\n\n", FALSE, TRUE); |
|
38 |
GGapi::putRichText('Przykład', FALSE, FALSE, TRUE); |
|
39 |
GGapi::putRichText("\n".'synonimy abecadło'."\n".'synonimy wyspa'); |
|
40 |
|
|
41 |
return; |
|
42 |
} |
|
43 |
|
|
44 |
$args = funcs::utfToAscii(trim($args)); |
|
45 |
|
|
46 |
$fp = fopen('./data/synonimy/thesaurus.res', 'r'); |
|
47 |
list($rows, $len) = explode('x', trim(fgets($fp, 50))); |
|
48 |
$start = ftell($fp); |
|
49 |
|
|
50 |
$l = 0; |
|
51 |
$p = $rows-1; |
|
52 |
|
|
53 |
while($l<$p) { |
|
54 |
//echo 'L: '.$l.' - P: '.$p."\n"; |
|
55 |
$s = floor(($l+$p)/2); |
|
56 |
|
|
57 |
$poz = $start + ($s*$len); |
|
58 |
fseek($fp, $poz); |
|
59 |
|
|
60 |
$line = fread($fp, $len); |
|
61 |
|
|
62 |
$word = strtok($line, ';'); |
|
63 |
$cmp = strcmp($word, $args); |
|
64 |
|
|
65 |
if($cmp >= 0) { |
|
66 |
//echo 'Right'."\n"; |
|
67 |
$p = $s; |
|
68 |
} |
|
69 |
else |
|
70 |
{ |
|
71 |
//echo 'Left'."\n"; |
|
72 |
$l = $s+1; |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
$poz = $start + ($l*$len); |
|
77 |
fseek($fp, $poz); |
|
78 |
|
|
79 |
$i = 1; |
|
80 |
$return = ''; |
|
81 |
while(TRUE) { |
|
82 |
$line = fread($fp, $len); |
|
83 |
$word = strtok($line, ';'); |
|
84 |
|
|
85 |
if($word != $args) break; |
|
86 |
$return .= "\n".($i++).'. '.rtrim(substr(strstr($line, ';'), 1)); |
|
87 |
} |
|
88 |
|
|
89 |
if(!empty($return)) { |
|
90 |
GGapi::putText('Znalezione synonimy:'.$return); |
|
91 |
} |
|
92 |
else |
|
93 |
{ |
|
94 |
GGapi::putText('Nie znaleziono synonimów podanego słowa'); |
|
95 |
} |
|
96 |
} |
|
97 |
} |
|
98 |
?> |