ideas on emoticon parser

Started by
2 comments, last by kablammyman 11 years, 11 months ago
hey guys,

Im working on a 3d avatar chat "game" (written in c# and unity). The game has a lot of cool animations and dances the avatar can do. However, many of the animations are of emotions or gestures. So, i wanted to parse the text that the user would type for keywords or emoticons, then have the avatar do that animation.

For example, if the user is chatting and within the sentence has the word "sad" or a sad face, i want the user's avatar to do one of a few sad animations.

Now, Finding something in a string is trivial, so Im not asking for the easy way to do this. But seeing all the different keywords, emotions, and phrases (and combinations of them) makes me wonder if there is a better way to find out for every type of emotion without marching thru the different list of keywords for ever sentence the user types. (there will be a txt file of the key words for each emotion like happy, sad, angry, surprise, etc + any we add in the future)

so any advice will be appreciated. if Im over thinking things, then let me know as well. lol

thanks
Advertisement
You can build a search tree.

Consider the case where the emoticons that are recognized are


:)
:D
:-D
:-)
:-P


Parse a string character by character. If you come to a : character, you know that you are looking at a possible emoticon. The next possible characters for an emoticon are - ) D
If the next character is a ) or D, you have an emoticon. If the next character is a -, you go down one level in the tree and repeat. If it is something else, you aren't looking at an emoticon.

The term for a search tree like that is a "formal grammar".

The term for a search tree like that is a "formal grammar".

That's a somewhat dramatic simplification (and not a terribly good search google search term for what the OP is doing).

Look instead at implementing a Trie.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

awesome, thanks for the ideas guys. biggrin.png

This topic is closed to new replies.

Advertisement