ID:1855089
 
Problem description: I want to make an AI system! But I don't know what kind of vars I should declare to start out with. I want the AI to be able to recognize key words in my posts in the OOC and respond in a way I've preset it to. Key words being it's name, or a "nickname" or something like that. Then when I give it a command, it runs whatever verb I told it to do. For example,

Me: Hey Jimbot
Jimbot: Yes, sir?
Me: Go ahead and mute Spammberboy007. He's griefing us too much
sleep(20)
Jimbot: Of course, sir.
(code for Spammerboy007 getting muted here)

I guess I would need efficient and clever use of the findtext proc. I haven't seen any snippets or demos anyone has made.

You could check out Dan's MyHome. It's REALLY old, and I've no idea if it even works anymore, but I remember it being pretty interesting and having some AIish stuff in it. It's been a lot of years since I've looked at it though. I could be wrong...
What you'd probably want to do to start out is have some kind of tokenizer, and parse like old text adventure games used to do. Text adventures use a very simplistic setup where the sentence structures break down like so:

Sentence:
[intransitive verb]
[transitive verb] [direct object]
[transitive verb] [direct object] [preposition] [indirect object]

Imperative:
[character], [sentence]

I think the imperative structure is a good concept, that doesn't require your bot to maintain an "awake" state where it knows you're addressing it. But there are lots of ways to go about it.

First, build a tokenizer. Have it split the string into words and any punctuation you care about. If a period, question mark, or exclamation point is encountered it should probably begin a new sentence.

At this point you need to identify keywords and what they could mean. Words could be adjectives, nouns, verbs, or prepositions. Typically, you'll have a list of recognized words and their possible meanings, and you'll want that to include player names. (A proc could handle that.)

Then, the engine has to try as best it can to map the words to the right parts of speech, and come up with the most likely sentence you mean. For instance:

Jimbot, ban Bob121 for 3 hours.

There are no junk words in that sentence, so all the words would be kept after parsing. Only the period would be discarded, and the comma would count as its own entity. It would then look at different sentence structures, and minus the Jimbot part, it'd find this:

ban [user] for [time]

Any words like "day", "hour", etc. could be parsed as time units, and when parsing a time value it'd simply look at preceding words and treat numbers as adjectives. (You may want to preserve "a", "an", "the", and "some" as they could have meaning here. "A day" for instance could be treated as 1 day.)

As you can see, writing a parser is not trivial, but it actually is a surprisingly approachable problem. In adventure parsers, they also will try to disambiguate if you refer an object by an ambiguous term. For example if there's a red key and a blue one, and you type "get key" and both are gettable, then it would ask "Which key do you mean, the red key or the blue key?" and you'd type in which one. BYOND does something very similar.
I haven't seen any sufficient demos/libs made either. Mostly because people don't associate moderating commands to be handled by a bot, instead they just simply employ "admins".

I've been working on something like this in the past. Basically start you own bot /datum and give it the commands it would need in proc form, Ban, Mute, Edit, etc. Use findtext()/copytext() in the chat form, and you could create a specific form of command like using symboles (#, @, etc. to call the bot).

The way I was looking into it I had a bot, that bot had a few /list variables. One was a preset command list of text strings like "boot, ban, mute, etc" and associated to the bot commands like /bot/proc/boot(atom/target). A second list was used for keywords, which would gather player names, the preset commands, number values (for ban time, or mute time, etc.) and other various things I can't remember.
The bot would basically take the list of keywords in order as they were in the text message and used an equation of priority. It would set player names to #1 priority to target the player first, then it would take the commands as #2 priority to see what needed done to the player (boot, ban, mute, etc), and then it would grab the remaining keywords and decide if it was a value (ban time length, mute time length, etc) and use the values accordingly. If just the player name and command was grabbed, the default values would be used. For example a default ban time could be 1 day, unless you specifiy to the bot like "/bot ban Maximus_Alex2003 for 10 days". The bot would then grab Maximus_Alex2003, find it's reference which would find all player specific /atoms with the name Maximus_Alex2003 (see below for more on this) and then it would grab "ban" and call it's ban(atom/target, length) proc and pass the Maximus_Alex2003 client (if it comes back as a /client) through that proc, then the bot would grab 10 and pass it for "length" in ban(atom/target, length).

As far as the /atoms thing goes, I was making something more designed for /bot and an auto-editor. A /bot that would allow me to type "edit Maximus_Alex2003 health 100" and even "delete GoldSword 10x10y1z" That would allow me to edit things without pulling up any menus, and allow me to delete things based in their name and/or their location.

Unfortunately I don't have the code anymore, nor the HDD it was on.


/EDIT/ Took me 15 minutes to type that, in the meantime Lummox answered it quite nicely.

Also, take a look at the various "parse" demos.
For example:
http://www.byond.com/developer/AlexPeterson/Interpreter
A lot of good links appear to be available here.
Damn, thanks guys. Flick, that demo had 6 errors since it was old but I fixed it and will be referring to the code it has relating to "Impy.

Maximus and Lummox, thanks for the whole rundown. I've looked at both links and they seem like they're going to do me a big help. Although I do need to sift through more of the links on the website you provided, Lummox.

Again, thanks guys!
Adventure command parsing is sort of a very limited subset of natural language processing. You may find some interesting links if you look up natural language processing as well.
In response to Lummox JR
Lummox JR wrote:
Adventure command parsing is sort of a very limited subset of natural language processing. You may find some interesting links if you look up natural language processing as well.


Alright, I'll google that in a little bit.