pub(crate) enum ResolvedEntry {
Atomic(&'static nibli_lexicon::PredicateEntry),
Compound(&'static nibli_lexicon::CompoundEntry),
}
impl ResolvedEntry {
fn place_index(&self, label: &str) -> Option<usize> {
match self {
ResolvedEntry::Atomic(e) => e.place_index(label),
ResolvedEntry::Compound(c) => c.place_index(label),
}
}
}
pub(crate) struct PredInfo {
pub(crate) surface: String,
pub(crate) arity: u8,
pub(crate) entry: ResolvedEntry,
}
pub(crate) fn lookup(word: &str) -> Result<PredInfo, String> {
if let Some(entry) = nibli_lexicon::alias(word) {
return Ok(PredInfo {
surface: word.to_owned(),
arity: entry.arity(),
entry: ResolvedEntry::Atomic(entry),
});
}
Err(format!(
"unknown predicate {word:?}: not a corpus name — \
unknown names are a compile error, never an arity-2 guess (NIBLI_KR §13)"
))
}
pub(crate) fn lookup_compound(parts: &[String]) -> Result<PredInfo, String> {
let spelling = parts.join("+");
if let Some(entry) = nibli_lexicon::compound(&spelling) {
return Ok(PredInfo {
surface: spelling,
arity: entry.arity(),
entry: ResolvedEntry::Compound(entry),
});
}
Err(format!(
"unknown compound predicate {spelling:?}: compounds resolve only via a \
committed corpus entry (place structures are conventional, never \
derivable) — curate one in nibli-lexicon/src/corpus/compounds.rs or \
use juxtaposition (NIBLI_KR §5)"
))
}
pub(crate) fn label_index(info: &PredInfo, label: &str) -> Option<usize> {
info.entry.place_index(label)
}
pub(crate) const PRONOUN_COLLISION_NAMES: [&str; 6] = ["me", "you", "we", "this", "that", "yonder"];