Exemple #1
0
from inspect import signature
from warnings import warn
from os.path import join

from lingua_franca.bracket_expansion import SentenceTreeParser
from lingua_franca.internal import localized_function, \
    populate_localized_function_dict, get_active_langs, \
    get_full_lang_code, get_default_lang, get_default_loc, \
    is_supported_full_lang, _raise_unsupported_language, \
    UnsupportedLanguageError, NoneLangWarning, InvalidLangWarning, \
    FunctionNotLocalizedError

_REGISTERED_FUNCTIONS = ("nice_number", "nice_time", "pronounce_number",
                         "nice_response", "nice_duration")

populate_localized_function_dict("format", langs=get_active_langs())


def _translate_word(name, lang=''):
    """ Helper to get word translations

    Args:
        name (str): Word name. Returned as the default value if not translated
        lang (str): Language code, e.g. "en-us"

    Returns:
        str: translated version of resource name
    """
    from lingua_franca.internal import resolve_resource_file
    if not lang:
        if lang is None:
Exemple #2
0
# See the License for the specific language governing permissions and
# limitations under the License.
#

from difflib import SequenceMatcher
from warnings import warn
from lingua_franca.time import now_local
from lingua_franca.internal import populate_localized_function_dict, \
    get_active_langs, get_full_lang_code, get_primary_lang_code, \
    get_default_lang, localized_function, _raise_unsupported_language

_REGISTERED_FUNCTIONS = ("extract_numbers", "extract_number",
                         "extract_duration", "extract_datetime", "normalize",
                         "get_gender", "is_fractional", "is_ordinal")

populate_localized_function_dict("parse", langs=get_active_langs())


def fuzzy_match(x, against):
    """Perform a 'fuzzy' comparison between two strings.
    Returns:
        float: match percentage -- 1.0 for perfect match,
               down to 0.0 for no match at all.
    """
    return SequenceMatcher(None, x, against).ratio()


def match_one(query, choices):
    """
        Find best match from a list or dictionary given an input