00001
00002
00003
00004
00005
00006
00007
00008 #include <iostream>
00009 #include <iomanip>
00010 #include "cgiClass.h"
00011 #include "AspellWrapperClass.hpp"
00012
00013 using namespace std;
00014
00015 int main( int argc, char ** argv )
00016 {
00017 cgiScript script("text/xml",true);
00018 script << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << endl;
00019 script << "<W3SysService>" << endl;
00020
00021 AspellWrapper speller("en_US");
00022 cgiInput & args = script.ClientArguments();
00023
00024
00025 if( args.count("dictionary") )
00026 {
00027 speller.addWords(args["dictionary"].c_str());
00028 }
00029 if( args.count("word") )
00030 {
00031
00032 if( speller.checkWord(args["word"].c_str()) )
00033 {
00034 script << "<good/>" << endl;
00035 }
00036 else
00037 {
00038 alternatives & list = speller.suggestWords(args["word"].c_str());
00039 for( int l=0; l < list.size(); ++l )
00040 {
00041 script << "<suggest>" << list[l] << "</suggest>" << endl;
00042 }
00043 }
00044 }
00045 else if( args.count("text") )
00046 {
00047 wordlist badWords;
00048 ocString fText = args["text"].c_str();
00049
00050 if( speller.checkText(fText, badWords) )
00051 {
00052 script << "<good/>" << endl;
00053 }
00054 else
00055 {
00056 bool noSuggestions = true;
00057 for( int i = 0; i < badWords.size(); i++ )
00058 {
00059 string & badWord = badWords[i];
00060 alternatives & list = speller.suggestWords(badWord);
00061 for( int l=0; l < list.size(); ++l )
00062 {
00063 script << "<suggest word='"<< badWord <<"'>" << list[l] << "</suggest>" << endl;
00064 noSuggestions = false;
00065 }
00066 }
00067 if( noSuggestions )
00068 {
00069 script << "<good/>" << endl;
00070 }
00071 }
00072 }
00073 else
00074 {
00075 script << "<what>You asked no good question about spelling! Usage: dictionary=name&(word=word||text=text)</what>" << endl;
00076 }
00077 script << "</W3SysService>" << endl;
00078 return 0;
00079 }
00080
00081
00082