简体   繁体   中英

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

!((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)

For ANTLR, use the First Order Logic Grammar as starting point.

For JParsec, the JParceC calculator tutorial gets close to what you need.

Smells like 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. "SELECT 1 WHERE " + expression

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. But I'm guessing that isn't doing exactly what you want.

I am not aware of any API in java. 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 is a statically-typed programming language which compiles to comprehensible Java source code. Xtend is developed using Xtext.

Xtext is a framework for development of programming languages and domain specific languages.

Above info is not applicable if you are looking at algorithm to simply the given expression.

Hope the information is useful to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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