001 package aima.logic.fol.kb.data; 002 003 import java.util.ArrayList; 004 import java.util.Collections; 005 import java.util.List; 006 007 /** 008 * Conjunctive Normal Form (CNF) : a conjunction of clauses, where each 009 * clause is a disjunction of literals. 010 */ 011 012 /** 013 * @author Ciaran O'Reilly 014 * 015 */ 016 public class CNF { 017 018 private List<Clause> conjunctionOfClauses = new ArrayList<Clause>(); 019 020 public CNF(List<Clause> conjunctionOfClauses) { 021 this.conjunctionOfClauses.addAll(conjunctionOfClauses); 022 } 023 024 public int getNumberOfClauses() { 025 return conjunctionOfClauses.size(); 026 } 027 028 public List<Clause> getConjunctionOfClauses() { 029 return Collections.unmodifiableList(conjunctionOfClauses); 030 } 031 032 public String toString() { 033 StringBuilder sb = new StringBuilder(); 034 for (int i = 0; i < conjunctionOfClauses.size(); i++) { 035 if (i > 0) { 036 sb.append(","); 037 } 038 sb.append(conjunctionOfClauses.get(i).toString()); 039 } 040 041 return sb.toString(); 042 } 043 }