Skip to main content

asimov_patterns/programs/
reasoner.rs

1// This is free and unencumbered software released into the public domain.
2
3//! RDF entailment: the reasoner marker trait and serialization options.
4
5use crate::Execute;
6use alloc::{string::String, vec::Vec};
7use bon::Builder;
8
9/// An RDF entailer that derives consequences under a documented regime or rule system.
10///
11/// The program defines whether output includes the original statements or
12/// only additional consequences, and how named graphs and inconsistent input
13/// are handled. The pattern specifies no particular reasoning algorithm, rule
14/// language, or completeness guarantee.
15///
16/// # Command-line contract
17///
18/// `PROGRAM [OPTIONS] [INPUT-FILE [OUTPUT-FILE]]`
19///
20/// Input and output default to stdin and stdout. A single operand selects
21/// input; two select input then output, with `-` denoting a standard stream.
22/// [`ReasonerOptions`] selects RDF serializations, both defaulting to `jsonl`.
23///
24/// `T` is the implementation's result representation. See [`crate::programs`]
25/// for links to concrete execution behavior and the [reasoner specification][spec].
26///
27/// [spec]: https://asimov-specs.github.io/program-patterns/#reasoner
28pub trait Reasoner<T>: Execute<T> {}
29
30/// RDF input/output formats and additional arguments for a [`Reasoner`].
31///
32/// `Default` leaves formats unset and `other` empty. The process wrapper omits
33/// unset flags and lets the program apply its defaults. These options do not
34/// select a standard entailment regime or validate the RDF payloads.
35///
36/// # Examples
37///
38/// ```rust
39/// use asimov_patterns::ReasonerOptions;
40///
41/// let options = ReasonerOptions::builder()
42///     .input("jsonl")
43///     .output("jsonl")
44///     .build();
45/// ```
46#[derive(Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd, Builder)]
47#[builder(derive(Debug), on(String, into))]
48#[cfg_attr(feature = "clap", derive(clap::Args))]
49pub struct ReasonerOptions {
50    /// Additional arguments, including optional input and output file operands.
51    ///
52    /// The wrapper appends these after generated format options. Put extension
53    /// options before files; each string is one literal argument. See
54    /// [`crate::programs`] for operand ordering and standard-stream selection.
55    #[builder(field)]
56    pub other: Vec<String>,
57
58    /// RDF input serialization passed as `--input=FORMAT` (`-i` in the CLI).
59    ///
60    /// `None` omits the option; the specified program default is `jsonl`.
61    /// This is a format token, not an input filename or a rule language.
62    pub input: Option<String>,
63
64    /// Entailed RDF serialization passed as `--output=FORMAT` (`-o` in the CLI).
65    ///
66    /// `None` omits the option; the specified program default is `jsonl`.
67    /// This selects neither an output file nor whether input statements are included.
68    pub output: Option<String>,
69}
70
71impl<S: reasoner_options_builder::State> ReasonerOptionsBuilder<S> {
72    /// Appends one literal argument to [`ReasonerOptions::other`], preserving order.
73    pub fn other(mut self, flag: impl Into<String>) -> Self {
74        self.other.push(flag.into());
75        self
76    }
77
78    /// Appends a present argument to [`ReasonerOptions::other`]; `None` adds nothing.
79    pub fn maybe_other(mut self, flag: Option<impl Into<String>>) -> Self {
80        if let Some(flag) = flag {
81            self.other.push(flag.into());
82        }
83        self
84    }
85}