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))]
48pub struct ReasonerOptions {
49    /// Additional arguments, including optional input and output file operands.
50    ///
51    /// The wrapper appends these after generated format options. Put extension
52    /// options before files; each string is one literal argument. See
53    /// [`crate::programs`] for operand ordering and standard-stream selection.
54    #[builder(field)]
55    pub other: Vec<String>,
56
57    /// RDF input serialization passed as `--input=FORMAT` (`-i` in the CLI).
58    ///
59    /// `None` omits the option; the specified program default is `jsonl`.
60    /// This is a format token, not an input filename or a rule language.
61    pub input: Option<String>,
62
63    /// Entailed RDF serialization passed as `--output=FORMAT` (`-o` in the CLI).
64    ///
65    /// `None` omits the option; the specified program default is `jsonl`.
66    /// This selects neither an output file nor whether input statements are included.
67    pub output: Option<String>,
68}
69
70impl<S: reasoner_options_builder::State> ReasonerOptionsBuilder<S> {
71    /// Appends one literal argument to [`ReasonerOptions::other`], preserving order.
72    pub fn other(mut self, flag: impl Into<String>) -> Self {
73        self.other.push(flag.into());
74        self
75    }
76
77    /// Appends a present argument to [`ReasonerOptions::other`]; `None` adds nothing.
78    pub fn maybe_other(mut self, flag: Option<impl Into<String>>) -> Self {
79        if let Some(flag) = flag {
80            self.other.push(flag.into());
81        }
82        self
83    }
84}