1/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15#include "tensorflow/core/data/name_utils.h"
16
17#include "absl/strings/str_join.h"
18
19namespace tensorflow {
20namespace data {
21namespace name_utils {
22
23ABSL_CONST_INIT const char kDelimiter[] = "::";
24ABSL_CONST_INIT const char kDefaultDatasetDebugStringPrefix[] = "";
25
26constexpr char kDataset[] = "Dataset";
27constexpr char kOp[] = "Op";
28constexpr char kVersion[] = "V";
29
30string OpName(const string& dataset_type) {
31 return OpName(dataset_type, OpNameParams());
32}
33
34string OpName(const string& dataset_type, const OpNameParams& params) {
35 if (params.op_version == 1) {
36 return strings::StrCat(dataset_type, kDataset);
37 }
38 return strings::StrCat(dataset_type, kDataset, kVersion, params.op_version);
39}
40
41string ArgsToString(const std::vector<string>& args) {
42 if (args.empty()) {
43 return "";
44 }
45 return strings::StrCat("(", absl::StrJoin(args, ", "), ")");
46}
47
48string DatasetDebugString(const string& dataset_type) {
49 return DatasetDebugString(dataset_type, DatasetDebugStringParams());
50}
51
52string DatasetDebugString(const string& dataset_type,
53 const DatasetDebugStringParams& params) {
54 OpNameParams op_name_params;
55 op_name_params.op_version = params.op_version;
56 string op_name = OpName(dataset_type, op_name_params);
57 return strings::StrCat(op_name, kOp, ArgsToString(params.args), kDelimiter,
58 params.dataset_prefix, kDataset);
59}
60
61string IteratorPrefix(const string& dataset_type, const string& prefix) {
62 return IteratorPrefix(dataset_type, prefix, IteratorPrefixParams());
63}
64
65string IteratorPrefix(const string& dataset_type, const string& prefix,
66 const IteratorPrefixParams& params) {
67 if (params.op_version == 1) {
68 return strings::StrCat(prefix, kDelimiter, params.dataset_prefix,
69 dataset_type);
70 }
71 return strings::StrCat(prefix, kDelimiter, params.dataset_prefix,
72 dataset_type, kVersion, params.op_version);
73}
74
75} // namespace name_utils
76} // namespace data
77} // namespace tensorflow
78