Skip to main content

qualia_core_db/query/
integrity_omit.rs

1//! Shared omit-predicate filters for ingest and import-aligned verify-graph.
2//!
3//! Applied identically on both sides so intentional omissions are proven, not accidental.
4
5use crate::q_hash;
6
7/// Well-known comment / definition / gloss IRIs (RDFS, SKOS, common WordNet).
8pub const COMMENT_GLOSS_PREDICATE_IRIS: &[&str] = &[
9    "http://www.w3.org/2000/01/rdf-schema#comment",
10    "http://www.w3.org/2000/01/rdf-schema#label",
11    "http://www.w3.org/2004/02/skos/core#definition",
12    "http://www.w3.org/2004/02/skos/core#scopeNote",
13    "http://www.w3.org/2004/02/skos/core#example",
14    "http://www.w3.org/2004/02/skos/core#prefLabel",
15    "http://www.w3.org/2004/02/skos/core#altLabel",
16    "https://globalwordnet.org/ontology#definition",
17    "http://globalwordnet.org/ontology#definition",
18    "https://en-word.net/ontology#definition",
19    "http://www.w3.org/2006/03/wn/wn20/schema/gloss",
20];
21
22/// Resolve CLI / script omit lists into FNV-1a predicate hashes (ingest encoding).
23pub fn resolve_omit_predicate_hashes(
24    iris: &[String],
25    preset: Option<&str>,
26) -> Result<Vec<u64>, String> {
27    let mut out = Vec::new();
28    if let Some(name) = preset {
29        let name = name.trim().to_ascii_lowercase();
30        match name.as_str() {
31            "comment-gloss" | "comment_gloss" | "gloss" => {
32                for iri in COMMENT_GLOSS_PREDICATE_IRIS {
33                    out.push(q_hash(iri));
34                }
35            }
36            "" => {}
37            other => {
38                return Err(format!(
39                    "unknown omit preset '{other}' (known: comment-gloss)"
40                ));
41            }
42        }
43    }
44    for iri in iris {
45        let iri = iri.trim();
46        if iri.is_empty() {
47            continue;
48        }
49        out.push(q_hash(iri));
50    }
51    out.sort_unstable();
52    out.dedup();
53    Ok(out)
54}
55
56/// Lexicon string length limit (u16) — terms longer than this fail closed in Complete ingest.
57pub const MAX_LEX_TERM_BYTES: usize = 65535;
58
59#[cfg(test)]
60mod tests {
61    use super::*;
62
63    #[test]
64    fn comment_gloss_preset_is_non_empty_and_stable() {
65        let a = resolve_omit_predicate_hashes(&[], Some("comment-gloss")).unwrap();
66        let b = resolve_omit_predicate_hashes(&[], Some("gloss")).unwrap();
67        assert!(!a.is_empty());
68        assert_eq!(a, b);
69        assert!(a.contains(&q_hash(COMMENT_GLOSS_PREDICATE_IRIS[0])));
70    }
71
72    #[test]
73    fn unknown_preset_fails() {
74        assert!(resolve_omit_predicate_hashes(&[], Some("nope")).is_err());
75    }
76}