Wednesday, October 05, 2011

XText and Attempto for Controlled Natural Language

Drools has always been independant of the parser. DRL is just a general purpose technical language for logic programming. We've always been big proponents of the conceptual idea of DSLs.

An early hack for our "DSL" was a simple string interpolation framework, for sentence templating. We always hoped to do more, as this was unstructured, but DSL's need tooling to fulfill their potential and this was beyond the resources we had.

I've been following XText for some time now and I think it now offers a real alternative to our DSLs, for domain specific structured content authoring. Version 2.0 is looking particularly sexy.

A recent blog "Using Xbase for Home Automation Rules " by Kai Kreuzer confirms that Xtext has a lot of potential here. I've suggested to Kai that he can use XText to drive our fluent descr api, which is what Antlr uses. Examples of the descr api for programmatic rule generation can be seen in this unit test:

In essence I think a number of examples can be done to develop best practices, as well as fleshing our helper classes and abstract classes to make it quicker to developer DSLs in XText for Drools.

This started to make me think about how XText can be leveraged for natural language rule authoring.

Attempto is a project for controlled natural language. You provide mappings from your classes and fields to nouns, verbs and adjectives and it's parser will then allow you to author rules via controlled natural language. However there is no IDE for this.

Enter XText, a rising star in the Eclipse world. Xtext provides complete tooling, code completion, refactoring, outlines, based on an antlr like grammar.

Using the class and field mappings and the techniques in the Attempto parser, it should be possibe to generate an XText grammar. This would allow for controlled natural language rule authoring.

I think this is a fantastic project idea and XText really is catalyst for making this easy to realise it's potential. Any takers?

If you're interested, you know where to find us:



  1. Hi,

    I've investigated Xtext some months ago. My desire was to use Xtext2 to create a DSL based on Behavior Driven Dev (BDD) model, that has a DSL similar to the one used by Drools. it uses the following keywords: GIVEN (to setup context), WHEN (events), THEN (actions), AND (glue).

    The big problem that I faced was related to internationalization. Using Xtext I can't have Keywords in more than one natural language by project.

    So, for example, If I want to write a Story using Portuguese, I have to create a Xtext project where the keywords are fixed in portuguese, unless I want to write a story mixing English (keywords) and Portuguese, what is not that charming...


  2. Interesting topic.

    Currently I work on a DSL for Drools Planner, as I think the drl dsl doesn't fit for this use case.

    I'm going to use the Descr API to transform my model created by the dsl to the drools engine.

    Maybe we could start up a project on github to share code on this...

  3. This is hot: I'm about to create an Xtext DSL to specify rules. Instead of using the fluent API, my idea is to compile it to DRL by means of xtend in order tu use the DRL IDE features.
    Mark: I'd appreciate if you could give me some reasons why I should (not) prefer the API- and not the compiler-approach.

  4. Im no expert, but I believe you just made an excellent point. You certainly fully understand what youre speaking about, and I can truly get behind that. how to wash vegetables and fruit naturally

  5. Hi, this projects is used to generate drools rules with Xtext?