Beispiel #1
0
def get_builtin_entity_examples(builtin_entity_kind, language):
    """Provides some examples of the builtin entity in the specified language
    """
    global _ENTITIES_EXAMPLES

    if not isinstance(builtin_entity_kind, str):
        raise TypeError("Expected `builtin_entity_kind` to be of type 'str' "
                        "but found: %s" % type(builtin_entity_kind))
    if not isinstance(language, str):
        raise TypeError(
            "Expected `language` to be of type 'str' but found: %s" %
            type(language))

    if builtin_entity_kind not in _ENTITIES_EXAMPLES:
        _ENTITIES_EXAMPLES[builtin_entity_kind] = dict()

    if language not in _ENTITIES_EXAMPLES[builtin_entity_kind]:
        with string_array_pointer(pointer(CStringArray())) as ptr:
            exit_code = lib.snips_nlu_ontology_builtin_entity_examples(
                builtin_entity_kind.encode("utf8"), language.encode("utf8"),
                byref(ptr))
            check_ffi_error(
                exit_code, "Something went wrong when retrieving "
                "builtin entity examples")
            array = ptr.contents
            _ENTITIES_EXAMPLES[builtin_entity_kind][language] = list(
                array.data[i].decode("utf8") for i in range(array.size))
    return _ENTITIES_EXAMPLES[builtin_entity_kind][language]
Beispiel #2
0
def get_supported_grammar_entities(language):
    """Lists the grammar entities supported in the specified *language*

    Returns:
          list of str: the list of entity labels
    """
    global _SUPPORTED_GRAMMAR_ENTITIES

    if not isinstance(language, str):
        raise TypeError("Expected language to be of type 'str' but found: %s" %
                        type(language))

    if language not in _SUPPORTED_GRAMMAR_ENTITIES:
        with string_array_pointer(pointer(CStringArray())) as ptr:
            exit_code = lib.snips_nlu_ontology_supported_grammar_entities(
                language.encode("utf8"), byref(ptr))
            check_ffi_error(
                exit_code, "Something went wrong when retrieving "
                "supported grammar entities")
            array = ptr.contents
            _SUPPORTED_GRAMMAR_ENTITIES[language] = set(
                array.data[i].decode("utf8") for i in range(array.size))
    return _SUPPORTED_GRAMMAR_ENTITIES[language]
def get_supported_entities(language):
    """Lists the builtin entities supported in the specified *language*

    Returns:
          list of str: the list of entity labels
    """
    global _SUPPORTED_ENTITIES

    if not isinstance(language, str):
        raise TypeError("Expected language to be of type 'str' but found: %s" %
                        type(language))

    if language not in _SUPPORTED_ENTITIES:
        with string_array_pointer(pointer(CStringArray())) as ptr:
            exit_code = lib.snips_nlu_ontology_supported_builtin_entities(
                language.encode("utf8"), byref(ptr))
            if exit_code:
                raise ValueError("Something wrong happened while retrieving "
                                 "supported entities. See stderr.")
            array = ptr.contents
            _SUPPORTED_ENTITIES[language] = set(array.data[i].decode("utf8")
                                                for i in range(array.size))
    return _SUPPORTED_ENTITIES[language]