Skip to main content

prosaic_core/
rst.rs

1//! Rhetorical Structure Theory relations for discourse labeling.
2
3/// A rhetorical relation between a discourse unit and its predecessor.
4///
5/// See Mann & Thompson (1988). The subset below covers the eight most-common
6/// relations in transaction/change-report narratives. When an RST relation
7/// is attached to an event in a [`crate::DocumentPlan`], the renderer uses
8/// the relation to pick a discourse marker ("Furthermore", "However",
9/// "As a result", etc.) instead of the default inter-sentence space.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
11#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
12pub enum RstRelation {
13    /// This unit adds detail to the previous unit.
14    Elaboration,
15    /// This unit contrasts with the previous unit.
16    Contrast,
17    /// This unit is caused by the previous unit.
18    Cause,
19    /// This unit is a result of the previous unit.
20    Result,
21    /// This unit runs counter to an expectation set up by the previous unit.
22    Concession,
23    /// This unit follows the previous unit in time.
24    Sequence,
25    /// This unit is conditional on the previous unit.
26    Condition,
27    /// This unit provides context for the previous unit.
28    Background,
29    /// This unit summarizes the preceding units.
30    Summary,
31}
32
33#[cfg(test)]
34mod tests {
35    use super::*;
36
37    #[test]
38    fn variants_are_distinct() {
39        assert_ne!(RstRelation::Elaboration, RstRelation::Contrast);
40        assert_ne!(RstRelation::Cause, RstRelation::Result);
41    }
42
43    #[cfg(feature = "serde")]
44    #[test]
45    fn serde_round_trip() {
46        let rel = RstRelation::Elaboration;
47        let json = serde_json::to_string(&rel).unwrap();
48        let back: RstRelation = serde_json::from_str(&json).unwrap();
49        assert_eq!(rel, back);
50    }
51}