pub struct Compiler { /* private fields */ }std only.Expand description
An external compiler that translates natural-language text into a SPARQL query.
Input bytes are copied to stdin, relying on the pattern’s default input-file
operand of -. The external program produces one UTF-8 SPARQL query for an
adapter, without Markdown fences or explanatory prose outside the query.
Dataset and vocabulary assumptions, and compatibility with the intended
adapter’s supported query forms, belong to that program.
This wrapper captures the generated query without parsing or executing it.
Use QueryOutput::Captured to retrieve it for an Adapter.
Input is consumed from its current position and is not rewound on subsequent
executions. Buffering, output routing, cancellation, and current stream-I/O
limitations follow crate::programs.
§Example
Compile a request, then pass the captured query to a dataset adapter:
use asimov_runner::{
Adapter, AdapterOptions, Compiler, CompilerOptions, GraphOutput,
QueryInput, QueryOutput, StreamExt, TextInput,
};
use std::io::Cursor;
let mut compiler = Compiler::new(
"asimov-example-compiler",
TextInput::AsyncRead(Box::new(Cursor::new(b"Describe the known cities.".to_vec()))),
QueryOutput::Captured,
CompilerOptions::default(),
);
let query = compiler.execute().await?;
let mut adapter = Adapter::new(
"asimov-example-adapter",
QueryInput::AsyncRead(Box::new(query)),
GraphOutput::Captured,
AdapterOptions::default(),
);
let mut graph = adapter.execute().await?;
while let Some(batch) = graph.next().await {
for bytes in batch?.lines() {
// Process this JSONL graph line.
}
}Implementations§
Source§impl Compiler
impl Compiler
Sourcepub fn new(
program: impl AsRef<OsStr>,
input: TextInput,
output: QueryOutput,
options: CompilerOptions,
) -> Self
pub fn new( program: impl AsRef<OsStr>, input: TextInput, output: QueryOutput, options: CompilerOptions, ) -> Self
Configures a compiler without starting it.
Forwards options.other as individual arguments in order. The pattern
defines no standard model or format flags, so none are generated.
input and output select stdin and stdout handling; stderr is captured
for failure diagnostics.
To select a named input file, supply its path through options.other
after any extension options and use TextInput::Ignored. No standard
output-file operand is defined. This constructor does not validate
operands, extension support, or the input’s encoding.
Sourcepub async fn execute(&mut self) -> CompilerResult
pub async fn execute(&mut self) -> CompilerResult
Sends the remaining text input to a new child and returns captured query bytes.
§Errors
Returns an ExecutorError if spawning, copying input, or waiting fails,
or if the compiler exits unsuccessfully. Query syntax and UTF-8 validity
are the external program’s responsibility and are not checked here.