BeBot - An Anarchy Online and Age Of Conan chat automaton

Archive => Anarchy Online Archive => 0.5.x Custom/Unofficial Modules => Topic started by: Temar on February 12, 2008, 05:28:15 am

Title: Smarter Bot :D
Post by: Temar on February 12, 2008, 05:28:15 am
Changes

This is in Normal Releases of Bebot
Title: Re: Smarter Bot :D
Post by: Wolfbiter on February 12, 2008, 11:39:51 am
Adding s at the non-found command doesn't make your bot smart at all.
Do some string compare instead, and if the result is over a certain %, and only one command is above that %, assume it's it.

Code: [Select]
function cmpr($one, $two) {
//How many % loss for each length difference? Substracted at the end.
$loss["diff"] = 10;
//How many % loss for a wrong char? It's 100-(this no.) for each wrong char.
$loss["char"] = 75;
//How many % loss for a wrong char, but the one before/after matches?
$loss["oneoff"] = 25;
$return = 0;

if (strlen($one) <= strlen($two)) {
$first = $one;
$second = $two;
$diff = strlen($two) - strlen($one);
}
else {
$first = $two;
$second = $one;
$diff = strlen($one) - strlen($two);
}
for ($i=0;$i<strlen($first);$i++) {
if ($first{$i} == $second{$i})
$return += 100;
elseif($first{$i} == $second{$i-1})
$return += 100-$loss["oneoff"];
elseif($first{$i} == $second{$i+1})
$return += 100-$loss["oneoff"];
else
$return += 100-$loss["char"];
}
return round(($return / strlen($first)) - ($loss["diff"] * $diff));
}

Ran a test on some different words (typos and different commands). A result of >75% should be accurate enough to assume it's a simple typo.
Code: [Select]
whois - ehois: 90%
items - item: 90%
items - tiems: 90%
alts - alt: 90%
items - tiem: 78%
xp - is: 50%
id - is: 75%
axp - apf: 75%
join - kick: 56%
level - guest: 60%
calc - city: 63%
tokens - whois: 50%
lvl - alts: 57%
cloak - calc: 59%
Title: Re: Smarter Bot :D
Post by: Tichy on February 12, 2008, 06:13:38 pm
Ever thought about the soundex or methaphone functions of php to compare the commands pronunciation? Never tried by myself...
Title: Re: Smarter Bot :D
Post by: Temar on February 12, 2008, 06:25:20 pm
wolf wont that have to compare every command to the word you used
Title: Re: Smarter Bot :D
Post by: Blueeagle on February 12, 2008, 08:13:22 pm
I would suggest using similar_text() (http://php.net/similar_text). Soundex and metaphone will most likely not catch instances where the first and second letter have been exchanged for example !tiem instead of !item.

For short commands like "is" typed as "si" all would fail. For longer commands like "member" vs "members" all would succeed.

There is some discussion as to the speed of similar_text() but that, as I understand it, is only relevant for really long (20000 characters+) texts.

The question is how one would go about implementing this. There are two scenarios that I see as fesable.

The first is to run trough the command list and check for an exact match like we're doing today. If no matches are found run trough again but this time check for the best match with similar text. If no command match more than 75% reply with a command not found. If one or more are matched with 75% or higher tell the user that we're assuming the best match. If two commands score exactly the same and both are above 75% tell the user that there are two possible matches and create a link to each of the two with the parameters as they were passed.

The second is to process commands with similar_text() and save the best match in a temporary variable array. If no 100% are found find the best match and if it's above 75% assume that it's the one the user wanted.


The danger here is when the command "lick" is removed and someone with access to the "kick" command hasn't been notified. So when that person tries to !lick someuser that user will be unexpectedly booted. To remedy this one can define a treshold for commands so that !kick will have to be 100% exact while !members can be 92% which is the difference between "member" and "members" (93% if you incude the command character)


The code I used to test this can be found on my server (http://php.tregt.net/similar.php).

I hope that helps.
Title: Re: Smarter Bot :D
Post by: Glarawyn on February 12, 2008, 09:21:30 pm
Or you know...just trow an error message and make the user type the command as intended by the developer.  :P
Title: Re: Smarter Bot :D
Post by: Wolfbiter on February 13, 2008, 12:03:47 am
soundex() and metaphone is for illiterate problems, not typos.
similar_text() would be a lot better than mine, but I needed to kill some time and it gave me something to do ;).

If an exact match is found, another loop would go over using similar_text() compare, and any match over set % is stored, and when it's done the highest (if any) will be used. More with same, just output a blob as Blue said.
It shouldn't be hard to implement it either, and don't think it would be slow, not hard to try.

And Glara... this is a post about a smarter bot, not smarter user... and it's so much easier to make the bot smarter. The users will always be dimwits...
Title: Re: Smarter Bot :D
Post by: Alreadythere on February 13, 2008, 06:11:36 pm
The option to use something like similar_text() doesn't sound bad.
Title: Re: Smarter Bot :D
Post by: Temar on February 13, 2008, 06:26:48 pm
ive done it ill be posting code in about 5 min :p
Title: Re: Smarter Bot :D
Post by: Temar on February 13, 2008, 06:51:24 pm
Done
Title: Re: Smarter Bot :D
Post by: Temar on February 15, 2008, 05:20:11 am
Corrected a Spelling Error
Added option to Turn off Disabled Commands Errors msg
Fixed bug were it did a search even tho it had found the command but user didnt have permission to use

This post = Total Posts: 8000 ;D
Title: Re: Smarter Bot :D
Post by: Blueeagle on February 15, 2008, 12:06:31 pm
Or you know...just trow an error message and make the user type the command as intended by the developer.  :P

Well technically this sort of thing wouldn't have been neccessary if a codingstandard has been set so that there wouldn't be mixed single and plural. (ie. all would have been !alt and !member and so on or all would have been !alts and !members) (I would advocate the first)
Title: Re: Smarter Bot :D
Post by: porter on February 16, 2008, 01:05:22 am
And Glara... this is a post about a smarter bot, not smarter user... and it's so much easier to make the bot smarter. The users will always be dimwits...

Then again, if people learn to expect a bot to understand any mistyped command they throw at it they will get even more lazy and dimwitted and make their friends the same by telling them to use an essentially wrong command to achieve something "because it is close enough" and "it works".

You know the apparently American habit of typing something that maybe resembles a word and adding a (sp?) after it to show your ignorance while at the same time making believe it is OK... ;)

[edit] And I agree with Blueeagle above, as well.

[edit2] "help" is your friend, if the choice was mine I'd focus more on up to date help files of all the bot commands instead of adding an AI to parse users trying to guess what that undocumented feature was... That would be a smart bot, one that actually knows all its commands and can tell the user how to use them.
Title: Re: Smarter Bot :D
Post by: Blueeagle on February 16, 2008, 05:28:10 am
Don't get me wrong. I don't think cleaning the mess up with such a feature is good. However we should go trough the commands and change them so that none are plural and tell the users that the command now has changed.

One could do this by returning a blob telling the person the correct command and throwing in a link that would execute the command the user wanted instead of just giving the person the result they tried to achieve in the first place.

That would limit forcing users to re-type but still be annoying enough that the next time the user would use the correct command.
Title: Re: Smarter Bot :D
Post by: Wolfbiter on February 16, 2008, 06:52:30 pm
The idea is to make the bot react to simple typos (ehois, tiems, etc) and not to make people lazy and dumber, even if that's a side effect. Nothing in this world is perfect.
But it's really hard to make a function (unless you predefine all typos) that'll know when it's a typo or when it's a dumb user.
Title: Re: Smarter Bot :D
Post by: Blueeagle on February 17, 2008, 05:51:55 am
But it's really hard to make a function (unless you predefine all typos) that'll know when it's a typo or when it's a dumb user.
Not really.
Code: [Select]
if($faction == 'clan')
  return(stupid_user_detected($player);
:P :P :P
Title: Re: Smarter Bot :D
Post by: Temar on February 17, 2008, 09:01:18 am
that must be a Bug it should be "Omni"
Title: Re: Smarter Bot :D
Post by: Temar on February 21, 2008, 12:20:34 am
Updated to Current SVN version
also fixed bug with ext privgroup output
Title: Re: Smarter Bot :D
Post by: Alreadythere on February 21, 2008, 02:53:58 pm
Command matching and Temar's access denied error notifications commited to SVN. The default for all those settings is OFF.
Title: Re: Smarter Bot :D
Post by: Temar on February 25, 2008, 07:41:17 am
the commands have become case sensitive
the command the user did wasnt changed to lowercase
Fixed

i also noticed

!online = works
!Online = works
!OnlinE = doesnt work

was going to ask why, but as i was typing this i relised why.
it was similar check which was also case sensitive and 2 capitol letters made it below 75%

so i fixed that too
Title: Re: Smarter Bot :D
Post by: Alreadythere on February 25, 2008, 11:53:38 am
Thanks, fixed in SVN.
Title: Re: Smarter Bot :D
Post by: Temar on February 26, 2008, 08:26:37 am
u missed a bug
$com is used and i think that is serpose to be $cmd
Title: Re: Smarter Bot :D
Post by: Alreadythere on February 26, 2008, 11:30:38 am
Thanks, fixed.
Title: Re: Smarter Bot :D
Post by: Xenixa on March 24, 2008, 11:48:55 am
Or you know...just trow an error message and make the user type the command as intended by the developer.  :P

Well technically this sort of thing wouldn't have been neccessary if a codingstandard has been set so that there wouldn't be mixed single and plural. (ie. all would have been !alt and !member and so on or all would have been !alts and !members) (I would advocate the first)

Ooh, ouch, bad examples. I know I haven't been around in awhile or ran a Bebot in about a year now for that matter(I'm just here catching up on changes so I'm not sure if these commands still work in the same manner) but !alts was for listing Alts. and !alt for adding and removing Alts. Two different commands. Same with !members and !member(one for listing, one for manual adding or removing). So it's not so much a case of mixing singular and plural usage as it is a grouping of like commands.

I'm with Glara, just type the commands properly and theres not a problem. Weened my teeth on MS-DOS 3.0... it was brutal when you typed a command wrong.  ;)

This is a pretty nifty module however, it's not without merit and it's definitely a nice bit of coding for those that want to use it.
SimplePortal 2.3.7 © 2008-2024, SimplePortal