| 101 | // ---------------------------------------------------------------------------------------- |
| 102 | |
| 103 | void make_training_examples ( |
| 104 | std::vector<std::vector<std::string> >& samples, |
| 105 | std::vector<std::vector<std::pair<unsigned long, unsigned long> > >& segments |
| 106 | ) |
| 107 | /*! |
| 108 | ensures |
| 109 | - This function fills samples with example sentences and segments with the |
| 110 | locations of person names that should be segmented out. |
| 111 | - #samples.size() == #segments.size() |
| 112 | !*/ |
| 113 | { |
| 114 | std::vector<std::pair<unsigned long, unsigned long> > names; |
| 115 | |
| 116 | |
| 117 | // Here we make our first training example. split() turns the string into an array of |
| 118 | // 10 words and then we store that into samples. |
| 119 | samples.push_back(split("The other day I saw a man named Jim Smith")); |
| 120 | // We want to detect person names. So we note that the name is located within the |
| 121 | // range [8, 10). Note that we use half open ranges to identify segments. So in this |
| 122 | // case, the segment identifies the string "Jim Smith". |
| 123 | names.push_back(make_pair(8, 10)); |
| 124 | segments.push_back(names); names.clear(); |
| 125 | |
| 126 | // Now we add a few more example sentences |
| 127 | |
| 128 | samples.push_back(split("Davis King is the main author of the dlib Library")); |
| 129 | names.push_back(make_pair(0, 2)); |
| 130 | segments.push_back(names); names.clear(); |
| 131 | |
| 132 | |
| 133 | samples.push_back(split("Bob Jones is a name and so is George Clinton")); |
| 134 | names.push_back(make_pair(0, 2)); |
| 135 | names.push_back(make_pair(8, 10)); |
| 136 | segments.push_back(names); names.clear(); |
| 137 | |
| 138 | |
| 139 | samples.push_back(split("My dog is named Bob Barker")); |
| 140 | names.push_back(make_pair(4, 6)); |
| 141 | segments.push_back(names); names.clear(); |
| 142 | |
| 143 | |
| 144 | samples.push_back(split("ABC is an acronym but John James Smith is a name")); |
| 145 | names.push_back(make_pair(5, 8)); |
| 146 | segments.push_back(names); names.clear(); |
| 147 | |
| 148 | |
| 149 | samples.push_back(split("No names in this sentence at all")); |
| 150 | segments.push_back(names); names.clear(); |
| 151 | } |
| 152 | |
| 153 | // ---------------------------------------------------------------------------------------- |
| 154 | |