def addSentencesTrueByRules(cls, sentencesByForm, model): """ generated source for method addSentencesTrueByRules """ prover = AimaProver(model.getDescription()) for form in model.getConstantSentenceForms(): for result in prover.askAll(query, ImmutableSet.of()): ConcurrencyUtils.checkForInterruption() # Variables may end up being replaced with functions, which is not # what we want here, so we have to double-check that the form is correct. if form.matches(result): sentencesByForm.put(form, result)
def getMatchingAndUpstream(cls, allNodes, dependencyGraph, matcher): """ generated source for method getMatchingAndUpstream """ results = Sets.newHashSet() toTry = Queues.newArrayDeque() toTry.addAll(Collections2.filter(allNodes, matcher)) while not toTry.isEmpty(): if not results.contains(curElem): results.add(curElem) toTry.addAll(dependencyGraph.get(curElem)) return ImmutableSet.copyOf(results)
def applyAmbiguities(cls, originalRule, ambiguitiesByOriginalForm, model): """ generated source for method applyAmbiguities """ rules = Lists.newArrayList(originalRule) # Each literal can potentially multiply the number of rules we have, so # we apply each literal separately to the entire list of rules so far. for literal in Iterables.concat(ImmutableSet.of(originalRule.getHead()), originalRule.getBody()): for rule in rules: Preconditions.checkArgument(originalRule.arity() == rule.arity()) newRules.addAll(applyAmbiguitiesForLiteral(literal, rule, ambiguitiesByOriginalForm, model)) rules = newRules return rules
def applyRuleBodyOnlyPropagation(cls, neededConstantsByForm, curDomains, model): """ generated source for method applyRuleBodyOnlyPropagation """ somethingChanged = False for rule in getRules(model.getDescription()): for var in ImmutableSet.copyOf(GdlUtils.getVariables(rule)): if not varsInHead.contains(var): if neededConstants == None: raise IllegalStateException("var is " + var + ";\nvarDomains key set is " + varDomains.keySet() + ";\nvarsInHead is " + varsInHead + ";\nrule is " + rule) for conjunct in rule.getBody(): somethingChanged |= addPossibleValuesToConjunct(neededConstants, conjunct, var, neededConstantsByForm, model) return somethingChanged
def getAmbiguitiesByOriginalForm(cls, model): """ generated source for method getAmbiguitiesByOriginalForm """ result = ArrayListMultimap.create() formsByName = getFormsByName(model) for name in formsByName.keySet(): for form in forms: result.putAll(form, getAmbiguities(form, forms)) allForms = ImmutableSet.copyOf(formsByName.values()) for ambiguity in result.values(): Assert.assertTrue(allForms.contains(ambiguity.getOriginal())) Assert.assertTrue(allForms.contains(ambiguity.getReplacement())) return result
def load(self): """ Creates and configures the context. """ if not self.__context: # Avoid loading the same context twice props = self._load_config() log.debug("Connecting to %s as %s" % (props.getProperty("abiquo.endpoint"), self.__config.user)) self.__context = AbiquoContextFactory().createContext( self.__config.user, self.__config.password, ImmutableSet.of(NullLoggingModule()), props) # Close context automatically when exiting atexit.register(self.__del__) return self.__context
def propagatePossibleConstants(cls, newPossibleConstantsByForm, curDomain, model): """ generated source for method propagatePossibleConstants """ # Injection: Go from the intersections of variable values in rules to the # values in their heads somethingChanged = False for rule in getRules(model.getDescription()): for varInHead in ImmutableSet.copyOf(GdlUtils.getVariables(rule.getHead())): domainsOfHeadVars.put(varInHead, domain) somethingChanged |= addPossibleValuesToSentence(domain, head, varInHead, newPossibleConstantsByForm, model) # Language-based injections somethingChanged |= applyLanguageBasedInjections(GdlPool.INIT, GdlPool.TRUE, newPossibleConstantsByForm) somethingChanged |= applyLanguageBasedInjections(GdlPool.NEXT, GdlPool.TRUE, newPossibleConstantsByForm) somethingChanged |= applyLanguageBasedInjections(GdlPool.LEGAL, GdlPool.DOES, newPossibleConstantsByForm) return somethingChanged
def mergeStrata(cls, toMerge, toAdd, strataDependencyGraph): """ generated source for method mergeStrata """ newStratum = ImmutableSet.copyOf(Iterables.concat(toMerge)) for oldStratum in toMerge: toAdd.remove(oldStratum) toAdd.add(newStratum) # Change the keys for oldStratum in toMerge: strataDependencyGraph.putAll(newStratum, parents) strataDependencyGraph.removeAll(oldStratum) # Change the values for entry in ImmutableList.copyOf(strataDependencyGraph.entries()): if toMerge.contains(entry.getValue()): strataDependencyGraph.remove(entry.getKey(), entry.getValue()) strataDependencyGraph.put(entry.getKey(), newStratum)
def create(cls, form, domain): """ generated source for method create """ domainsForSlotsBuilder = Lists.newArrayList() i = 0 while i < form.getTupleSize(): domainsForSlotsBuilder.add(ImmutableSet.builder()) i += 1 for sentence in domain: assert form.matches(sentence) if len(tuple_) != form.getTupleSize(): raise IllegalArgumentException() while i < len(tuple_): domainsForSlotsBuilder.get(i).add(constant) i += 1 domainsForSlots = ImmutableList.builder() for builder in domainsForSlotsBuilder: domainsForSlots.add(builder.build()) return FullSentenceFormDomain(form, ImmutableList.copyOf(domain), domainsForSlots.build())
def __init__(self, interfaceClass): """ generated source for method __init__ """ self.interfaceClass = interfaceClass self.allClasses = ImmutableSet.copyOf(self.REFLECTIONS.getSubTypesOf(interfaceClass)) self.concreteClasses = ImmutableSet.copyOf(Sets.filter(self.allClasses, self.IS_CONCRETE_CLASS))
def findSentenceForms(self): """ generated source for method findSentenceForms """ createModel() return ImmutableSet.copyOf(getSentenceFormsFromModel())
def getConstantSentenceForms(cls, sentenceForms, dependencyGraph): """ generated source for method getConstantSentenceForms """ augmentedGraph = augmentGraphWithLanguageRules(dependencyGraph, sentenceForms) changingSentenceForms = DependencyGraphs.getMatchingAndDownstream(sentenceForms, augmentedGraph, Predicates.or_(SentenceForms.TRUE_PRED, SentenceForms.DOES_PRED)) return ImmutableSet.copyOf(Sets.difference(sentenceForms, changingSentenceForms))
def createStrataDependencyGraph(cls, dependencyGraph): """ generated source for method createStrataDependencyGraph """ strataDependencyGraph = HashMultimap.create() for entry in dependencyGraph.entries(): strataDependencyGraph.put(ImmutableSet.of(entry.getKey()), ImmutableSet.of(entry.getValue())) return strataDependencyGraph
def createAllStrata(cls, allElements): """ generated source for method createAllStrata """ result = Sets.newHashSet() for element in allElements: result.add(ImmutableSet.of(element)) return result
def create(cls, form, constantChecker): """ generated source for method create """ return FunctionInfoImpl(form, ImmutableSet.copyOf(constantChecker.getTrueSentences(form)))
def copyOf(cls, other): """ generated source for method copyOf """ if isinstance(other, (ImmutableSentenceDomainModel, )): return cls.copyOf((other).getFormModel()) elif isinstance(other, (ImmutableSentenceFormModel, )): return other rulesByForm = ImmutableSetMultimap.builder() trueSentencesByForm = ImmutableSetMultimap.builder() for form in other.getSentenceForms(): rulesByForm.putAll(form, other.getRules(form)) trueSentencesByForm.putAll(form, other.getSentencesListedAsTrue(form)) return ImmutableSentenceFormModel(ImmutableList.copyOf(other.getDescription()), ImmutableSet.copyOf(other.getSentenceForms()), ImmutableSet.copyOf(other.getConstantSentenceForms()), ImmutableSet.copyOf(other.getIndependentSentenceForms()), ImmutableSetMultimap.copyOf(other.getDependencyGraph()), rulesByForm.build(), trueSentencesByForm.build())
def create(cls, form): """ generated source for method create """ return cls.create(form, ImmutableSet.of())
def getIndependentSentenceForms(cls, sentenceForms, dependencyGraph): """ generated source for method getIndependentSentenceForms """ augmentedGraph = augmentGraphWithLanguageRules(dependencyGraph, sentenceForms) moveDependentSentenceForms = DependencyGraphs.getMatchingAndDownstream(sentenceForms, augmentedGraph, SentenceForms.DOES_PRED) return ImmutableSet.copyOf(Sets.difference(sentenceForms, moveDependentSentenceForms))