Debian Codegraph @

php/phpAiksaur_embedded.php

raw
1 <?
2 /*
3 * phpAiksaur - A Web Interface to the AikSaurus Thesaurus Library
4 * Copyright (C) 2001 by Jared Davis
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21
22 // Define this as the path to your aiksaurus executable:
23 define(EXEC_PATH, "./CommandLineDemo");
24
25 // This path also needs to be correct. Usually you just put
26 // phpAiksaurusClass.php in the same directory with this file.
27 include_once("phpAiksaur.php");
28
29
30
31
32
33
34 define(LINK_URL, $PHP_SELF . "?lookup=");
35
36 function makeLink($word)
37 {
38 return "<a href=\"" . LINK_URL . rawurlencode($word) . "\">$word</a>";
39 }
40
41
42 function printResults($res, $title)
43 {
44 if (count($res) == 0)
45 return;
46
47 switch( count($res) % 4 )
48 {
49 case 0:
50 case 3:
51 $stop1 = count($res) / 4;
52 $stop2 = 2 * $stop1;
53 $stop3 = 3 * $stop1;
54 $stop4 = count($res);
55 break;
56
57 case 1:
58 $stop1 = (count($res) / 4);
59 $stop2 = $stop1 + count($res) / 4;
60 $stop3 = $stop2 + count($res) / 4;
61 $stop4 = count($res);
62 break;
63
64 case 2:
65 $stop1 = count($res) / 4;
66 $stop2 = 1 + $stop1 + count($res) / 4;
67 $stop3 = $stop2 + count($res) / 4;
68 $stop4 = count($res);
69 break;
70 }
71
72 print "<table border=\"0\" width=\"90%\" align=\"center\" cellpadding=\"5\">";
73 print "<tr valign=\"top\">";
74 print "<td width=\"20%\" bgcolor=\"#eeeeee\" valign=\"middle\" align=\"center\">";
75 print "<big>" . count($res) . " $title</big>";
76 print "</td><td width=\"20%\">";
77 for($i = 0;$i < $stop1;++$i)
78 {
79 print makeLink($res[$i]) . "<br>";
80 }
81 print "</td><td width=\"20%\">";
82 for(; $i < $stop2; ++$i)
83 {
84 print makeLink($res[$i]) . "<br>";
85 }
86 print "</td><td width=\"20%\">";
87 for(; $i < $stop3; ++$i)
88 {
89 print makeLink($res[$i]) . "<br>";
90 }
91 print "</td><td width=\"20%\">";
92 for(; $i < $stop4; ++$i)
93 {
94 print makeLink($res[$i]) . "<br>";
95 }
96 print "</td></tr></table><br>";
97 }
98
99
100 $thesaurus = new phpAiksaur(EXEC_PATH);
101
102 if ($thesaurus->doSearch($lookup))
103 {
104 print "<h2>Synonyms for ";
105 print "<font color=\"#ff0000\">";
106 print ucwords(strtolower($lookup));
107 print "</font></h2>\n";
108
109
110 printResults($thesaurus->getNouns(), "Nouns");
111 printResults($thesaurus->getVerbs(), "Verbs");
112 printResults($thesaurus->getAdjectives(), "Adjectives");
113 printResults($thesaurus->getAdverbs(), "Adverbs");
114 printResults($thesaurus->getOthers(), "Others");
115 printResults($thesaurus->getUnknowns(), "Unknowns");
116 }
117
118
119 else
120 {
121 print "<h2>No known synonyms for ";
122 print "<font color=\"#ff0000\">";
123 print ucwords(strtolower($lookup));
124 print "</font></h2>\n";
125
126 $similar = $thesaurus->getSimilar();
127
128 print "<p>Alphabetically nearby known words:";
129 print "<ul>";
130 for($i = 0;$i < count($similar);++$i)
131 {
132 print "<li>" . makeLink($similar[$i]) . "</li>";
133 }
134 print "</ul>";
135 }
136
137 ?>