00001 package edu.tum.cs.logic;
00002
00003 import java.util.Collection;
00004 import java.util.HashMap;
00005 import java.util.Map;
00006 import java.util.Set;
00007 import java.util.Vector;
00008
00009 import edu.tum.cs.srl.Database;
00010
00011 public abstract class ComplexFormula extends Formula {
00012 public Formula[] children;
00013
00014 public ComplexFormula(Collection<Formula> children) {
00015 this.children = children.toArray(new Formula[children.size()]);
00016 }
00017
00018 public ComplexFormula(Formula ... children) {
00019 this.children = children;
00020 }
00021
00022
00023
00024
00025
00026 @Override
00027 public void getVariables(Database db, Map<String, String> ret) throws Exception {
00028 for(Formula f : children)
00029 f.getVariables(db, ret);
00030 }
00031
00032 @Override
00033 public Formula ground(Map<String, String> binding, WorldVariables vars, Database db) throws Exception {
00034 Vector<Formula> groundChildren = new Vector<Formula>();
00035 for(Formula child : children) {
00036 groundChildren.add(child.ground(binding, vars, db));
00037 }
00038 return this.getClass().getConstructor(Collection.class).newInstance(groundChildren);
00039 }
00040
00041 public void getGroundAtoms(Set<GroundAtom> ret) {
00042 for(Formula child : children)
00043 child.getGroundAtoms(ret);
00044 }
00045 }