aima.core.logic.propositional.visitors.ConvertToConjunctionOfClauses Maven / Gradle / Ivy
package aima.core.logic.propositional.visitors;
import java.util.ArrayList;
import java.util.List;
import aima.core.logic.propositional.kb.data.Clause;
import aima.core.logic.propositional.kb.data.ConjunctionOfClauses;
import aima.core.logic.propositional.parsing.ast.Sentence;
/**
* Artificial Intelligence A Modern Approach (3rd Edition): page 253.
*
* A sentence expression as a conjunction of clauses is said to be in
* conjunctive normal form or CNF.
*
*
* CNFSentence -> Clause_1 & ... & Clause_n
* Clause -> Literal_1 | ... | Literal_m
* Literal -> Symbol : ~Symbol
* Symbol -> P : Q : R : ... // (1)
*
*
* Figure 7.14 A grammar for conjunctive normal form.
*
* Note (1): While the book states 'We use symbols that start with an upper case
* letter and may contain other letters or subscripts' in this implementation we
* allow any legal java identifier to stand in for a proposition symbol.
*
* @author Ciaran O'Reilly
* @author Ravi Mohan
* @author Mike Stampone
*/
public class ConvertToConjunctionOfClauses {
/**
* Returns the specified sentence in its logically equivalent conjunction of
* clauses.
*
* @param s
* a propositional logic sentence
*
* @return the input sentence converted to it logically equivalent
* conjunction of clauses.
*/
public static ConjunctionOfClauses convert(Sentence s) {
ConjunctionOfClauses result = null;
Sentence cnfSentence = ConvertToCNF.convert(s);
List clauses = new ArrayList();
clauses.addAll(ClauseCollector.getClausesFrom(cnfSentence));
result = new ConjunctionOfClauses(clauses);
return result;
}
}