Skip to main content

sqlite_graphrag/i18n/validation/
messages_graph.rs

1//! Messages about GRAPH edges and their endpoints (GAP-SG-146).
2//!
3//! Relation vocabulary, edge weights and the self-reference guard.
4
5use crate::i18n::{current, Language};
6
7/// Localized message for `invalid_link_weight`.
8pub fn invalid_link_weight(weight: f64) -> String {
9    match current() {
10        Language::English => {
11            format!("--weight: must be between 0.0 and 1.0 (actual: {weight})")
12        }
13        Language::Portuguese => {
14            format!("--weight: deve estar entre 0.0 e 1.0 (atual: {weight})")
15        }
16    }
17}
18
19/// Invalid relationship id.
20pub fn invalid_relationship_id(item_key: &str) -> String {
21    match current() {
22        Language::English => format!("invalid relationship id: {item_key}"),
23        Language::Portuguese => format!("id de relacionamento inválido: {item_key}"),
24    }
25}
26
27/// Relationship strength outside [0.0, 1.0].
28pub fn invalid_relationship_strength(strength: f64, source: &str, target: &str) -> String {
29    match current() {
30        Language::English => format!(
31            "invalid strength {strength} for relationship '{source}' -> '{target}'; \
32             expected value in [0.0, 1.0]"
33        ),
34        Language::Portuguese => format!(
35            "força inválida {strength} para relacionamento '{source}' -> '{target}'; \
36             valor esperado em [0.0, 1.0]"
37        ),
38    }
39}
40
41/// Non-canonical relation under --strict-relations.
42pub fn non_canonical_relation(relation: &str, allowed: &str) -> String {
43    match current() {
44        Language::English => format!(
45            "non-canonical relation '{relation}': use --strict-relations=false or choose from: {allowed}"
46        ),
47        Language::Portuguese => format!(
48            "relação não canônica '{relation}': use --strict-relations=false ou escolha entre: {allowed}"
49        ),
50    }
51}
52
53/// Batch reclassification whose `--from-type` matches no entity at all.
54///
55/// v1.2.8: with a closed enum, a typo in `--from-type` was refused by clap. The
56/// vocabulary is open now, so the same typo would parse, match nothing, and
57/// report success over zero rows. Counting the targets first turns that silent
58/// no-op back into a refusal.
59pub fn reclassify_batch_no_targets(from_type: &str, namespace: &str) -> String {
60    match current() {
61        Language::English => format!(
62            "--from-type '{from_type}' matches no entity in namespace '{namespace}'; \
63             list the stored types with `graph entities` before retrying"
64        ),
65        Language::Portuguese => format!(
66            "--from-type '{from_type}' não corresponde a nenhuma entidade no namespace '{namespace}'; \
67             liste os tipos gravados com `graph entities` antes de repetir"
68        ),
69    }
70}
71
72/// Relation format error scoped to a source→target edge.
73pub fn relation_format_for_relationship(
74    err: &impl std::fmt::Display,
75    source: &str,
76    target: &str,
77) -> String {
78    match current() {
79        Language::English => format!("{err} for relationship '{source}' -> '{target}'"),
80        Language::Portuguese => {
81            format!("{err} para relacionamento '{source}' -> '{target}'")
82        }
83    }
84}
85
86/// Localized message for `self_referential_link`.
87pub fn self_referential_link() -> String {
88    match current() {
89        Language::English => "--from and --to must be different entities — self-referential relationships are not supported".to_string(),
90        Language::Portuguese => "--from e --to devem ser entidades diferentes — relacionamentos auto-referenciais não são suportados".to_string(),
91    }
92}