001 /**
002 * Copyright (C) 2007-2011, 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 */
019
020 package org.dllearner.prolog;
021
022 import java.util.ArrayList;
023
024 /**
025 *
026 * @author Sebastian Bader
027 *
028 */
029 public class Program {
030 private ArrayList<Clause> clauses;
031
032 public Program() {
033 clauses = new ArrayList<Clause>();
034 }
035
036 public void addClause(Clause clause) {
037 clauses.add(clause);
038 }
039
040 public ArrayList<Clause> getClauses() {
041 return clauses;
042 }
043
044 public boolean isGround() {
045 for (int c = 0; c < clauses.size(); c++) {
046 Clause clause = (Clause) clauses.get(c);
047 if (!clause.isGround())
048 return false;
049 }
050
051 return true;
052 }
053
054 @Override
055 public String toString() {
056 StringBuffer ret = new StringBuffer();
057
058 for (int i = 0; i < clauses.size(); i++) {
059 ret.append(clauses.get(i));
060 if (i + 1 < clauses.size())
061 ret.append(" ");
062 }
063
064 return ret.toString();
065 }
066
067 public String toPLString() {
068 StringBuffer ret = new StringBuffer();
069
070 for (int i = 0; i < clauses.size(); i++) {
071 ret.append(((Clause) clauses.get(i)).toPLString());
072 if (i + 1 < clauses.size())
073 ret.append("\n");
074 }
075
076 return ret.toString();
077 }
078
079 }