inference_engine/reasoning/target/
mod.rs1mod engine;
3mod grounding;
4use super::{PropositionLimits, PropositionReport, ReasoningError};
5use crate::entailment::{EntailmentError, EntailmentLimits};
6pub use engine::Rdf12TargetConstructor;
7use serde::{Deserialize, Serialize};
8use std::{
9 error::Error,
10 fmt,
11 num::{NonZeroU32, NonZeroU64},
12};
13
14#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
16#[serde(deny_unknown_fields)]
17pub struct TargetConstructionLimits {
18 matching: EntailmentLimits,
19 propositions: PropositionLimits,
20 slots: NonZeroU32,
21 work: NonZeroU64,
22}
23impl TargetConstructionLimits {
24 pub const fn new(
27 matching: EntailmentLimits,
28 propositions: PropositionLimits,
29 slots: NonZeroU32,
30 work: NonZeroU64,
31 ) -> Self {
32 Self {
33 matching,
34 propositions,
35 slots,
36 work,
37 }
38 }
39}
40
41#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
43#[serde(deny_unknown_fields)]
44pub struct TargetConstructionReport {
45 pub substitutions: u64,
47 pub matching_steps: u64,
49 pub grounding_steps: u64,
51 pub propositions: PropositionReport,
53}
54
55#[derive(Debug)]
57pub enum TargetConstructionError<E> {
58 Matching(EntailmentError<E>),
60 Reasoning(ReasoningError<E>),
62 SlotLimit,
64 WorkLimit,
66 Identity,
68 CounterOverflow,
70}
71impl<E: fmt::Display> fmt::Display for TargetConstructionError<E> {
72 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
73 match self {
74 Self::Matching(e) => write!(f, "target construction matching failed: {e}"),
75 Self::Reasoning(e) => write!(f, "target construction failed: {e}"),
76 Self::SlotLimit => f.write_str("target grounding slot limit exceeded"),
77 Self::WorkLimit => f.write_str("target grounding work limit exceeded"),
78 Self::Identity => f.write_str("target construction dictionary identity mismatch"),
79 Self::CounterOverflow => f.write_str("target construction counter overflow"),
80 }
81 }
82}
83impl<E: Error + 'static> Error for TargetConstructionError<E> {
84 fn source(&self) -> Option<&(dyn Error + 'static)> {
85 match self {
86 Self::Matching(e) => Some(e),
87 Self::Reasoning(e) => Some(e),
88 _ => None,
89 }
90 }
91}
92impl<E> From<EntailmentError<E>> for TargetConstructionError<E> {
93 fn from(e: EntailmentError<E>) -> Self {
94 Self::Matching(e)
95 }
96}
97impl<E> From<ReasoningError<E>> for TargetConstructionError<E> {
98 fn from(e: ReasoningError<E>) -> Self {
99 Self::Reasoning(e)
100 }
101}