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    
023    
024    /**
025     * 
026     * @author Sebastian Bader
027     *
028     */
029    public class Clause {
030        private Atom head;
031        private Body body;
032        
033        public Clause(Atom head, Body body) {
034            this.head = head;
035            this.body = body;
036            if (body == null)
037                this.body = new Body();
038        }
039    
040        @Override
041            public String toString() {
042            if (body.isEmpty())
043                return head+".";
044            return head + " :- " + body +".";
045        }
046    
047        public String toPLString() {
048            if (body.isEmpty())
049                return head.toPLString()+".";
050            return head.toPLString() + " :- " + body.toPLString() +".";
051        }
052    
053        public boolean isGround() {
054            if (!head.isGround())
055                return false;
056            
057            return body.isGround();
058        }
059    
060        public Body getBody() {
061            return body;
062        }
063    
064        public Atom getHead() {
065            return head;
066        }
067        
068        /**
069             * 
070             * @param variable
071             *            Substitution variable.
072             * @param term
073             *            A term.
074             * @return Returns a new instance of this term, where the variable is
075             *         replaced by the term.
076             */    
077        public Clause getInstance(Variable variable, Term term) {
078            Atom newhead = head.getInstance(variable, term);
079            Body newbody = body.getInstance(variable, term);
080            
081            return new Clause(newhead, newbody);
082        }
083    
084    }
085