{
GdlRelation relation = (GdlRelation) gdl;
String name = relation.getName().toString();
if(!name.equals("base"))
{
GdlTerm term = relation.toTerm();
GdlTerm generified = findGenericForm(term);
Assignment instantiation = getConstantList(term);
if(!domains.containsKey(generified))
domains.put(generified, new Domain(generified, term));
Domain dom = domains.get(generified);
dom.assignments.add(instantiation);
}
}
else if(gdl instanceof GdlRule)
{
GdlRule rule = (GdlRule)gdl;
GdlSentence head = rule.getHead();
if(head instanceof GdlRelation)
{
GdlRelation rel = (GdlRelation)head;
GdlTerm term = rel.toTerm();
GdlTerm generified = findGenericForm(term);
if(!domains.containsKey(generified))
domains.put(generified, new Domain(generified, term));
Domain dom = domains.get(generified);
List<GdlTerm> productionTemplate = getConstantAndVariableList(term);
List<List<GdlLiteral>> newRHSs = deOr(rule.getBody());
for(List<GdlLiteral> RHS : newRHSs)
{
RuleReference ruleRef = new RuleReference(GdlPool.getRule(head, RHS));
ruleRef.productionTemplate = productionTemplate;
for(GdlLiteral lit : RHS)
{
if(lit instanceof GdlSentence)
{
GdlTerm t = ((GdlSentence)lit).toTerm();
Condition cond = new Condition(t);
ruleRef.conditions.add(cond);
}
}
dom.ruleRefs.add(ruleRef);
}
}
else
{
List<List<GdlLiteral>> newRHSs = deOr(rule.getBody());
for(List<GdlLiteral> RHS : newRHSs)
{
RuleReference ruleRef = new RuleReference(GdlPool.getRule(head, RHS));
for(GdlLiteral lit : RHS)
{
if(lit instanceof GdlSentence)
{
GdlTerm t = ((GdlSentence)lit).toTerm();
Condition cond = new Condition(t);
ruleRef.conditions.add(cond);
}
}
extraRefs.add(ruleRef);