Addons

Help and bugs.

Addons

Postby robertson » October 30th, 2012, 1:16 pm

Hi,

I recently installed the ASPELL spell checker as I wanted to include it in my ESL-chatbot, but I seem to be having some problems:

On this page, the spell checker corrects the spelling of "I need to practis my englihs"
http://www.linguo.org/grammar-checker/aspell

but when I try to include it in the chatbot it doesn't show. I have tried including it via php- include('aspell.php') -and simply pasting the code of aspell.php into the bot's index.php makes the page not load.

Here's the code:

Code: Select all
<?php
$pspell = pspell_new('en','british','','utf-8',PSPELL_FAST);

function spellCheckWord($word) {
    global $pspell;
    $autocorrect = TRUE;

    // Take the string match from preg_replace_callback's array
    $word = $word[0];
   
    // Ignore ALL CAPS
    if (preg_match('/^[A-Z]*$/',$word)) return $word;

    // Return dictionary words
    if (pspell_check($pspell,$word))
        return $word;

    // Auto-correct with the first suggestion, color green
    if ($autocorrect && $suggestions = pspell_suggest($pspell,$word))
        return '<span style="color:#00FF00;">'.current($suggestions).'</span>';
   
    // No suggestions, color red
    return '<span style="color:#FF0000;">'.$word.'</span>';
}

function spellCheck($string) {
    return preg_replace_callback('/\b\w+\b/','spellCheckWord',$string);
}

echo spellCheck('I need to practis my englihs');
//
?>


Obviously that last line would be:
Code: Select all
echo spellCheck($res);


... but that doesn't work either.

Any ideas?
Thanks
User avatar
robertson
Avid Member
 
Posts: 72
Joined: November 10th, 2011, 4:06 pm

Re: Addons

Postby GeekCaveCreations » November 4th, 2012, 8:22 am

I've never used that script, so off the top of my head, I couldn't tell you, but I see that the script works solo, so if you can provide a link to the code for aspell, I'll do some experimenting to see what I can find. :)
Comforting the disturbed, and disturbing the comfortable
Chat with Morti
User avatar
GeekCaveCreations
Safe, Reliable Insanity, Since 1961
 
Posts: 1115
Joined: April 18th, 2011, 10:52 pm
Location: Nevada, USA

Re: Addons

Postby robertson » November 5th, 2012, 1:15 am

It's installed via SSH and requires root access so if you don't have it then there's little you can do. In any case, I got it from here: http://aspell.net/

Thanks
User avatar
robertson
Avid Member
 
Posts: 72
Joined: November 10th, 2011, 4:06 pm

Re: Addons

Postby GeekCaveCreations » November 5th, 2012, 1:56 am

I see. Sadly, that keeps me from testing it on my remote server, and will keep a lot of other folks from using it at all, since very few folks these days actually have a chance to get root access to their remote servers, through SSH or otherwise. I could probably install it on my Windows box, but it's not likely to give me the same results. :(
Comforting the disturbed, and disturbing the comfortable
Chat with Morti
User avatar
GeekCaveCreations
Safe, Reliable Insanity, Since 1961
 
Posts: 1115
Joined: April 18th, 2011, 10:52 pm
Location: Nevada, USA

Re: Addons

Postby robertson » November 5th, 2012, 8:07 pm

Here we go:

[Mon Nov 05 19:58:07 2012] [error] [client 89.130.173.121] PHP Fatal error: Cannot redeclare spellcheck() (previously declared in /var/www/html/grammar-checker/index.php:64) in /var/www/html/grammar-checker/bot/response_handler.php on line 449

The thing is, I've erased the spellcheck from my tables as I'm using this for my grammar and spelling checker. Bearing that in mind I decided to erase everything on lines 400-450 in response_handler. It seems to work now except for a few bugs which I'll fix over the next few days :-) Thanks!
User avatar
robertson
Avid Member
 
Posts: 72
Joined: November 10th, 2011, 4:06 pm

Re: Addons

Postby GeekCaveCreations » November 5th, 2012, 8:32 pm

You've got the same function (or two functions with the same name) declared in two different files:

1.) in /var/www/html/grammar-checker/index.php at line 64
2.) in /var/www/html/grammar-checker/bot/response_handler.php on line 449

Look at both functions, and see which one you want to use, then delete the other. Then try it again. :)

It could also be that you're include-ing or require-ing a file that shouldn't be, so before you go deleting functions you might want to look into that, first.
Comforting the disturbed, and disturbing the comfortable
Chat with Morti
User avatar
GeekCaveCreations
Safe, Reliable Insanity, Since 1961
 
Posts: 1115
Joined: April 18th, 2011, 10:52 pm
Location: Nevada, USA

Re: Addons

Postby robertson » November 5th, 2012, 9:14 pm

Yeah, I think I've got the hang of it. There are other problems, and using program-o as a grammar checker is maybe not the best option... the chatbot confuses words like fast as it doesn't know whether to interpret it as an adjective, a verb or a noun. So if a user writes:

She fast

The both doesn't know whether it's right, or it should be she fasts, she is fast.
User avatar
robertson
Avid Member
 
Posts: 72
Joined: November 10th, 2011, 4:06 pm

Re: Addons

Postby robertson » November 5th, 2012, 9:16 pm

Deary me, what terrible spelling mistakes!!! Ironic, huh?
User avatar
robertson
Avid Member
 
Posts: 72
Joined: November 10th, 2011, 4:06 pm

Re: Addons

Postby GeekCaveCreations » November 5th, 2012, 10:06 pm

Well, it would take quite a bit of extra coding, but there are MySQL adaptations of WordNet, which is a really good way to get context-based Parts of Speech for a given word. I've not played with it, myself, other than to dink around with other PHP implementations of it (as a user, not as a programmer).

Now []bTHAT[/b] would be a heck of an addon, wouldn't it? :D
Comforting the disturbed, and disturbing the comfortable
Chat with Morti
User avatar
GeekCaveCreations
Safe, Reliable Insanity, Since 1961
 
Posts: 1115
Joined: April 18th, 2011, 10:52 pm
Location: Nevada, USA


Return to Bugs and Help

Who is online

Users browsing this forum: No registered users and 1 guest

cron