varar_core/step_role.rs
1//! Guess a step's role from its neighbours in document order — port of
2//! `step-role.ts` / `StepRole.java`. Purely structural (no keyword heuristics).
3
4use crate::step_kind::StepKind;
5
6/// The kinds of the steps immediately before and after the step being inferred.
7#[derive(Clone, Debug, PartialEq, Eq)]
8pub struct Neighbours {
9 pub before: Vec<StepKind>,
10 pub after: Vec<StepKind>,
11}
12
13impl Neighbours {
14 pub fn new(before: Vec<StepKind>, after: Vec<StepKind>) -> Neighbours {
15 Neighbours { before, after }
16 }
17}
18
19/// Guesses a step's role: nothing after it → most likely the observation
20/// (sensor); anything followed by other steps → most likely driving (stimulus).
21pub fn infer_step_role(neighbours: &Neighbours) -> StepKind {
22 if neighbours.after.is_empty() {
23 StepKind::Sensor
24 } else {
25 StepKind::Stimulus
26 }
27}