简体   繁体   English

是否有任何开源Java库或java源代码来简化布尔表达式

[英]Is there any open source Java Library or java source code to simplify boolean expression

Is there any open source Java Library or java source code to simplify Boolean expression like 是否有任何开源Java库或java源代码来简化布尔表达式

!((A.B+C).(!A+BC))

Where, 哪里,

! - represents NOT
+ - represents OR
. - represents AND

Your help would be greatly appreciated in this regard 在这方面,我们将非常感谢您的帮助

No, I don't think so, but it should be pretty simple to write a parser for such a language using ANTLR (declarative) or JParsec (programmatic) 不,我不这么认为,但使用ANTLR (声明性)或JParsec (编程式)为这种语言编写解析器应该非常简单

For ANTLR, use the First Order Logic Grammar as starting point. 对于ANTLR,使用First Order Logic Grammar作为起点。

For JParsec, the JParceC calculator tutorial gets close to what you need. 对于JParsec, JParceC计算器教程可以满足您的需求。

Smells like SQL? 闻起来像SQL? You could trivialy translate the !,.,+ into NOT, AND, OR, filter out certain magic keywords, then pass them on to a traditional JDBC back-end. 您可以琐事将!,。,+转换为NOT,AND,OR,过滤掉某些魔术关键字,然后将它们传递给传统的JDBC后端。 "SELECT 1 WHERE " + expression “SELECT 1 WHERE”+表达式

Otherwise, it sounds like you need a full logical AST+parser (antlr), since simply constructing a DOM representing the expression isn't going to be terribly useful (and consequently, there aren't that many tools that generally take an expression object-graph and apply generic axioms).. There are some HIGHLY specialized variants of this - lookup rule engines like drools. 否则,听起来你需要一个完整的逻辑AST +解析器(antlr),因为简单地构造一个表示表达式的DOM并不会非常有用(因此,通常没有那么多的工具通常采用表达式对象-graph和应用通用公理)..有一些高度专业化的变体 - 查找规则引擎,如drools。 But I'm guessing that isn't doing exactly what you want. 但我猜这并不是你想做的。

I am not aware of any API in java. 我不知道java中的任何API。 However, you can split your expression and build a predicates for each part. 但是,您可以拆分表达式并为每个部分构建谓词。 You might be interested to take a look on this 您可能有兴趣看看这个

First of all let me confirm if I get your question correctly - are you looking at ability to code the given expression in simplified manner? 首先让我确认一下我的问题是否正确 - 您是否正在寻找以简化方式编写给定表达式的能力?

If yes then you can try Xtend : http://eclipse.org/xtend/ and Xtext http://www.eclipse.org/Xtext/ 如果是,那么您可以尝试Xtend: http//eclipse.org/xtend/和Xtext http://www.eclipse.org/Xtext/

Xtend is a statically-typed programming language which compiles to comprehensible Java source code. Xtend是一种静态类型的编程语言,它编译成可理解的Java源代码。 Xtend is developed using Xtext. Xtend是使用Xtext开发的。

Xtext is a framework for development of programming languages and domain specific languages. Xtext是用于开发编程语言和领域特定语言的框架。

Above info is not applicable if you are looking at algorithm to simply the given expression. 如果您正在查看算法以简化给定表达式,则上述信息不适用。

Hope the information is useful to you. 希望这些信息对您有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM