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