Skip to content

Commit 41273f3

Browse files
authored
Merge pull request #458 from AdaWorldAPI/fix/pearl-junction-deprecated-shim
fix(codex P1 #457): restore deprecated NarsRule + nars_rule() for back-compat
2 parents 063f7df + 34c53f6 commit 41273f3

1 file changed

Lines changed: 120 additions & 0 deletions

File tree

crates/lance-graph-contract/src/pearl_junction.rs

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,81 @@ impl PearlJunction {
9999
Self::Unrelated => None,
100100
}
101101
}
102+
103+
/// **Deprecated** — use [`Self::inference_type`] instead.
104+
///
105+
/// Back-compat shim preserved for downstream consumers that imported
106+
/// PR #456's `nars_rule() -> Option<NarsRule>` surface (per codex P1
107+
/// review on PR #457 — removing the method outright is a breaking
108+
/// change even one commit after introduction). New code should call
109+
/// `inference_type()`, which returns the canonical
110+
/// [`crate::nars::InferenceType`].
111+
///
112+
/// The mapping is identical (Chain / ChainRev → Deduction; Fork →
113+
/// Induction; Collider → Abduction); the returned [`NarsRule`] is a
114+
/// deprecated subset enum that `From`-converts into `InferenceType`.
115+
#[deprecated(
116+
since = "0.2.0",
117+
note = "Use `inference_type()` which returns the canonical `crate::nars::InferenceType`. `NarsRule` is preserved as a deprecated alias for back-compat with PR #456."
118+
)]
119+
#[allow(deprecated)]
120+
pub const fn nars_rule(self) -> Option<NarsRule> {
121+
// Route the deprecated v1 surface through inference_type() so the
122+
// junction → rule mapping lives in ONE place (per CodeRabbit on
123+
// PR #458 — avoid the same duplication-map drift class that
124+
// motivated the inference_type() introduction in #457).
125+
//
126+
// The full InferenceType taxonomy includes Revision + Synthesis
127+
// which are NOT junction-derivable (no Pearl junction maps to
128+
// either), so those arms return None defensively even though
129+
// they are unreachable in practice.
130+
match self.inference_type() {
131+
Some(InferenceType::Deduction) => Some(NarsRule::Deduction),
132+
Some(InferenceType::Induction) => Some(NarsRule::Induction),
133+
Some(InferenceType::Abduction) => Some(NarsRule::Abduction),
134+
Some(InferenceType::Revision) | Some(InferenceType::Synthesis) | None => None,
135+
}
136+
}
137+
}
138+
139+
/// **Deprecated** — use [`crate::nars::InferenceType`] instead.
140+
///
141+
/// Back-compat alias for PR #456's original three-variant NARS-rule
142+
/// enum. `NarsRule` always corresponds 1:1 to a subset of
143+
/// [`InferenceType`] (Deduction / Induction / Abduction); the full
144+
/// `InferenceType` taxonomy also includes Revision + Synthesis which
145+
/// are not junction-derivable. `From<NarsRule>` lifts to the canonical
146+
/// type for migration.
147+
///
148+
/// Removed in a future major bump; new code should not introduce
149+
/// references to this enum.
150+
#[deprecated(
151+
since = "0.2.0",
152+
note = "Use `crate::nars::InferenceType` instead. `NarsRule` is preserved as a back-compat alias for PR #456's original surface; `From<NarsRule>` lifts to the canonical type."
153+
)]
154+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
155+
pub enum NarsRule {
156+
/// Chain figure: `M -> P`, `S -> M` ⊢ `S -> P` (or the reverse).
157+
Deduction,
158+
/// Fork figure (common cause): `M -> P`, `M -> S` ⊢ `S -> P` (with
159+
/// confidence calibrated by Pearl's induction discounting).
160+
Induction,
161+
/// Collider figure (explaining-away): `P -> M`, `S -> M` ⊢ `S -> P`
162+
/// (with confidence calibrated by Pearl's abduction discounting).
163+
Abduction,
164+
}
165+
166+
#[allow(deprecated)]
167+
impl From<NarsRule> for InferenceType {
168+
/// Lift a deprecated [`NarsRule`] to the canonical
169+
/// [`InferenceType`]. The mapping is 1:1.
170+
fn from(r: NarsRule) -> Self {
171+
match r {
172+
NarsRule::Deduction => InferenceType::Deduction,
173+
NarsRule::Induction => InferenceType::Induction,
174+
NarsRule::Abduction => InferenceType::Abduction,
175+
}
176+
}
102177
}
103178

104179
/// A pair of SPO edges expressed as their four `NiblePath` endpoints.
@@ -345,4 +420,49 @@ mod tests {
345420
// Both edges' subjects are out-of-range → EMPTY.
346421
assert_eq!(EdgePair::new(bad1, real, bad2, real).classify(), PearlJunction::Unrelated);
347422
}
423+
424+
425+
// ===== Back-compat shim (codex P1 on PR #457) =====
426+
427+
/// The deprecated nars_rule() method must continue to work for
428+
/// downstream consumers that imported PR #456's surface. Verifies the
429+
/// 1:1 correspondence with inference_type().
430+
#[test]
431+
#[allow(deprecated)]
432+
fn deprecated_nars_rule_matches_inference_type() {
433+
let dog = NiblePath::root(0x1).child(0x1);
434+
let cat = NiblePath::root(0x1).child(0x2);
435+
let mammal = NiblePath::root(0x1);
436+
437+
let collider = EdgePair::new(dog, mammal, cat, mammal).classify();
438+
assert_eq!(collider.nars_rule(), Some(NarsRule::Abduction));
439+
assert_eq!(collider.inference_type(), Some(InferenceType::Abduction));
440+
441+
// Round-trip via From<NarsRule>
442+
let canonical: InferenceType = collider.nars_rule().unwrap().into();
443+
assert_eq!(canonical, collider.inference_type().unwrap());
444+
}
445+
446+
/// Unrelated returns None on both methods.
447+
#[test]
448+
#[allow(deprecated)]
449+
fn deprecated_nars_rule_none_when_unrelated() {
450+
let a = NiblePath::root(0x1);
451+
let b = NiblePath::root(0x2);
452+
let c = NiblePath::root(0x3);
453+
let d = NiblePath::root(0x4);
454+
let j = EdgePair::new(a, b, c, d).classify();
455+
assert_eq!(j.nars_rule(), None);
456+
assert_eq!(j.inference_type(), None);
457+
}
458+
459+
/// From<NarsRule> for InferenceType covers the three deprecated variants.
460+
#[test]
461+
#[allow(deprecated)]
462+
fn from_nars_rule_lifts_to_inference_type() {
463+
assert_eq!(InferenceType::from(NarsRule::Deduction), InferenceType::Deduction);
464+
assert_eq!(InferenceType::from(NarsRule::Induction), InferenceType::Induction);
465+
assert_eq!(InferenceType::from(NarsRule::Abduction), InferenceType::Abduction);
466+
}
467+
348468
}

0 commit comments

Comments
 (0)