00001 package edu.tum.cs.logic; 00002 00003 import java.util.Map; 00004 import java.util.Set; 00005 00006 import edu.tum.cs.srl.Database; 00007 00008 public class GroundLiteral extends Formula { 00009 public boolean isPositive; 00010 public GroundAtom gndAtom; 00011 00012 public GroundLiteral(boolean isPositive, GroundAtom gndAtom) { 00013 this.gndAtom = gndAtom; 00014 this.isPositive = isPositive; 00015 } 00016 00017 public boolean isTrue(IPossibleWorld w) { 00018 boolean v = w.isTrue(gndAtom); 00019 return isPositive ? v : !v; 00020 } 00021 00022 @Override 00023 public void getVariables(Database db, Map<String, String> ret) { 00024 } 00025 00026 @Override 00027 public Formula ground(Map<String, String> binding, WorldVariables vars, Database db) throws Exception { 00028 return this; 00029 } 00030 00031 @Override 00032 public void getGroundAtoms(Set<GroundAtom> ret) { 00033 ret.add(gndAtom); 00034 } 00035 00036 @Override 00037 public String toString() { 00038 return isPositive ? gndAtom.toString() : "!" + gndAtom.toString(); 00039 } 00040 00041 @Override 00042 public Formula toCNF() { 00043 return this; 00044 } 00045 00046 @Override 00047 public Formula toNNF() { 00048 return this; 00049 } 00050 00051 public void negate() { 00052 isPositive = !isPositive; 00053 } 00054 00060 @Override 00061 public Formula simplify(Database evidence) { 00062 Formula f = this.gndAtom.simplify(evidence); 00063 if(f instanceof TrueFalse) { 00064 if(isPositive) 00065 return f; 00066 else 00067 return ((TrueFalse)f).opposite(); 00068 } 00069 return this; 00070 } 00071 }