/** * Copyright (c) 2017-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ #include #include #include #include #include std::string EOS = ""; bool readWord(std::istream& in, std::string& word) { char c; std::streambuf& sb = *in.rdbuf(); word.clear(); while ((c = sb.sbumpc()) != EOF) { if (c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '\v' || c == '\f' || c == '\0') { if (word.empty()) { if (c == '\n') { word += EOS; return true; } continue; } else { if (c == '\n') sb.sungetc(); return true; } } word.push_back(c); } in.get(); return !word.empty(); } int main(int argc, char** argv) { int k = 10; if (argc < 4) { std::cerr<<"eval []"< > KB; while (kbf.peek() != EOF) { std::string label, key, word; while (readWord(kbf, word)) { if (word == EOS) {break;} if (word.find("__label__") == 0) {label = word;} else {key += "|" + word;} } KB[key][label] = true; } kbf.close(); double precision = 0.0; int32_t nexamples = 0; while (predf.peek() != EOF || gtf.peek() != EOF) { if (predf.peek() == EOF || gtf.peek() == EOF) { std::cerr<<"pred / gt files have diff sizes"<