1 /** 2 * Copyright 2020-2021 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "minddata/dataset/text/ir/validators.h" 18 19 namespace mindspore { 20 namespace dataset { 21 /* ####################################### Validator Functions ############################################ */ 22 23 // Helper function to validate tokenizer directory parameter ValidateTokenizerDirParam(const std::string & tokenizer_name,const std::string & tokenizer_file)24Status ValidateTokenizerDirParam(const std::string &tokenizer_name, const std::string &tokenizer_file) { 25 if (tokenizer_file.empty()) { 26 std::string err_msg = tokenizer_name + ": tokenizer_file is not specified."; 27 LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg); 28 } 29 30 Path file(tokenizer_file); 31 if (!file.Exists()) { 32 std::string err_msg = tokenizer_name + ": tokenizer_file: [" + tokenizer_file + "] is an invalid directory path."; 33 LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg); 34 } 35 36 if (access(tokenizer_file.c_str(), R_OK) == -1) { 37 std::string err_msg = tokenizer_name + ": No access to specified tokenizer path: " + tokenizer_file; 38 LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg); 39 } 40 41 return Status::OK(); 42 } 43 44 // Helper functions to help validate data type passed by user IsTypeNumeric(const std::string & data_type)45bool IsTypeNumeric(const std::string &data_type) { 46 if (data_type == "int8" || data_type == "uint8" || data_type == "int16" || data_type == "uint16" || 47 data_type == "int32" || data_type == "uint32" || data_type == "int64" || data_type == "uint64" || 48 data_type == "float16" || data_type == "float32" || data_type == "float64") { 49 return true; 50 } 51 return false; 52 } 53 IsTypeBoolean(const std::string & data_type)54bool IsTypeBoolean(const std::string &data_type) { return data_type == "bool"; } 55 IsTypeString(const std::string & data_type)56bool IsTypeString(const std::string &data_type) { return data_type == "string"; } 57 } // namespace dataset 58 } // namespace mindspore 59