/**
 * Check if a given key falls within the legal terms.
 *
 * @param legalTerms List of legal terms.
 * @param key Key to be checked.
 * @return True if the key is legal, False otherwise.
 */
fun isLegalKey(legalTerms: List<String>, key: String): Boolean {

    for (term in legalTerms) {
        if (term == key || term == "*" || (key.startsWith(term) && key.getOrNull(term.length)?.let { it.isWhitespace() || it in setOf('.', ',', '?', '!', ':', ';', '\n') } == true)) {
            return true
        }
    }
    return false
}

val legalTerms = listOf("court", "judge", "attorney", "lawyer", "legal", "lawsuit")
/**
 * Check if a given key falls within the legal terms.
 *
 * @param legalTerms List of legal terms.
 * @param key Key to be checked.
 * @return True if the key is legal, False otherwise.
 */
fun isLegalKey(legalTerms: List<String>, key: String): Boolean {
/**
 * Check if a given key falls within the legal terms.
 *
 * @param legalTerms List of legal terms.
 * @param key Key to be checked.
 * @return True if the key is legal, False otherwise.
 */
fun isLegalKey(legalTerms: List<String>, key: String): Boolean {

    for (term in legalTerms) {
        if (term == key || term == "*" || (key.startsWith(term) && key.getOrNull(term.length)?.let { it.isWhitespace() || it in setOf('.', ',', '?', '!', ':', ';', '\n') } == true)) {
            return true
        }
    }
    return false
}

val legalTerms = listOf("court", "judge", "attorney", "lawyer", "legal", "lawsuit")