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