pub struct Audience { /* private fields */ }Expand description
An audience is a strict partial order over values, represented as
ranked tiers. Each inner Vec<Value> is one tier; values within a
tier are equally preferred. Earlier tiers are strictly more preferred
than later tiers.
§Examples
use argumentation_values::{Audience, Value};
let life = Value::new("life");
let property = Value::new("property");
// Total order: life > property
let strict = Audience::total([life.clone(), property.clone()]);
assert!(strict.prefers(&life, &property));
assert!(!strict.prefers(&property, &life));
// Incomparable values
let flat = Audience::from_tiers(vec![vec![life.clone(), property.clone()]]);
assert!(!flat.prefers(&life, &property));
assert!(!flat.prefers(&property, &life));Implementations§
Source§impl Audience
impl Audience
Sourcepub fn total<I: IntoIterator<Item = Value>>(ranked: I) -> Self
pub fn total<I: IntoIterator<Item = Value>>(ranked: I) -> Self
Construct a total ordering from an iterator of values, most preferred first.
Sourcepub fn from_tiers(tiers: Vec<Vec<Value>>) -> Self
pub fn from_tiers(tiers: Vec<Vec<Value>>) -> Self
Construct from explicit ranked tiers. Each inner vec is one tier of equally preferred values.
Sourcepub fn prefers(&self, a: &Value, b: &Value) -> bool
pub fn prefers(&self, a: &Value, b: &Value) -> bool
Returns true iff a is strictly preferred to b under this audience.
Returns false if either value is unranked (incomparable).
Sourcepub fn rank(&self, v: &Value) -> Option<usize>
pub fn rank(&self, v: &Value) -> Option<usize>
0-indexed tier of v (0 = most preferred), or None if v is
unranked (not mentioned in any tier).
Public so consumers (e.g., ValueAwareScorer) can compute boost
magnitudes without re-implementing the lookup.
Sourcepub fn values(&self) -> impl Iterator<Item = &Value>
pub fn values(&self) -> impl Iterator<Item = &Value>
Iterate the distinct values mentioned in this audience.
Sourcepub fn value_count(&self) -> usize
pub fn value_count(&self) -> usize
Number of distinct values in this audience.
Sourcepub fn tier_count(&self) -> usize
pub fn tier_count(&self) -> usize
Number of tiers (rank levels).