本文整理匯總了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()