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 Literal {
030        private Atom atom;
031        private boolean positive;
032        
033        public Literal(Atom atom, boolean state) {
034            this.atom = atom;
035            this.positive = state;
036        }
037        
038        public Atom getAtom() {
039            return atom;
040        }
041        
042        public boolean isPositive() {
043            return positive;
044        }
045    
046        public boolean isGround() {
047            return atom.isGround();
048        }
049    
050        public Literal getInstance(Variable variable, Term term) {
051            return new Literal(atom.getInstance(variable, term), positive);
052        }
053               
054        @Override
055            public String toString() {
056            return (positive?"+":"-")+atom.toString();
057        }
058        
059        public String toPLString() {
060            return (positive?"":"not ")+atom.toPLString();
061        }
062        
063        @Override
064            public boolean equals(Object obj) {
065            if (obj == null)
066                return false;
067                  
068            Literal l;
069            
070            try {
071                l = (Literal) obj;
072            } catch (ClassCastException cce) {
073                return false;
074            }
075            
076            if (positive != l.positive)
077                return false;
078                        
079            return atom.equals(l.atom);
080        }
081    
082        @Override
083            public int hashCode() {
084            return atom.hashCode() * (positive?1:2);
085        }
086    }