-
Notifications
You must be signed in to change notification settings - Fork 0
research wafer inc duckling api public functions
Source: src/lib.rs
| Field | Value |
|---|---|
| Crate name | duckling |
| Version | 0.4.0 |
| Cargo.toml | Cargo.toml |
| Crate type |
rlib (library, not cdylib) |
| License | BSD-3-Clause |
| Repository | https://github.com/wafer-inc/duckling |
The Cargo.toml defines no [lib] section, so the crate type defaults to
rlib. There are no magnus or rb-sys dependencies in the crate
itself — those belong exclusively to the gem's ext/ layer.
pub fn parse(
text: &str,
locale: &Locale,
dims: &[DimensionKind],
context: &Context,
options: &Options,
) -> Vec<Entity>Defined in src/lib.rs (line 73).
| Parameter | Type | Notes |
|---|---|---|
text |
&str |
Input text to parse. |
locale |
&Locale |
Language + optional region. See Locale System. |
dims |
&[DimensionKind] |
Which dimensions to extract. Pass &[] (empty slice) to extract all 14 dimensions. |
context |
&Context |
Reference time and locale for resolving relative expressions. |
options |
&Options |
Controls latent entity inclusion. |
Vec<Entity> — zero or more non-overlapping parsed entities, ranked by
confidence. Overlapping spans are deduplicated by the ranker before
returning.
In release builds (#[cfg(not(debug_assertions))]) the function wraps the
inner parser in catch_unwind, logs any panic via log::error!, and
returns an empty Vec rather than unwinding the caller. In debug builds the
panic propagates normally.
use duckling::{parse, Locale, Lang, Context, Options, DimensionKind};
let context = Context::default();
let options = Options::default();
let locale = Locale::new(Lang::EN, None);
let entities = parse(
"I need 3 degrees celsius",
&locale,
&[DimensionKind::Temperature],
&context,
&options,
);
assert!(!entities.is_empty());pub fn parse_en(text: &str, dims: &[DimensionKind]) -> Vec<Entity>Defined in src/lib.rs (line 166).
Thin wrapper that hard-codes:
-
locale = Locale::new(Lang::EN, None)— English, no region -
context = Context::default()—Utc::now()as reference time, EN-US locale -
options = Options::default()— latent entities excluded
use duckling::{parse_en, Entity, DimensionKind, DimensionValue};
assert_eq!(
parse_en("forty-two", &[DimensionKind::Numeral]),
vec![Entity {
body: "forty-two".into(),
start: 0,
end: 9,
latent: Some(false),
value: DimensionValue::Numeral(42.0),
}]
);impl Default for Context {
fn default() -> Self {
Self::new(Utc::now().fixed_offset(), Locale::default())
}
}Locale::default() is Locale { lang: Lang::EN, region: Some(Region::US) }.
So Context::default() = current UTC time as a fixed-offset datetime, with
EN-US locale.
#[derive(Debug, Clone, Default)]
pub struct Options {
pub with_latent: bool,
}Options::default() = Options { with_latent: false }.
With with_latent: false (the default), latent/ambiguous entities are
excluded from results. Set with_latent: true to include them.
// "morning" is latent — only returned when with_latent is true
let opts = Options { with_latent: true };
let results = parse("morning", &locale, &[DimensionKind::Time], &context, &opts);
// results contains a Time entity with latent = Some(true)
let results = parse("morning", &locale, &[DimensionKind::Time], &context, &Options::default());
// results is empty — latent filtered outTwo additional items are pub-gated behind #[cfg(feature = "train")] and
are not part of the normal runtime surface:
pub fn train_classifiers(locale, corpus, dims) -> Classifierspub use ranking::train::TrainingCorpuspub use ranking::Classifiers
The train feature is not enabled by the gem; these are irrelevant for
wrapping.