Fleet  0.0.9
Inference in the LOT
Data.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <tuple>
4 #include <vector>
5 #include <iostream>
6 
12 std::tuple<std::vector<MyObject>*,
13  std::vector<bool>*,
14  std::vector<size_t>*,
15  std::vector<size_t>*,
16  std::string> get_next_human_data(std::ifstream& fs) {
17 
18  auto objs = new std::vector<MyObject>();
19  auto corrects = new std::vector<bool>();
20  auto yeses = new std::vector<size_t>();
21  auto nos = new std::vector<size_t>();
22  std::string conceptlist = "";
23 
24  S line;
25  int prev_setNumber = -1;
26  while(true) {
27 
28  auto pos = fs.tellg(); // remember where we were since when we get the next set, we seek back
29 
30  // get the line
31  auto& b = std::getline(fs, line);
32 
33  if(not b) { // if end of file, return
34  return std::make_tuple(objs,corrects,yeses,nos,conceptlist);
35  }
36  else {
37  // else break up the line an dprocess
38  auto parts = split(line, ' ');
39  auto new_conceptlist = S(parts[0]) + S(parts[1]);
40  int setNumber = std::stoi(parts[2]);
41  bool correctAnswer = (parts[4] == "True");
42  MyObject o{parts[5], parts[6], parts[7]};
43  size_t cntyes = std::stoi(parts[8]);
44  size_t cntno = std::stoi(parts[9]);
45 
46  // if we are on a new set, then we seek back and return
47  if(prev_setNumber != -1 and setNumber != prev_setNumber) {
48  fs.clear(); // must clear the EOF bit
49  fs.seekg(pos, std::ios_base::beg); // so next time this gets called, it starts at the right set
50  return std::make_tuple(objs,corrects,yeses,nos,conceptlist);
51  }
52  else {
53  // else we are still building this set
54  conceptlist = new_conceptlist;
55  objs->push_back(o);
56  corrects->push_back(correctAnswer);
57  yeses->push_back(cntyes);
58  nos->push_back(cntno);
59  }
60 
61 
62  prev_setNumber = setNumber;
63  }
64 
65  }
66 
67 }
std::string S
Definition: Main.cpp:28
std::deque< std::string > split(const std::string &s, const char delimiter)
Split is returns a deque of s split up at the character delimiter. It handles these special cases: sp...
Definition: str.h:50
std::tuple< std::vector< MyObject > *, std::vector< bool > *, std::vector< size_t > *, std::vector< size_t > *, std::string > get_next_human_data(std::ifstream &fs)
This functions reads our data file format and returns a vector with the human data by each set item...
Definition: Data.h:16
Definition: Object.h:20