ConverterBallotToStrictOrder¶
-
class
whalrus.
ConverterBallotToStrictOrder
(priority: whalrus.priorities.priority.Priority = Priority.UNAMBIGUOUS)[source]¶ Default converter to a strictly ordered ballot.
This is a default converter to a strictly ordered ballot (cf.
BallotOrder.is_strict
). It tries to infer the type of input and converts it to aBallotOrder
(possibly a ballot of a subclass, such asBallotLevels
), ensuring that the represented order is strict.- Parameters
priority (Priority) – The
Priority
used to break ties. Default:Priority.UNAMBIGUOUS
.
Examples
>>> converter = ConverterBallotToStrictOrder(priority=Priority.ASCENDING) >>> converter('a > b ~ c') BallotOrder(['a', 'b', 'c'], candidates={'a', 'b', 'c'}) >>> converter(['a', {'b', 'c'}]) BallotOrder(['a', 'b', 'c'], candidates={'a', 'b', 'c'}) >>> converter({'a': 10, 'b': 7, 'c': 0}) BallotLevels({'a': 10, 'b': 7, 'c': 0}, candidates={'a', 'b', 'c'}, scale=Scale()) >>> converter(BallotOneName('a', candidates={'a', 'b', 'c'})) BallotOrder(['a', 'b', 'c'], candidates={'a', 'b', 'c'}) >>> converter(BallotPlurality('a', candidates={'a', 'b', 'c'})) BallotOrder(['a', 'b', 'c'], candidates={'a', 'b', 'c'}) >>> converter(BallotVeto('a', candidates={'a', 'b', 'c'})) BallotOrder(['b', 'c', 'a'], candidates={'a', 'b', 'c'})