| 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 |
# EXEC_PATH |
| 23 |
# --------- |
| 24 |
# Define this to be the path to your AikSaurus CommandLineDemo program. |
| 25 |
# |
| 26 |
# For example: |
| 27 |
# /usr/local/apache/htdocs/aiksaurus/CommandLineDemo |
| 28 |
# |
| 29 |
# You should really use an absolute path here. |
| 30 |
# |
| 31 |
define(EXEC_PATH, "./CommandLineDemo"); |
| 32 |
|
| 33 |
|
| 34 |
class phpAiksaur |
| 35 |
{ |
| 36 |
var $d_word; |
| 37 |
var $d_similar; |
| 38 |
var $d_error; |
| 39 |
|
| 40 |
var $d_synonyms; |
| 41 |
var $d_nouns; |
| 42 |
var $d_verbs; |
| 43 |
var $d_adjectives; |
| 44 |
var $d_adverbs; |
| 45 |
var $d_others; |
| 46 |
var $d_unknowns; |
| 47 |
|
| 48 |
// getSynonyms: returns an array of all synonyms. |
| 49 |
function getSynonyms() |
| 50 |
{ |
| 51 |
return $this->d_synonyms; |
| 52 |
} |
| 53 |
|
| 54 |
// getNouns: returns an array of all nouns. |
| 55 |
function getNouns() |
| 56 |
{ |
| 57 |
return $this->d_nouns; |
| 58 |
} |
| 59 |
|
| 60 |
// getVerbs: returns an array of all verbs. |
| 61 |
function getVerbs() |
| 62 |
{ |
| 63 |
return $this->d_verbs; |
| 64 |
} |
| 65 |
|
| 66 |
// getAdjectives: returns an array of all adjectives. |
| 67 |
function getAdjectives() |
| 68 |
{ |
| 69 |
return $this->d_adjectives; |
| 70 |
} |
| 71 |
|
| 72 |
// getAdverbs: returns an array of all adverbs. |
| 73 |
function getAdverbs() |
| 74 |
{ |
| 75 |
return $this->d_adverbs; |
| 76 |
} |
| 77 |
|
| 78 |
// getOthers: returns an array of all words of other classification. |
| 79 |
function getOthers() |
| 80 |
{ |
| 81 |
return $this->d_others; |
| 82 |
} |
| 83 |
|
| 84 |
// getUnknowns: returns an array of words of unknown classification. |
| 85 |
function getUnknowns() |
| 86 |
{ |
| 87 |
return $this->d_unknowns; |
| 88 |
} |
| 89 |
|
| 90 |
// getSimilar: returns an array of alphabetically nearby words. |
| 91 |
function getSimilar() |
| 92 |
{ |
| 93 |
return $this->d_similar; |
| 94 |
} |
| 95 |
|
| 96 |
// getCount: returns number of synonyms found for word. |
| 97 |
function getCount() |
| 98 |
{ |
| 99 |
return count($this->d_synonyms); |
| 100 |
} |
| 101 |
|
| 102 |
// getWord: returns current word being searched for. |
| 103 |
function getWord() |
| 104 |
{ |
| 105 |
return $this->d_word; |
| 106 |
} |
| 107 |
|
| 108 |
// getError: returns error description from core library if error occured. |
| 109 |
function getError() |
| 110 |
{ |
| 111 |
return $this->d_error; |
| 112 |
} |
| 113 |
|
| 114 |
// doSearch: returns TRUE if word found, FALSE if word not found. |
| 115 |
function doSearch($word) |
| 116 |
{ |
| 117 |
$this->d_word = $word; |
| 118 |
$this->d_synonyms = $this->d_similar = |
| 119 |
$this->d_nouns = $this->d_verbs = $this->d_adjectives = |
| 120 |
$this->d_adverbs = $this->d_others = $this->d_unknown = array(); |
| 121 |
$this->d_error = 0; |
| 122 |
|
| 123 |
$command = EXEC_PATH . " \"$word\""; |
| 124 |
exec($command, $res); |
| 125 |
|
| 126 |
if (ereg("^Error", $res[0])) // error with thesaurus program. |
| 127 |
{ |
| 128 |
print "<h3>Internal Aiksaurus Error</h3>"; |
| 129 |
print "<pre>"; |
| 130 |
for($i = 0;$i < count($res);++$i) |
| 131 |
{ |
| 132 |
$this->d_error .= $res[$i]; |
| 133 |
print $res[$i]; |
| 134 |
} |
| 135 |
print "</pre>"; |
| 136 |
return false; |
| 137 |
} |
| 138 |
|
| 139 |
if (!ereg("^Not found", $res[0])) // synonyms were found. |
| 140 |
{ |
| 141 |
for($i = 0;$i < count($res);++$i) |
| 142 |
{ |
| 143 |
$word = substr($res[$i], 7, strlen($res[$i]) - 7); |
| 144 |
$this->d_synonyms[] = $word; |
| 145 |
|
| 146 |
if ($res[$i][0] == 'N') |
| 147 |
$this->d_nouns[] = $word; |
| 148 |
|
| 149 |
if ($res[$i][1] == 'V') |
| 150 |
$this->d_verbs[] = $word; |
| 151 |
|
| 152 |
if ($res[$i][2] == 'J') |
| 153 |
$this->d_adjectives[] = $word; |
| 154 |
|
| 155 |
if ($res[$i][3] == 'D') |
| 156 |
$this->d_adverbs[] = $word; |
| 157 |
|
| 158 |
if ($res[$i][4] == 'O') |
| 159 |
$this->d_others[] = $word; |
| 160 |
|
| 161 |
if ($res[$i][5] == 'U') |
| 162 |
$this->d_unknowns[] = $word; |
| 163 |
} |
| 164 |
|
| 165 |
return true; |
| 166 |
} |
| 167 |
|
| 168 |
else // no synonyms found. |
| 169 |
{ |
| 170 |
for($i = 1;$i < count($res);++$i) |
| 171 |
{ |
| 172 |
$this->d_similar[] = htmlentities(trim($res[$i])); |
| 173 |
} |
| 174 |
|
| 175 |
return false; |
| 176 |
} |
| 177 |
} |
| 178 |
}; |
| 179 |
|
| 180 |
|
| 181 |
?> |