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 Body {
030 private ArrayList<Literal> literals;
031
032 public Body() {
033 literals = new ArrayList<Literal>();
034 }
035
036 public void addLiteral(Literal literal) {
037 literals.add(literal);
038 }
039
040 public ArrayList<Literal> getLiterals() {
041 return literals;
042 }
043
044 public boolean isEmpty() {
045 return literals.isEmpty();
046 }
047
048 public boolean isGround() {
049 for (int i = 0; i < literals.size(); i++) {
050 if (!((Literal) literals.get(i)).isGround())
051 return false;
052 }
053
054 return true;
055 }
056
057 public Body getInstance(Variable variable, Term term) {
058 Body newbody = new Body();
059
060 for (int i = 0; i < literals.size(); i++) {
061 Literal literal = (Literal) literals.get(i);
062 newbody.addLiteral(literal.getInstance(variable, term));
063 }
064
065 return newbody;
066 }
067
068 @Override
069 public String toString() {
070 StringBuffer ret = new StringBuffer();
071
072 for (int i = 0; i < literals.size(); i++) {
073 ret.append(literals.get(i));
074 if (i + 1 < literals.size())
075 ret.append(", ");
076 }
077
078 return ret.toString();
079 }
080
081 public String toPLString() {
082 StringBuffer ret = new StringBuffer();
083
084 for (int i = 0; i < literals.size(); i++) {
085 ret.append(((Literal) literals.get(i)).toPLString());
086 if (i + 1 < literals.size())
087 ret.append(", ");
088 }
089
090 return ret.toString();
091 }
092
093 }