# Embed IF text parser in another game?

Are there any existing interactive fiction text parsing engines that I can embed in another game or application?

I'm looking to use something as a library. I can pass it the available objects and verbs from my own side. It will parse the sentences from the user and give me back some sort of structure/AST describing what the user asked for. Then my own code can then act upon that request.

I don't need something SIRI level. The simple sentences and actions that current IF games support is fine. But I'm not looking to write a whole text/sentence parser myself.

This isn't an If game and I can't write it entirely in an interactive-fiction language like inform 7. Unfortunatly, I can't seem to find any examples of anyone using the text parsing capabilities of these engines without writing the entire game in that engine's language.

• Interesting idea. I don't think embedding a z-machine would be an impossible task (which means you could use inform to write the if-part) - afair, windows port of some z-machine had the z-machine run in a separate thread from the UI, so it kinda already does (parts) of what you want. – Jari Komppa Oct 5 '12 at 8:20
• All that said, it's entirely possible that what you actually want to do is easier to do without embedding a whole IF virtual machine.. – Jari Komppa Oct 5 '12 at 8:21
• yeah, it looks like I'll have to write my own parser. – DragonFax Oct 5 '12 at 10:40

This is a tricky question. It's possible to extract the text parsing functionality from one of a number of IF engines written in general-purpose programming languages (i.e. not something like Inform). Some possibilities might be Pyf, and the Aunt and Butler's engine. If you expand your search to muds you'll have an order of magnitude more choices (here are lists of open source muds and Python muds specifically).

However the tricky part, and from your question you understand this, is resolving the parse in the context of the game world. This is the hard part, and something like OpenNLP won't get you there unfortunately. The problem is that these IF engines and muds each have their own way of doing that and it may be difficult to reconcile with how you're designed your world model.

Luckily there are many resources to writing an effective parser and resolver. I'm just going to throw some links at you,

http://www.mudbytes.net/topic-1838

http://www.mudbytes.net/topic-2962

http://www.mudbytes.net/topic-2038

http://www.mud.co.uk/richard/commpars.htm

http://www.intfiction.org/forum/viewtopic.php?f=38&t=4205#p30260

https://groups.google.com/forum/?fromgroups#!searchin/rec.arts.int-fiction/writing$20a$20parser/rec.arts.int-fiction/VpsWZdWRnlA/2mf5y25xk7MJ

https://groups.google.com/forum/?fromgroups#!searchin/rec.arts.int-fiction/writing$20a$20parser/rec.arts.int-fiction/EfxdLAc5Tmo/Fn5CEQvZCGsJ

http://ifwiki.org/index.php/Past_raif_topics:_Development:_part_2#Parsing

http://www.kotancode.com/2012/02/15/scalamud-scala-java-nlp/

http://effbot.org/zone/simple-top-down-parsing.htm

http://www.skotos.net/articles/dawnof09.shtml

http://www.skotos.net/articles/dawnof22.shtml

http://discworld.starturtle.net/lpc/playing/documentation.c?path=/concepts/parser

http://disinterest.org/resource/MUD-Dev/1999q2/010160.html

• Yeah, I've written parsers for programming languages. Enough to know tackling natural languages is a different beast. – DragonFax Oct 5 '12 at 18:53
• Remember, it's not just the natural language parse, it's the world model analyzer that'll take all your time :). – georgek Oct 5 '12 at 20:27

Would this be useful to your project? I believe what you are asking for is NLP and IF is just a specific use case.

http://opennlp.apache.org/

Well, if you wish to check that the correct combination of a noun and a verb was found in the sentence and not so much about structure, grammar and other aspects:

You could use it to basically check if a synonym exists for both the verb and the noun you are looking for in a sentence without having to manually type in all the viable synonyms for each word.

If you wish to see text adventure game source code that was recently released, you could find some games here (just hit Ctrl + F) and type text

http://en.wikipedia.org/wiki/List_of_open-source_video_games

There is also a list of Text Adventure game engines here: