001/**
002 * Copyright (C) 2007 - 2016, Jens Lehmann
003 *
004 * This file is part of DL-Learner.
005 *
006 * DL-Learner is free software; you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation; either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * DL-Learner is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
018 */
019package org.dllearner.prolog;
020
021import java.util.ArrayList;
022
023/**
024 * 
025 * @author Sebastian Bader
026 * 
027 */
028public class Program {
029        private ArrayList<Clause> clauses;
030
031        public Program() {
032                clauses = new ArrayList<>();
033        }
034
035        public void addClause(Clause clause) {
036                clauses.add(clause);
037        }
038
039        public ArrayList<Clause> getClauses() {
040                return clauses;
041        }
042
043        public boolean isGround() {
044                for (Clause clause : clauses) {
045                        if (!clause.isGround())
046                                return false;
047                }
048
049                return true;
050        }
051
052        @Override
053        public String toString() {
054                StringBuffer ret = new StringBuffer();
055
056                for (int i = 0; i < clauses.size(); i++) {
057                        ret.append(clauses.get(i));
058                        if (i + 1 < clauses.size())
059                                ret.append(" ");
060                }
061
062                return ret.toString();
063        }
064
065        public String toPLString() {
066                StringBuffer ret = new StringBuffer();
067
068                for (int i = 0; i < clauses.size(); i++) {
069                        ret.append(clauses.get(i).toPLString());
070                        if (i + 1 < clauses.size())
071                                ret.append("\n");
072                }
073
074                return ret.toString();
075        }
076
077}