Exemplo n.º 1
0
 def getInstantiationAux(self, gdl, varInstantiation):
     """ generated source for method getInstantiationAux """
     if isinstance(gdl, (GdlRelation, )):
         while i < relation.arity():
             body.add(self.getInstantiationAux(relation.get(i), varInstantiation))
             i += 1
         return GdlPool.getRelation(relation.__name__, body)
     elif isinstance(gdl, (GdlRule, )):
         while i < rule.arity():
             body.add(self.getInstantiationAux(rule.get(i), varInstantiation))
             i += 1
         return GdlPool.getRule(head, body)
     elif isinstance(gdl, (GdlDistinct, )):
         return GdlPool.getDistinct(arg1, arg2)
     elif isinstance(gdl, (GdlNot, )):
         return GdlPool.getNot(body)
     elif isinstance(gdl, (GdlOr, )):
         while i < or_.arity():
             body.add(self.getInstantiationAux(or_.get(i), varInstantiation))
             i += 1
         return GdlPool.getOr(body)
     elif isinstance(gdl, (GdlProposition, )):
         return gdl
     elif isinstance(gdl, (GdlConstant, )):
         return gdl
     elif isinstance(gdl, (GdlFunction, )):
         while i < func.arity():
             body.add(self.getInstantiationAux(func.get(i), varInstantiation))
             i += 1
         return GdlPool.getFunction(func.__name__, body)
     elif isinstance(gdl, (GdlVariable, )):
         return varInstantiation.get(variable)
     else:
         raise RuntimeException("Someone went and extended the GDL hierarchy without updating this code.")
Exemplo n.º 2
0
 def replaceVariablesInternal(cls, gdl, assignment):
     """ generated source for method replaceVariablesInternal """
     if isinstance(gdl, (GdlProposition, )):
         return gdl
     elif isinstance(gdl, (GdlRelation, )):
         for term in relation.getBody():
             newBody.add(cls.replaceVariables(term, assignment))
         return GdlPool.getRelation(name, newBody)
     elif isinstance(gdl, (GdlConstant, )):
         return gdl
     elif isinstance(gdl, (GdlVariable, )):
         if assignment.containsKey(gdl):
             return assignment.get(gdl)
         else:
             return gdl
     elif isinstance(gdl, (GdlFunction, )):
         for term in function_.getBody():
             newBody.add(cls.replaceVariables(term, assignment))
         return GdlPool.getFunction(name, newBody)
     elif isinstance(gdl, (GdlDistinct, )):
         return GdlPool.getDistinct(arg1, arg2)
     elif isinstance(gdl, (GdlNot, )):
         return GdlPool.getNot(cls.replaceVariables(internal, assignment))
     elif isinstance(gdl, (GdlOr, )):
         while i < or_.arity():
             newInternals.add(cls.replaceVariables(or_.get(i), assignment))
             i += 1
         return GdlPool.getOr(newInternals)
     elif isinstance(gdl, (GdlRule, )):
         for conjunct in rule.getBody():
             newBody.add(cls.replaceVariables(conjunct, assignment))
         return GdlPool.getRule(newHead, newBody)
     else:
         raise RuntimeException("Unforeseen Gdl subtype " + gdl.__class__.getSimpleName())
Exemplo n.º 3
0
 def substituteOr(cls, or_, theta):
     """ generated source for method substituteOr """
     if or_.isGround():
         return or_
     else:
         while i < or_.arity():
             disjuncts.add(cls.substituteLiteral(or_.get(i), theta))
             i += 1
         return GdlPool.getOr(disjuncts)
Exemplo n.º 4
0
 def cleanParentheses_0(cls, literal):
     """ generated source for method cleanParentheses_0 """
     if isinstance(literal, (GdlSentence, )):
         return cls.cleanParentheses(literal)
     elif isinstance(literal, (GdlDistinct, )):
         return GdlPool.getDistinct(term1, term2)
     elif isinstance(literal, (GdlNot, )):
         return GdlPool.getNot(cls.cleanParentheses(body))
     elif isinstance(literal, (GdlOr, )):
         while i < or_.arity():
             pass
             i += 1
         return GdlPool.getOr(disjuncts)
     raise RuntimeException("Unexpected literal type in GdlCleaner")
Exemplo n.º 5
0
 def replaceVariableInternal(cls, gdl, toSubstitute, theReplacement):
     """ generated source for method replaceVariableInternal """
     if isinstance(gdl, (GdlDistinct, )):
         return GdlPool.getDistinct(cls.replaceVariableInternal((gdl).getArg1(), toSubstitute, theReplacement), cls.replaceVariableInternal((gdl).getArg2(), toSubstitute, theReplacement))
     elif isinstance(gdl, (GdlNot, )):
         return GdlPool.getNot(cls.replaceVariableInternal((gdl).getBody(), toSubstitute, theReplacement))
     elif isinstance(gdl, (GdlOr, )):
         while i < or_.arity():
             rval.add(cls.replaceVariableInternal(or_.get(i), toSubstitute, theReplacement))
             i += 1
         return GdlPool.getOr(rval)
     elif isinstance(gdl, (GdlProposition, )):
         return gdl
     elif isinstance(gdl, (GdlRelation, )):
         while i < rel.arity():
             rval.add(cls.replaceVariableInternal(rel.get(i), toSubstitute, theReplacement))
             i += 1
         return GdlPool.getRelation(rel.__name__, rval)
     elif isinstance(gdl, (GdlRule, )):
         while i < rule.arity():
             rval.add(cls.replaceVariableInternal(rule.get(i), toSubstitute, theReplacement))
             i += 1
         return GdlPool.getRule(cls.replaceVariableInternal(rule.getHead(), toSubstitute, theReplacement), rval)
     elif isinstance(gdl, (GdlConstant, )):
         return gdl
     elif isinstance(gdl, (GdlFunction, )):
         while i < func.arity():
             rval.add(cls.replaceVariableInternal(func.get(i), toSubstitute, theReplacement))
             i += 1
         return GdlPool.getFunction(func.__name__, rval)
     elif isinstance(gdl, (GdlVariable, )):
         if gdl == toSubstitute:
             return theReplacement
         else:
             return gdl
     else:
         raise RuntimeException("Uh oh, gdl hierarchy must have been extended without updating this code.")