MCPcopy Create free account
hub / github.com/PaddlePaddle/Serving / set_file

Method set_file

tools/cpp_examples/demo-client/src/text_classification.cpp:70–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68}
69
70bool DataFeed::set_file(const char *filename) {
71 std::ifstream ifs(filename);
72 char *line = new char[MAX_LINE_SIZE];
73 int len = 0;
74 char *sequence_begin_ptr = NULL;
75 char *sequence_end_ptr = NULL;
76 char *id_begin_ptr = NULL;
77 char *id_end_ptr = NULL;
78 char *label_ptr = NULL;
79 int label = -1;
80 int id = -1;
81 while (!ifs.eof()) {
82 std::vector<int64_t> vec;
83 ifs.getline(line, MAX_LINE_SIZE);
84 len = strlen(line);
85 if (line[0] != '(' || line[len - 1] != ')') {
86 continue;
87 }
88 line[len - 1] = '\0';
89
90 sequence_begin_ptr = strchr(line, '(') + 1;
91 if (*sequence_begin_ptr != '[') {
92 continue;
93 }
94
95 sequence_end_ptr = strchr(sequence_begin_ptr, ']');
96 if (sequence_end_ptr == NULL) {
97 continue;
98 }
99 *sequence_end_ptr = '\0';
100
101 id_begin_ptr = sequence_begin_ptr;
102 while (id_begin_ptr != NULL) {
103 id_begin_ptr++;
104 id_end_ptr = strchr(id_begin_ptr, ',');
105 if (id_end_ptr != NULL) {
106 *id_end_ptr = '\0';
107 }
108 id = atoi(id_begin_ptr);
109 id_begin_ptr = id_end_ptr;
110 vec.push_back(id);
111 }
112
113 label_ptr = strchr(sequence_end_ptr + 1, ',');
114 if (label_ptr == NULL) {
115 continue;
116 }
117 *label_ptr = '\0';
118
119 label_ptr++;
120 label = atoi(label_ptr);
121
122 _test_input.push_back(vec);
123 _test_label.push_back(label);
124 }
125
126 ifs.close();
127

Callers 1

mainFunction · 0.80

Calls 3

push_backMethod · 0.80
closeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected