views:

245

answers:

1

I've got the equivalent of an AST that a user has built using a rule engine. But when displaying a list of the rules, I'd like to be able to "pretty print" each rule into something that looks nice**. Internally when represented as a string they look like s-expressions so imagine something like:

(and (contains "foo" "foobar") (equals 4 (plus 2 2 )))

Can anyone point me at a program that has done a good job of displaying rules in a readable fashion?

** Needs to be localizable too, but I guess we'll leave that for extra credit.

+1  A: 

Maybe check out the Attempto project that is developing Attempto Controlled English (ACE). ACE allows you to write rules in a subset of English. For example:

If "foo" contains "foobar" and "foobar" does not contain "foo" then 4 = 2 + 2.

The ACE parser converts such rules into a logical form called Discourse Representation Structure (DRS). For the above example, it looks like this:

[]
   [A]
   predicate(A, contain, string(foo), string(foobar))-1
      NOT
      [B]
      predicate(B, contain, string(foobar), string(foo))-1
   =>
   []
   formula(int(4), =, expr(+, int(2), int(2)))-1

There is a tool called DRS verbalizer that converts DRSs into ACE. For the above DRS you would get:

If "foo" contains "foobar" and it is false that "foobar" contains "foo" then 4 = ( 2 + 2 ).

In your case, you would have to convert your rule representation into the DRS (which should be quite straight-forward), and then you can directly use the DRS verbalizer. The mentioned tools are available under the LGPL license.

Kaarel