// multilingual_gate.el - deterministic language detect + localized-phrase test.

fn mg_det(text: String, want: String) -> String {
    let got: String = ml_detect(text)
    let ok: String = "MISMATCH"
    if str_eq(got, want) { let ok = "ok" }
    return "  detect(" + got + ") want=" + want + " (" + ok + ")  :: " + text + "\n"
}

fn mg_ok(text: String, want: String) -> Int {
    if str_eq(ml_detect(text), want) { return 1 }
    return 0
}

fn run_ml_gate() -> String {
    let t1: String = "Does Neuron use SQLite for storage?"
    let t2: String = "Neuron, me explica cómo la saliencia forma las geometrías."
    let t3: String = "O professor não leu o livro na memória."
    let t4: String = "Che cosa memorizza Neuron nella memoria?"

    let rep: String = "==== ELP multilingual detect + localized phrases ====\n"
    let rep = rep + mg_det(t1, "en")
    let rep = rep + mg_det(t2, "es")
    let rep = rep + mg_det(t3, "pt")
    let rep = rep + mg_det(t4, "it")

    let rep = rep + "  localized decline (pt): " + ml_tr("no_memory", "pt") + "\n"
    let rep = rep + "  localized decline (es): " + ml_tr("no_memory", "es") + "\n"
    let rep = rep + "  term(saliência->en):    " + ml_term("saliência", "pt") + "\n"
    let rep = rep + "  pred(store->pt):        " + ml_translate_pred("store", "pt") + "\n"

    let ok: Int = 0
    if mg_ok(t1, "en") == 1 { let ok = ok + 1 }
    if mg_ok(t2, "es") == 1 { let ok = ok + 1 }
    if mg_ok(t3, "pt") == 1 { let ok = ok + 1 }
    if mg_ok(t4, "it") == 1 { let ok = ok + 1 }
    let rep = rep + "-----------------------------------------------------------------\n"
    let rep = rep + "language detected correctly: " + int_to_str(ok) + "/4\n"
    if ok == 4 { let rep = rep + "ML GATE: PASS\n" } else { let rep = rep + "ML GATE: FAIL\n" }
    return rep
}

println(run_ml_gate())
