ja-inventory: rev 5 concepts and frames for the original bed (model-drafted, Validation-informed), weksa inventory admit, onto:ja-JP:15 (#54)

This commit is contained in:
Weksa 2026-11-12 18:08:04 +00:00
commit 7babf8aadc
9 changed files with 130 additions and 162 deletions

View file

@ -223,19 +223,22 @@ impl EditDraft {
}
/// The revision after `base` this edit asks for, and the entries it adds.
/// `None` when the edit makes no change or more than [`MAX_EDIT_CHANGES`].
/// `None` when the edit makes no change or more than `max_changes`. The
/// loop's cycle passes [`MAX_EDIT_CHANGES`]; the CLI's `inventory admit`
/// passes its own larger cap for a draft reviewed whole in its cut.
/// Every id is the store's: an added entry takes the next number of its
/// family after the highest in `inventory`, retired entries included, in
/// draft order. Nothing else is judged here: the gloss, the entry's shape,
/// whether a retire target is live and a repeated id are
/// `InventoryStore::admit_revision`'s to refuse.
pub(crate) fn into_revision(
pub fn into_revision(
self,
inventory: &Inventory,
base: u32,
max_changes: usize,
) -> Option<(InventoryRevision, Vec<InventoryEntry>)> {
let count = self.add.len() + self.retire.len();
if count == 0 || count > MAX_EDIT_CHANGES {
if count == 0 || count > max_changes {
return None;
}
let n = base.checked_add(1)?;
@ -583,7 +586,7 @@ mod tests {
InvId::parse("frame:2").unwrap(),
],
};
let (rev, entries) = draft.clone().into_revision(&inv, 6).unwrap();
let (rev, entries) = draft.clone().into_revision(&inv, 6, MAX_EDIT_CHANGES).unwrap();
let ids: Vec<String> = entries.iter().map(|e| e.id.to_string()).collect();
// After the highest of the family, retired ones included, in draft order.
assert_eq!(ids, ["concept:4", "role:1", "concept:5", "frame:3"]);
@ -626,20 +629,25 @@ mod tests {
.collect(),
retire: vec![],
};
assert!(adds(0).into_revision(&inv, 1).is_none());
assert!(adds(1).into_revision(&inv, 1).is_some());
assert_eq!(adds(8).into_revision(&inv, 1).unwrap().1.len(), 8);
assert!(adds(9).into_revision(&inv, 1).is_none());
assert!(adds(0).into_revision(&inv, 1, MAX_EDIT_CHANGES).is_none());
assert!(adds(1).into_revision(&inv, 1, MAX_EDIT_CHANGES).is_some());
assert_eq!(adds(8).into_revision(&inv, 1, MAX_EDIT_CHANGES).unwrap().1.len(), 8);
assert!(adds(9).into_revision(&inv, 1, MAX_EDIT_CHANGES).is_none());
// Adds and retires count together.
let mixed = |a: usize, r: usize| EditDraft {
add: (0..a).map(|_| add(Family::Concept, "g")).collect(),
retire: vec![InvId::parse("concept:1").unwrap(); r],
};
assert!(mixed(4, 4).into_revision(&inv, 1).is_some());
assert!(mixed(4, 5).into_revision(&inv, 1).is_none());
assert!(mixed(0, 9).into_revision(&inv, 1).is_none());
assert!(mixed(4, 4).into_revision(&inv, 1, MAX_EDIT_CHANGES).is_some());
assert!(mixed(4, 5).into_revision(&inv, 1, MAX_EDIT_CHANGES).is_none());
assert!(mixed(0, 9).into_revision(&inv, 1, MAX_EDIT_CHANGES).is_none());
// A repeated retire is the door's to refuse, not this fn's.
assert!(mixed(0, 2).into_revision(&inv, 1).is_some());
assert!(mixed(0, 2).into_revision(&inv, 1, MAX_EDIT_CHANGES).is_some());
// The cap is the caller's.
let (_, entries) = adds(200).into_revision(&inv, 1, 256).unwrap();
assert_eq!(entries.first().unwrap().id.to_string(), "concept:2");
assert_eq!(entries.last().unwrap().id.to_string(), "concept:201");
assert!(adds(257).into_revision(&inv, 1, 256).is_none());
}
#[test]

View file

@ -8,7 +8,7 @@ use clap::error::{ContextKind, ContextValue, ErrorKind};
use clap::{Args, Parser, Subcommand, ValueEnum};
use unicode_normalization::UnicodeNormalization;
use weksa::corpus::{CorpusItem, ModelFamily, NameSpan, Source, Turn};
use weksa::encode::OntologyDraft;
use weksa::encode::{EditDraft, OntologyDraft};
use weksa::entity::{Entity, EntityOrigin, LanguageForms, Pronunciation};
use weksa::inventory::{proof_revision, seed, speaker_scene_revision};
use weksa::packet::{FeatValue, FeatureValue, Grade};
@ -200,8 +200,15 @@ enum InventoryCommand {
/// Admit the speaker-state revision (Scene and Speaker features) as the
/// inventory's latest plus one.
SpeakerScene,
/// Admit a model's inventory draft (a JSON file, {add, retire} as the
/// loop's editor writes it) as the inventory's latest plus one.
Admit { answer: PathBuf },
}
/// The most changes `inventory admit` takes in one draft. A hand-admitted draft
/// is reviewed whole in its cut, so the cap is not the loop editor's.
const MAX_ADMIT_CHANGES: usize = 256;
#[derive(Subcommand)]
enum SceneCommand {
/// Append a scene revision for one corpus group: its one live speaker's
@ -785,6 +792,22 @@ fn main() -> Result<()> {
store.admit_revision(rev, entries).map_err(refused)?;
println!("admitted rev:{n} with {count} entries");
}
Command::Inventory(InventoryCommand::Admit { answer }) => {
let text = std::fs::read_to_string(&answer).context("the draft would not read")?;
let draft = EditDraft::parse(&text)?;
let mut store = InventoryStore::open(&cli.inventory)?;
let inventory = store.inventory()?;
let latest = inventory
.latest()
.map(|r| r.n)
.context("the inventory holds no revision")?;
let (rev, entries) = draft
.into_revision(&inventory, latest, MAX_ADMIT_CHANGES)
.context("the draft makes no change or more than the cap")?;
let (n, count) = (rev.n, entries.len());
store.admit_revision(rev, entries).map_err(refused)?;
println!("admitted rev:{n} with {count} entries");
}
Command::Scene(SceneCommand::Put {
group,
to,

View file

@ -40,7 +40,7 @@ use unicode_segmentation::UnicodeSegmentation;
use crate::context::{EditFeedback, EncoderOffer, Prompt, TrainItems};
use crate::corpus::{CorpusItem, CorpusItemId, ModelFamily, Source};
use crate::encode::{EditDraft, LoweringDraft, PacketDraft, encoder_id};
use crate::encode::{EditDraft, LoweringDraft, MAX_EDIT_CHANGES, PacketDraft, encoder_id};
use crate::form::{is_attestation, is_language_tag, is_slug};
use crate::model::{ModelPort, PortError};
use crate::packet::{Packet, Stance};
@ -2257,7 +2257,7 @@ pub fn cycle<M: ModelPort, E: Embedder>(
let Some(draft) = answer.as_deref().and_then(|a| EditDraft::parse(a).ok()) else {
return reject(run, Why::EditParse);
};
let Some((revision, entries)) = draft.into_revision(&inventory, base_rev) else {
let Some((revision, entries)) = draft.into_revision(&inventory, base_rev, MAX_EDIT_CHANGES) else {
return reject(run, Why::EditAdmit);
};
let candidate_rev = revision.n;