谁能给我指出一个关于“英语”的漂亮打印规则的好例子吗?

发布于 2024-07-09 02:13:37 字数 269 浏览 12 评论 0原文

我已经得到了用户使用规则引擎构建的 AST 的等效项。 但是当显示规则列表时,我希望能够将每个规则“漂亮地打印”成看起来不错的**。 在内部,当表示为字符串时,它们看起来像 s 表达式,因此可以想象一下:

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

任何人都可以向我指出一个以可读方式很好地显示规则的程序吗?

** 也需要本地化,但我想我们会把它留作额外的功劳。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掩饰不了的爱 2024-07-16 02:13:37

也许可以查看正在开发 Attempto Controlled English (ACE) 的 Attempto 项目。 ACE 允许您用英语的子集编写规则。 例如:

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

ACE解析器将此类规则转换为称为话语表示结构(DRS)的逻辑形式。 对于上面的例子,它看起来像这样:

[]
   [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

有一个名为 DRSverbalizer 的工具,可以将 DRS 转换为 ACE。 对于上面的 DRS,您将得到:

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

在您的情况下,您必须将规则表示转换为 DRS(这应该非常简单),然后您可以直接使用 DRS 语言器。 上述工具可根据 LGPL 许可证使用

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文