Exemple #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.")
Exemple #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())
Exemple #3
0
 def substituteFunction(cls, function_, theta):
     """ generated source for method substituteFunction """
     if function_.isGround():
         return function_
     else:
         while i < function_.arity():
             body.add(substituteTerm(function_.get(i), theta))
             i += 1
         return GdlPool.getFunction(name, body)
Exemple #4
0
 def cleanParentheses_2(cls, term):
     """ generated source for method cleanParentheses_2 """
     if isinstance(term, (GdlConstant, )) or isinstance(term, (GdlVariable, )):
         return term
     if isinstance(term, (GdlFunction, )):
         # The whole point of the function
         if function_.arity() == 0:
             return function_.__name__
         for functionTerm in function_.getBody():
             cleanedBody.add(cls.cleanParentheses(functionTerm))
         return GdlPool.getFunction(function_.__name__, cleanedBody)
     raise RuntimeException("Unexpected term type in GdlCleaner")
Exemple #5
0
 def getFunctionFromTuple(self, tuple_, curIndex):
     """ generated source for method getFunctionFromTuple """
     functionBody = Lists.newArrayList()
     i = 0
     while i < self.arity:
         Preconditions.checkArgument(not (isinstance(term, (GdlFunction, ))))
         if self.functions.containsKey(i):
             functionBody.add(functionForm.getFunctionFromTuple(tuple_, curIndex))
             curIndex += functionForm.getTupleSize()
         else:
             functionBody.add(term)
             curIndex += 1
         i += 1
     return GdlPool.getFunction(self.name, functionBody)
Exemple #6
0
 def mergeBaseRelations(self, rels):
     """ generated source for method mergeBaseRelations """
     merges = HashMap()
     for rel in rels:
         if not merges.containsKey(name):
             merges.put(name, ArrayList())
         addRelToMerge(rel, merge)
     rval = HashSet()
     valConst = GdlPool.getConstant("val")
     for c in merges.keySet():
         body.add(c)
         for mergeSet in merge:
             Collections.sort(ms2, SortTerms())
             body.add(GdlPool.getFunction(valConst, ms2))
         rval.add(toAdd)
     return rval
Exemple #7
0
 def findGenericForm(self, term):
     """ generated source for method findGenericForm """
     if isinstance(term, (GdlConstant, )):
         return self.fillerVar
     elif isinstance(term, (GdlVariable, )):
         return self.fillerVar
     func = term
     newBody = ArrayList()
     for t in func.getBody():
         newBody.add(self.findGenericForm(t))
     name = func.__name__
     if name == self.legalConst:
         name = self.doesConst
     elif name == self.nextConst:
         name = self.trueConst
     elif name == self.initConst:
         name = self.trueConst
     return GdlPool.getFunction(name, newBody)
Exemple #8
0
 def getAnnotations(self):
     """ generated source for method getAnnotations """
     # Find universe and initial domains
     for gdl in description:
         processGdl(gdl, None)
         processDomain(gdl)
     # Compute the actual domains of everything
     updateDomains()
     # printDomains();
     # printDomainRefs();
     # Compute function corresponding to universal set for insertion in baseprops
     body = ArrayList()
     body.addAll(self.universe)
     self.universalDom = GdlPool.getFunction(GdlPool.getConstant("thing"), body)
     # Find next/init things and use them to instantiate base props
     for gdl in description:
         findAndInstantiateBaseProps(gdl)
     self.baseRelations = mergeBaseRelations(self.baseRelations)
     # Return the results
     rval = ArrayList()
     rval.addAll(self.baseRelations)
     return rval
Exemple #9
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.")