Exemple #1
0
 def removeComponent(self, c):
     """ generated source for method removeComponent """
     if isinstance(c, (Proposition, )):
         if self.basePropositions.containsKey(name):
             self.basePropositions.remove(name)
         elif self.inputPropositions.containsKey(name):
             self.inputPropositions.remove(name)
             if partner != None:
                 self.legalInputMap.remove(partner)
                 self.legalInputMap.remove(p)
         elif name == GdlPool.getProposition(GdlPool.getConstant("INIT")):
             raise RuntimeException("The INIT component cannot be removed. Consider leaving it and ignoring it.")
         elif name == GdlPool.getProposition(GdlPool.getConstant("terminal")):
             raise RuntimeException("The terminal component cannot be removed.")
         else:
             for propositions in legalPropositions.values():
                 if self.propositions.contains(p):
                     self.propositions.remove(p)
                     if partner != None:
                         self.legalInputMap.remove(partner)
                         self.legalInputMap.remove(p)
             for propositions in goalPropositions.values():
                 self.propositions.remove(p)
         self.propositions.remove(p)
     self.components.remove(c)
     for parent in c.getInputs():
         parent.removeOutput(c)
     for child in c.getOutputs():
         child.removeInput(c)
 def normalizePropositions(cls, componentSet):
     """ generated source for method normalizePropositions """
     for component in componentSet:
         if isinstance(component, (Proposition, )):
             if isinstance(sentence, (GdlRelation, )):
                 if relation.__name__ == cls.NEXT:
                     p.setName(GdlPool.getProposition(GdlPool.getConstant("anon")))
Exemple #3
0
 def applyCondensation(cls, condensationSet, rule, sentenceNameSource):
     """ generated source for method applyCondensation """
     varsInCondensationSet = HashSet()
     for literal in condensationSet:
         varsInCondensationSet.addAll(GdlUtils.getVariables(literal))
     varsToKeep = HashSet()
     for literal in condensationSet:
         varsToKeep.addAll(GdlUtils.getVariables(literal))
     varsToKeep2 = HashSet()
     varsToKeep2.addAll(GdlUtils.getVariables(rule.getHead()))
     for literal in rule.getBody():
         if not condensationSet.contains(literal):
             varsToKeep2.addAll(GdlUtils.getVariables(literal))
     varsToKeep.retainAll(varsToKeep2)
     orderedVars = ArrayList(varsToKeep)
     condenserName = sentenceNameSource.getNameWithPrefix(rule.getHead().__name__)
     condenserHead = GdlSentence()
     if orderedVars.isEmpty():
         condenserHead = GdlPool.getProposition(condenserName)
     else:
         condenserHead = GdlPool.getRelation(condenserName, orderedVars)
     condenserBody = ArrayList(condensationSet)
     condenserRule = GdlPool.getRule(condenserHead, condenserBody)
     remainingLiterals = ArrayList()
     for literal in rule.getBody():
         if not condensationSet.contains(literal):
             remainingLiterals.add(literal)
     remainingLiterals.add(condenserHead)
     modifiedRule = GdlPool.getRule(rule.getHead(), remainingLiterals)
     newRules = ArrayList(2)
     newRules.add(condenserRule)
     newRules.add(modifiedRule)
     return newRules
Exemple #4
0
 def cleanParentheses_1(cls, sentence):
     """ generated source for method cleanParentheses_1 """
     if isinstance(sentence, (GdlProposition, )):
         return sentence
     cleanedBody = ArrayList()
     for term in sentence.getBody():
         cleanedBody.add(cls.cleanParentheses(term))
     if len(cleanedBody) == 0:
         return GdlPool.getProposition(sentence.__name__)
     else:
         return GdlPool.getRelation(sentence.__name__, cleanedBody)
 def setUpInit(cls, components, trueComponent, falseComponent):
     """ generated source for method setUpInit """
     initProposition = Proposition(GdlPool.getProposition(cls.INIT_CAPS))
     for entry in components.entrySet():
         # Is this something that will be true?
         if entry.getValue() == trueComponent:
             if entry.getKey().__name__ == cls.INIT:
                 if trueSentenceComponent.getInputs().isEmpty():
                     transition.addInput(initProposition)
                     initProposition.addOutput(transition)
                     trueSentenceComponent.addInput(transition)
                     transition.addOutput(trueSentenceComponent)
                 else:
                     input.removeOutput(transition)
                     transition.removeInput(input)
                     orInputs.add(input)
                     orInputs.add(initProposition)
                     orify(orInputs, transition, falseComponent)
Exemple #6
0
 def fixDisjunctions(self):
     """ generated source for method fixDisjunctions """
     fixList = ArrayList()
     for proposition in propositions.values():
         if proposition.getInputs().size() > 1:
             fixList.add(proposition)
     for fixItem in fixList:
         for input in fixItem.getInputs():
             i += 1
             if isinstance(, (GdlProposition, )):
                 disjunct = Proposition(GdlPool.getProposition(GdlPool.getConstant(proposition.__name__.getValue() + "-" + i)))
             else:
                 disjunct = Proposition(GdlPool.getRelation(GdlPool.getConstant(relation.__name__.getValue() + "-" + i), relation.getBody()))
             input.getOutputs().clear()
             link(input, disjunct)
             link(disjunct, or_)
             self.components.add(disjunct)
         fixItem.getInputs().clear()
         link(or_, fixItem)
         self.components.add(or_)
Exemple #7
0
 def getSentenceFromTuple(self, tuple_):
     """ generated source for method getSentenceFromTuple """
     if len(tuple_) != self.tupleSize:
         raise IllegalArgumentException("Passed tuple of the wrong size to a sentence form: " + "tuple was " + tuple_ + ", sentence form is " + self)
     if len(tuple_) < self.arity:
         raise IllegalStateException("Something is very wrong, probably fixable by the GdlCleaner; name: " + self.name + "; arity: " + self.arity + "; tupleSize: " + self.tupleSize)
     sentenceBody = Lists.newArrayList()
     curIndex = 0
     i = 0
     while i < self.arity:
         Preconditions.checkArgument(not (isinstance(term, (GdlFunction, ))))
         if self.functions.containsKey(i):
             sentenceBody.add(functionForm.getFunctionFromTuple(tuple_, curIndex))
             curIndex += functionForm.getTupleSize()
         else:
             sentenceBody.add(term)
             curIndex += 1
         i += 1
     if self.arity == 0:
         return GdlPool.getProposition(self.name)
     else:
         return GdlPool.getRelation(self.name, sentenceBody)