def beta_to_uni(text, strict=False):
    """
    Converts the given text from betacode to unicode.

    Args:
    text: The beta code text to convert. All of this text must be betacode.
    strict: Flag to allow for flexible diacritic order on input.

    Returns:
    The converted text.
    """
    # Check if the requested configuration for conversion already has a trie
    # stored otherwise convert it.
    param_key = (strict,)
    try:
       t = _BETA_CONVERSION_TRIES[param_key]
    except KeyError:
        t = _create_conversion_trie(*param_key)
        _BETA_CONVERSION_TRIES[param_key] = t

    transform = []
    idx = 0
    possible_word_boundary = False

    while idx < len(text):
        if possible_word_boundary and _penultimate_sigma_word_final(transform):
            transform[-2] = _FINAL_LC_SIGMA

        step = t.longest_prefix(text[idx:idx + _MAX_BETA_TOKEN_LEN])

        if step:
            possible_word_boundary = text[idx] in _BETA_PUNCTUATION

            key, value = step
            transform.append(value)
            idx += len(key)
        else:
            possible_word_boundary = True

            transform.append(text[idx])
            idx += 1

    # Check one last time in case there is some whitespace or punctuation at the
    # end and check if the last character is a sigma.
    if possible_word_boundary and _penultimate_sigma_word_final(transform):
        transform[-2] = _FINAL_LC_SIGMA
    elif len(transform) > 0 and transform[-1] == _MEDIAL_LC_SIGMA:
        transform[-1] = _FINAL_LC_SIGMA

    converted = ''.join(transform)
    return converted
Converts the given text from betacode to unicode.

    Args:
    text: The beta code text to convert. All of this text must be betacode.
    strict: Flag to allow for flexible diacritic order on input.

    Returns:
    The converted text.