本文整理汇总了Python中java.util.Collections.disjoint方法的典型用法代码示例。如果您正苦于以下问题:Python Collections.disjoint方法的具体用法?Python Collections.disjoint怎么用?Python Collections.disjoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Collections
的用法示例。
在下文中一共展示了Collections.disjoint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getCondensationSet
# 需要导入模块: from java.util import Collections [as 别名]
# 或者: from java.util.Collections import disjoint [as 别名]
def getCondensationSet(cls, rule, model, checker, sentenceNameSource):
""" generated source for method getCondensationSet """
varsInRule = GdlUtils.getVariables(rule)
varsInHead = GdlUtils.getVariables(rule.getHead())
varsNotInHead = ArrayList(varsInRule)
varsNotInHead.removeAll(varsInHead)
for var in varsNotInHead:
ConcurrencyUtils.checkForInterruption()
for literal in rule.getBody():
if GdlUtils.getVariables(literal).contains(var):
minSet.add(literal)
for literal in minSet:
if isinstance(literal, (GdlRelation, )):
varsSupplied.addAll(GdlUtils.getVariables(literal))
elif isinstance(literal, (GdlDistinct, )) or isinstance(literal, (GdlNot, )):
varsNeeded.addAll(GdlUtils.getVariables(literal))
varsNeeded.removeAll(varsSupplied)
if not varsNeeded.isEmpty():
continue
for varNeeded in varsNeeded:
for literal in rule.getBody():
if isinstance(literal, (GdlRelation, )):
if GdlUtils.getVariables(literal).contains(varNeeded):
suppliers.add(literal)
candidateSuppliersList.add(suppliers)
for suppliers in candidateSuppliersList:
if Collections.disjoint(suppliers, literalsToAdd):
literalsToAdd.add(suppliers.iterator().next())
minSet.addAll(literalsToAdd)
if goodCondensationSetByHeuristic(minSet, rule, model, checker, sentenceNameSource):
return minSet
return None
示例2: getFunctionAddedChildren
# 需要导入模块: from java.util import Collections [as 别名]
# 或者: from java.util.Collections import disjoint [as 别名]
#.........这里部分代码省略.........
# Map is from potential set of dependencies to function indices
# Create this map...
while i < len(self.functionalSentencesInfo):
# Variables already in varOrdering don't go in dependents list
producibleVars.removeAll(self.varOrdering)
allVars.removeAll(self.varOrdering)
for producibleVar in producibleVars:
dependencies.addAll(allVars)
dependencies.remove(producibleVar)
if not functionsHavingDependencies.containsKey(dependencies):
functionsHavingDependencies.put(dependencies, HashSet())
functionsHavingDependencies.get(dependencies).add(i)
i += 1
# Now, we can keep creating functions to generate the remaining variables
while len(self.varOrdering) < len(self.varsToAssign):
if functionsHavingDependencies.isEmpty():
raise RuntimeException("We should not run out of functions we could use")
# Find the smallest set of dependencies
if functionsHavingDependencies.containsKey(Collections.emptySet()):
dependencySetToUse = Collections.emptySet()
else:
for dependencySet in functionsHavingDependencies.keySet():
if len(dependencySet) < smallestSize:
smallestSize = len(dependencySet)
dependencySetToUse = dependencySet
# See if any of the functions are applicable
for function_ in functions:
producibleVars.removeAll(dependencySetToUse)
producibleVars.removeAll(self.varOrdering)
if not producibleVars.isEmpty():
functionToUse = function_
varProduced = producibleVars.iterator().next()
break
if functionToUse == -1:
# None of these functions were actually useful now?
# Dump the dependency set
functionsHavingDependencies.remove(dependencySetToUse)
else:
# Apply the function
# 1) Add the remaining dependencies as iterated variables
for var in dependencySetToUse:
self.varOrdering.add(var)
self.functionalConjunctIndices.add(-1)
self.varSources.add(-1)
# 2) Add the function's produced variable (varProduced)
self.varOrdering.add(varProduced)
self.functionalConjunctIndices.add(functionToUse)
self.varSources.add(-1)
# 3) Remove all vars added this way from all dependency sets
addedVars.addAll(dependencySetToUse)
addedVars.add(varProduced)
# Tricky, because we have to merge sets
# Easier to use a new map
for entry in functionsHavingDependencies.entrySet():
newKey.removeAll(addedVars)
if not newFunctionsHavingDependencies.containsKey(newKey):
newFunctionsHavingDependencies.put(newKey, HashSet())
newFunctionsHavingDependencies.get(newKey).addAll(entry.getValue())
functionsHavingDependencies = newFunctionsHavingDependencies
# 4) Remove this function from the lists?
for functionSet in functionsHavingDependencies.values():
functionSet.remove(functionToUse)
# Now we need to actually return the ordering in a list
# Here's the quick way to do that...
# (since we've added all the new stuff to ourself already)
return Collections.singletonList(IterationOrderCandidate(self))
else:
# Let's try a new technique for restricting the space of possibilities...
# We already have an ordering on the functions
# Let's try to constrain things to that order
# Namely, if i<j and constant form j is already used as a function,
# we cannot use constant form i UNLESS constant form j supplies
# as its variable something used by constant form i.
# We might also try requiring that c.f. i NOT provide a variable
# used by c.f. j, though there may be multiple possibilities as
# to what it could provide.
if not self.functionalConjunctIndices.isEmpty():
lastFunctionUsedIndex = Collections.max(self.functionalConjunctIndices)
while i < len(self.functionalConjunctIndices):
if self.functionalConjunctIndices.get(i) != -1:
varsProducedByFunctions.add(self.varOrdering.get(i))
i += 1
while i < len(self.functionalSentencesInfo):
if i < lastFunctionUsedIndex:
# We need to figure out whether i could use any of the
# vars we're producing with functions
# TODO: Try this with a finer grain
# i.e., see if i needs a var from a function that is after
# it, not one that might be before it
if Collections.disjoint(varsInSentence, varsProducedByFunctions):
continue
# What is the best variable to grab from this form, if there are any?
if bestVariable == None:
continue
children.add(newCandidate)
i += 1
# If there are no more functions to add, add the completed version
if children.isEmpty():
children.add(IterationOrderCandidate(self))
return children