本文整理汇总了Python中java.util.Collections.frequency方法的典型用法代码示例。如果您正苦于以下问题:Python Collections.frequency方法的具体用法?Python Collections.frequency怎么用?Python Collections.frequency使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Collections
的用法示例。
在下文中一共展示了Collections.frequency方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from java.util import Collections [as 别名]
# 或者: from java.util.Collections import frequency [as 别名]
#.........这里部分代码省略.........
# flatten into a tuple
# Go through the vars/constants in the tuple
while i < len(conjunctTuple):
if isinstance(term, (GdlConstant, )):
constraintSlots.add(i)
constraintValues.add(term)
# TODO: What if tuple size ends up being 0?
# Need to keep that in mind
elif isinstance(term, (GdlVariable, )):
varsChosen.add(varIndex)
if self.sourceDefiningSlot.get(varIndex) == -1:
# We define it
self.sourceDefiningSlot.set(varIndex, j)
putDontCheck.add(True)
else:
# It's an overlap; we just check for consistency
putDontCheck.add(False)
else:
raise RuntimeException("Function returned in tuple")
i += 1
self.varsChosenBySource.add(ImmutableList.copyOf(varsChosen))
self.putDontCheckBySource.add(ImmutableList.copyOf(putDontCheck))
# Now we put the tuples together
# We use constraintSlots and constraintValues to check that the
# tuples have compatible values
for sentence in sentences:
# Check that it doesn't conflict with our headAssignment
if not headAssignment.isEmpty():
for var in headAssignment.keySet():
if tupleAssignment.containsKey(var) and tupleAssignment.get(var) != headAssignment.get(var):
continue
while c < len(constraintSlots):
if not longTuple.get(slot) == value:
continue
c += 1
while s < len(longTuple):
# constraintSlots is sorted in ascending order
if c < len(constraintSlots) and constraintSlots.get(c) == s:
c += 1
else:
shortTuple.add(longTuple.get(s))
s += 1
# The tuple fits the source conjunct
tuples.add(ImmutableList.copyOf(shortTuple))
# sortTuples(tuples); //Needed? Useful? Not sure. Probably not?
self.tuplesBySource.add(ImmutableList.copyOf(tuples))
j += 1
# We now want to see which we can give assignment functions to
self.valuesToCompute = ArrayList(len(self.varsToAssign))
for var in varsToAssign:
self.valuesToCompute.add(None)
self.indicesToChangeWhenNull = ArrayList(len(self.varsToAssign))
i = 0
while i < len(self.varsToAssign):
# Change itself, why not?
# Actually, instead let's try -1, to catch bugs better
self.indicesToChangeWhenNull.add(-1)
i += 1
# Now we have our functions already selected by the ordering
# bestOrdering.functionalConjunctIndices;
# Make AssignmentFunctions out of the ordering
functionalConjuncts = bestOrdering.getFunctionalConjuncts()
# print "functionalConjuncts: " + functionalConjuncts;
i = 0
while i < len(functionalConjuncts):
if functionalConjunct != None:
# These are the only ones that could be constant functions
if functionInfoMap != None:
functionInfo = functionInfoMap.get(conjForm)
if functionInfo != None:
# Now we need to figure out which variables are involved
# and which are suitable as functional outputs.
# 1) Which vars are in this conjunct?
# 2) Of these vars, which is "rightmost"?
# 3) Is it only used once in the relation?
if Collections.frequency(varsInSentence, rightmostVar) != 1:
continue
# Can't use it
# 4) Which slot is it used in in the relation?
# 5) Build an AssignmentFunction if appropriate.
# This should be able to translate from values of
# the other variables to the value of the wanted
# variable.
# We don't guarantee that this works until we check
if not function_.functional():
continue
self.valuesToCompute.set(index, function_)
remainingVarsInSentence.remove(rightmostVar)
self.indicesToChangeWhenNull.set(index, self.varsToAssign.indexOf(nextRightmostVar))
i += 1
# We now have the remainingVars also assigned their domains
# We also cover the distincts here
# Assume these are just variables and constants
self.distincts = ArrayList()
for literal in rule.getBody():
if isinstance(literal, (GdlDistinct, )):
self.distincts.add(literal)
computeVarsToChangePerDistinct()
# Need to add "distinct" restrictions to head assignment, too...
checkDistinctsAgainstHead()