开发者

Simple Natural Language Parser in Objective-C

开发者 https://www.devze.com 2023-04-11 16:54 出处:网络
I\'m building this app for Mac OS X v10.6 I\'m building a text-based adventure and I\'ve created a very simple natural language parser that can process the commands that the user types. So far it wor

I'm building this app for Mac OS X v10.6

I'm building a text-based adventure and I've created a very simple natural language parser that can process the commands that the user types. So far it works great and can parse sentences such as: "take the sword" or "look in the box"

What I'm trying to do is create a list of aliases for different words to make typing commands less strict. So for example "take" could have 开发者_开发问答an alias of "grab" or "go" could have the aliases "move, walk, or travel"

I've tried creating an NSDictionary where the key was the word and the value was an NSArray of aliases. The problem was that when determining if the command entered matched an available command, I would have to reference the aliases with the word that was used for the key.

I want to be able to use any of the aliases to reference any of the other aliases. Does anyone know of a good way to do that?

Another thought I had (but it seems to inefficient) is to store each set of aliases in an array. When parsing I would find the array that contains the word I want to match and try to match all the other words in that array against it.


Check NSLinguisticTagger class (new in iOS 5)


Conceptually, I think you might find it productive to treat all words on the same footing. Let your dictionary have any word from your vocab as a key, and the value numerically encode the interpretation or information that guides interpretation in context.


It works also for OS X http://cutecoder.org/programming/introduction-cocoa-nslinguistictagger-nsbrief-podcast-72/ and check out https://github.com/adib/ColorizeWords

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号