-
Notifications
You must be signed in to change notification settings - Fork 0
feat(method): refuse house-voice style as unique content #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f9ff41a
71d83f4
3679355
f3f1504
020b446
4c0612f
d9df3a6
531c1b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| [package] | ||
| name = "style_source" | ||
| description = "House-voice style residue is not unique content and not stopword deletion." | ||
| version.workspace = true | ||
| edition.workspace = true | ||
| rust-version.workspace = true | ||
| license.workspace = true | ||
| authors.workspace = true | ||
| repository.workspace = true | ||
| homepage.workspace = true | ||
| readme.workspace = true | ||
| keywords.workspace = true | ||
| categories.workspace = true | ||
| publish = false | ||
|
|
||
| [lints] | ||
| workspace = true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| //! Fail-closed style-source errors. | ||
|
|
||
| use std::fmt; | ||
|
|
||
| /// A fail-closed style-source error. | ||
| #[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
| #[non_exhaustive] | ||
| pub enum StyleSourceError { | ||
| /// Style residue was treated as unique latent content. | ||
| StyleIsNotUniqueContent, | ||
| /// Style residue was treated as stopword deletion. | ||
| StyleIsNotStopwordDeletion, | ||
| /// A recovery slice was empty or length-mismatched. | ||
| InvalidStylePayload, | ||
| } | ||
|
|
||
| impl fmt::Display for StyleSourceError { | ||
| fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| let message = match self { | ||
| Self::StyleIsNotUniqueContent => { | ||
| "house-voice style residue is not unique latent content" | ||
| } | ||
| Self::StyleIsNotStopwordDeletion => { | ||
| "house-voice style residue is not stopword deletion" | ||
| } | ||
| Self::InvalidStylePayload => "invalid style-source payload", | ||
| }; | ||
| formatter.write_str(message) | ||
| } | ||
| } | ||
|
|
||
| impl std::error::Error for StyleSourceError {} | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::StyleSourceError; | ||
|
|
||
| #[test] | ||
| fn error_messages_are_stable() { | ||
| for (error, message) in [ | ||
| ( | ||
| StyleSourceError::StyleIsNotUniqueContent, | ||
| "house-voice style residue is not unique latent content", | ||
| ), | ||
| ( | ||
| StyleSourceError::StyleIsNotStopwordDeletion, | ||
| "house-voice style residue is not stopword deletion", | ||
| ), | ||
| ( | ||
| StyleSourceError::InvalidStylePayload, | ||
| "invalid style-source payload", | ||
| ), | ||
| ] { | ||
| assert_eq!(error.to_string(), message); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| //! Style residue versus unique latent content. | ||
|
|
||
| use crate::StyleSourceError; | ||
|
|
||
| /// Closed vocabulary of style-related token treatments. | ||
| #[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
| pub enum StyleKind { | ||
| /// House-voice or style residue, not unique document meaning. | ||
| StyleResidue, | ||
| /// Token treatment reserved for unique latent content. | ||
| UniqueContent, | ||
| } | ||
|
|
||
| impl StyleKind { | ||
| /// Return the stable wire kind name. | ||
| #[must_use] | ||
| pub const fn wire_name(self) -> &'static str { | ||
| match self { | ||
| Self::StyleResidue => "style", | ||
| Self::UniqueContent => "unique_content", | ||
| } | ||
| } | ||
|
|
||
| /// Parse a stable wire kind name. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns [`StyleSourceError::InvalidStylePayload`] for unrecognized names. | ||
| pub fn from_wire_name(name: &str) -> Result<Self, StyleSourceError> { | ||
| match name { | ||
| "style" => Ok(Self::StyleResidue), | ||
| "unique_content" => Ok(Self::UniqueContent), | ||
| _ => Err(StyleSourceError::InvalidStylePayload), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Refuse to treat style residue as unique latent content. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns [`StyleSourceError::StyleIsNotUniqueContent`] when `kind` is | ||
| /// [`StyleKind::StyleResidue`]. | ||
| pub fn refuse_style_as_unique_content(kind: StyleKind) -> Result<(), StyleSourceError> { | ||
| match kind { | ||
| StyleKind::StyleResidue => Err(StyleSourceError::StyleIsNotUniqueContent), | ||
| StyleKind::UniqueContent => Ok(()), | ||
| } | ||
| } | ||
|
|
||
| /// Refuse to treat style residue as stopword deletion. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns [`StyleSourceError::StyleIsNotStopwordDeletion`] when `kind` is | ||
| /// [`StyleKind::StyleResidue`]. | ||
| pub fn refuse_style_as_stopword_deletion(kind: StyleKind) -> Result<(), StyleSourceError> { | ||
| match kind { | ||
| StyleKind::StyleResidue => Err(StyleSourceError::StyleIsNotStopwordDeletion), | ||
| StyleKind::UniqueContent => Ok(()), | ||
| } | ||
| } | ||
|
|
||
| /// Fraction of recovered style kinds that match known truth. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns [`StyleSourceError::InvalidStylePayload`] when either slice is | ||
| /// empty or the lengths differ. | ||
| pub fn identity_recovery_rate( | ||
| truth: &[StyleKind], | ||
| decided: &[StyleKind], | ||
| ) -> Result<f64, StyleSourceError> { | ||
| if truth.is_empty() || truth.len() != decided.len() { | ||
| return Err(StyleSourceError::InvalidStylePayload); | ||
| } | ||
| let mut matches = 0_u32; | ||
| for (truth_kind, decided_kind) in truth.iter().zip(decided) { | ||
| if truth_kind == decided_kind { | ||
| matches += 1; | ||
| } | ||
| } | ||
| Ok(f64::from(matches) / truth.len() as f64) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::{ | ||
| StyleKind, identity_recovery_rate, refuse_style_as_stopword_deletion, | ||
| refuse_style_as_unique_content, | ||
| }; | ||
| use crate::StyleSourceError; | ||
|
|
||
| #[test] | ||
| fn local_branches_cover_kinds_payloads_and_wire_names() { | ||
| assert_eq!( | ||
| refuse_style_as_unique_content(StyleKind::StyleResidue), | ||
| Err(StyleSourceError::StyleIsNotUniqueContent) | ||
| ); | ||
| assert_eq!( | ||
| refuse_style_as_stopword_deletion(StyleKind::StyleResidue), | ||
| Err(StyleSourceError::StyleIsNotStopwordDeletion) | ||
| ); | ||
| refuse_style_as_unique_content(StyleKind::UniqueContent).expect("unique"); | ||
| refuse_style_as_stopword_deletion(StyleKind::UniqueContent).expect("unique"); | ||
| for kind in [StyleKind::StyleResidue, StyleKind::UniqueContent] { | ||
| assert_eq!( | ||
| StyleKind::from_wire_name(kind.wire_name()).expect("round-trip"), | ||
| kind | ||
| ); | ||
| } | ||
| assert_eq!( | ||
| StyleKind::from_wire_name("stopword"), | ||
| Err(StyleSourceError::InvalidStylePayload) | ||
| ); | ||
| let matched = | ||
| identity_recovery_rate(&[StyleKind::StyleResidue], &[StyleKind::StyleResidue]) | ||
| .expect("rate"); | ||
| assert!((matched - 1.0).abs() < f64::EPSILON); | ||
| assert_eq!( | ||
| identity_recovery_rate(&[], &[]), | ||
| Err(StyleSourceError::InvalidStylePayload) | ||
| ); | ||
| assert_eq!( | ||
| identity_recovery_rate(&[StyleKind::StyleResidue], &[]), | ||
| Err(StyleSourceError::InvalidStylePayload) | ||
| ); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #![forbid(unsafe_code)] | ||
| #![deny(missing_docs)] | ||
| #![allow(clippy::cast_precision_loss)] | ||
| //! House-voice style residue is not unique latent content. | ||
| //! | ||
| //! Style and house-voice stay explicit method/background structure. They | ||
| //! are not unique document meaning and are not erased by a stopword list | ||
| //! (ADR 0004/0012). | ||
|
|
||
| mod error; | ||
| mod kind; | ||
|
|
||
| /// Fail-closed style-source errors. | ||
| pub use error::StyleSourceError; | ||
| /// Closed vocabulary of style-related token treatments. | ||
| pub use kind::StyleKind; | ||
| /// Fraction of recovered style kinds that match known truth. | ||
| pub use kind::identity_recovery_rate; | ||
| /// Refuse to treat style residue as stopword deletion. | ||
| pub use kind::refuse_style_as_stopword_deletion; | ||
| /// Refuse to treat style residue as unique latent content. | ||
| pub use kind::refuse_style_as_unique_content; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| //! Integration contract for the `style_source` package identity. | ||
|
|
||
| #[test] | ||
| fn package_identity_is_stable() { | ||
| let observed = std::hint::black_box(env!("CARGO_PKG_NAME")); | ||
| assert_eq!(observed, "style_source"); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| //! House-voice style residue is not unique content and not stopword deletion. | ||
|
|
||
| use style_source::{ | ||
| StyleKind, StyleSourceError, identity_recovery_rate, refuse_style_as_stopword_deletion, | ||
| refuse_style_as_unique_content, | ||
| }; | ||
|
|
||
| #[test] | ||
| fn style_residue_cannot_become_unique_content_or_stopword_deletion() { | ||
| assert_eq!( | ||
| refuse_style_as_unique_content(StyleKind::StyleResidue), | ||
| Err(StyleSourceError::StyleIsNotUniqueContent) | ||
| ); | ||
| assert_eq!( | ||
| refuse_style_as_stopword_deletion(StyleKind::StyleResidue), | ||
| Err(StyleSourceError::StyleIsNotStopwordDeletion) | ||
| ); | ||
| refuse_style_as_unique_content(StyleKind::UniqueContent).expect("unique"); | ||
| refuse_style_as_stopword_deletion(StyleKind::UniqueContent).expect("unique"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn recovered_kinds_match_known_truth_better_than_a_unique_content_collapse() { | ||
| let truth = [ | ||
| StyleKind::StyleResidue, | ||
| StyleKind::UniqueContent, | ||
| StyleKind::StyleResidue, | ||
| ]; | ||
| let recovered = truth; | ||
| let collapsed = [ | ||
| StyleKind::UniqueContent, | ||
| StyleKind::UniqueContent, | ||
| StyleKind::UniqueContent, | ||
| ]; | ||
| let recovered_rate = identity_recovery_rate(&truth, &recovered).expect("recovered"); | ||
| let collapsed_rate = identity_recovery_rate(&truth, &collapsed).expect("collapsed"); | ||
| let expected = { | ||
| let mut matches = 0_u32; | ||
| for (truth_kind, decided_kind) in truth.iter().zip(recovered.iter()) { | ||
| if truth_kind == decided_kind { | ||
| matches += 1; | ||
| } | ||
| } | ||
| f64::from(matches) / f64::from(u32::try_from(truth.len()).expect("len")) | ||
| }; | ||
| assert!((recovered_rate - expected).abs() < f64::EPSILON); | ||
| assert!(recovered_rate > collapsed_rate); | ||
| } | ||
|
|
||
| #[test] | ||
| fn empty_or_mismatched_kind_payloads_fail_closed() { | ||
| assert_eq!( | ||
| identity_recovery_rate(&[], &[]), | ||
| Err(StyleSourceError::InvalidStylePayload) | ||
| ); | ||
| assert_eq!( | ||
| identity_recovery_rate(&[StyleKind::StyleResidue], &[]), | ||
| Err(StyleSourceError::InvalidStylePayload) | ||
| ); | ||
| assert_eq!( | ||
| identity_recovery_rate( | ||
| &[StyleKind::StyleResidue, StyleKind::UniqueContent], | ||
| &[StyleKind::StyleResidue] | ||
| ), | ||
| Err(StyleSourceError::InvalidStylePayload) | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,8 +24,8 @@ The full APA 7th standards/literature register remains `docs/research/standards- | |
| | multilingual shared latent semantic space | PRD; ADR 0004 | future semantic/concept/topic crates | accepted-target | | ||
| | TRSL-TM temporal/relational topic posterior and backend compatibility | ADR 0012; ADR 0004 | future `topic_measurement` | accepted-target | | ||
| | global P0 topic identity with activity/dormancy/reactivation | ADR 0012 | future topic lineage/activity state | accepted-target | | ||
| | no default stopword deletion / no TF-IDF-BM25 inferential weighting | ADR 0004/0012; PRD/TRD | `stopword_deletion` default-list refusal on the active PR; TF-IDF/BM25 inferential-weight refusal remains accepted-target | partial | | ||
| | report template/section/copied/style/modality method effects | ADR 0004/0012; PRD/TRD | simulation truth factors implemented; estimator-side method model remains future | partial | | ||
| | no default stopword deletion / no TF-IDF-BM25 inferential weighting | ADR 0004/0012; PRD/TRD | future semantic/method-source model | accepted-target | | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Traceability matrix marks a built capability as future work The Prompt for agentsWas this helpful? React with 👍 or 👎 to provide feedback. |
||
| | report template/section/copied/style/modality method effects | ADR 0004/0012; PRD/TRD | simulation truth factors implemented; `style_source` style-versus-unique-content identity on the active PR; estimator-side method model remains future | partial | | ||
| | candidate K statistical/Pareto gates + blinded LLM review | ADR 0012; research | future `model_selection` | accepted-target | | ||
| | compositional topic correlation / stable clustering | ADR 0005/0012; research | future `network_analysis` | accepted-target | | ||
| | posterior ESEM / longitudinal invariance / DSEM | ADR 0005 | `psychometric_fit` ESEM loading and DSEM lag gates on the active PR; `psychometric_core` input gates remain #49; invariance/multilevel remain accepted-target | active-PR | | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| # ADR 0004 — Shared multilingual latent semantic space | ||
|
|
||
| **Decision status:** Accepted | ||
| **Implementation maturity:** accepted-target — style-versus-unique-content identity in `style_source` on the active PR; shared-space estimators remain accepted-target | ||
| **Implementation maturity:** partial — default stopword-deletion refusal is `stopword_deletion` on the active PR; shared-space estimators, language profiles, and TF-IDF/BM25 inferential-weight refusal remain accepted-target | ||
|
Comment on lines
+4
to
5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 Info: Stacked conflicting maturity headers in ADR 0004 ADR 0004 now carries two Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| **Date:** 2026-08-05 | ||
| **Supersedes:** None. ADR 0012 governs the complete topic-estimator/backend/global-topic contract built on this multilingual measurement decision. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Info: Recovery rate fail-closed logic is correct for empty/mismatched slices
identity_recovery_ratein kind.rs guards withtruth.is_empty() || truth.len() != decided.len(). This covers all invalid-payload cases: empty truth, empty decided (length mismatch), and unequal lengths. Thezipthen only iterates matching pairs, and the divisor usestruth.len(), so the rate is a valid fraction in [0,1]. No off-by-one or division-by-zero risk exists.Was this helpful? React with 👍 or 👎 to provide feedback.