Ejemplo n.º 1
0
 def create_from_save_state_dict(
     cls,
     save_state: dict,
     new_type_context: TypeContext
 ) -> 'TypeContextWrapperVocab':
     instance = cls.__new__(cls)
     instance.itos = np.array([
         new_type_context.get_type_by_name(name) if is_type
         else new_type_context.get_object_by_name(name)
         for is_type, name in save_state['itos']
     ])
     instance._finish_init()
     return instance
Ejemplo n.º 2
0
def _get_root_parser(
    type_context: typecontext.TypeContext, type_name: str,
    parser_name: Optional[str]
) -> ainix_common.parsing.parse_primitives.TypeParser:
    """The public interface accepts a type name to parse as the root AST node
    for the string. This method converts that type name into an actuall parser
    instance."""
    if parser_name:
        return type_context.get_type_parser_by_name(parser_name)
    else:
        type_instance = type_context.get_type_by_name(type_name)
        if type_instance.default_type_parser is None:
            raise ValueError(
                f"No default type parser available for {type_instance}")
        return type_instance.default_type_parser