public static String toCNF ( INode in , String formula ) throws ContextClassifierException { PEParser parser = new PEParser ( ) ; CNFTransformer transformer = new CNFTransformer ( ) ; String result = formula ; if ( ( formula . contains ( "&" ) && formula . contains ( "|" ) ) || formula . contains ( "~" ) ) { String tmpFormula = formula ; tmpFormula = tmpFormula . trim ( ) ; tmpFormula = tmpFormula . replace ( "&" , "AND" ) ; tmpFormula = tmpFormula . replace ( "|" , "OR" ) ; tmpFormula = tmpFormula . replace ( "~" , "NOT" ) ; tmpFormula = "(" + tmpFormula + ")" ; if ( ! tmpFormula . isEmpty ( ) ) { tmpFormula = tmpFormula . replace ( ' ' , ' ' ) ; Sentence f = ( Sentence ) parser . parse ( tmpFormula ) ; Sentence cnf = transformer . transform ( f ) ; tmpFormula = cnf . toString ( ) ; tmpFormula = tmpFormula . replace ( "AND" , "&" ) ; tmpFormula = tmpFormula . replace ( "OR" , "|" ) ; tmpFormula = tmpFormula . replace ( "NOT" , "~" ) ; result = tmpFormula . replace ( ' ' , ' ' ) ; } else { result = tmpFormula ; } } return result ; }
Converts the formula into CNF .