21 #include <boost/program_options.hpp> 29 namespace po = boost::program_options;
40 cout <<
"validate pattern " << pattern->name << endl;
45 double confidenceSum = 0;
46 double thresholdConfidence = 0.8;
57 set<pair<string, string> > mappedTypes;
62 mappedTypes.insert(make_pair(obj->type, obj->observedId));
71 vector<RecognitionResultPtr> results = recognizer->recognizePattern(os);
74 if (result->patternName == pattern->name) {
75 vector<RecognitionResultPtr> all;
76 all.push_back(result);
77 stack<RecognitionResultPtr> subPatterns;
80 subPatterns.push(subPattern);
83 while (subPatterns.size() > 0) {
88 subPatterns.push(subPattern);
93 for (
ObjectPtr& obj : pattern->recognizedSet->objects) {
94 set<pair<string, string> >::iterator match = mappedTypes.find(make_pair(obj->type, obj->observedId));
95 if (match != mappedTypes.end()) {
96 mappedTypes.erase(match);
103 confidenceSum += result->confidence;
107 cout << (found ?
"." :
",");
116 double meanConfidence = confidenceSum / (double) setCount;
117 cout << (meanConfidence >= thresholdConfidence ?
"SUCCESS" :
"FAILURE") <<
" mean confidence for pattern '" 118 << pattern->name <<
"' is " << meanConfidence << endl;
120 double identifyRate = (double) identifySum / (
double) objectCount;
121 cout <<
"Identification rate: " << identifyRate << endl;
125 int main(
int argc,
char** argv) {
126 double bin_size = 0.005;
128 po::options_description desc(
"Allowed options");
129 desc.add_options()(
"help,h",
"produce help message")(
"database-file,d",
130 po::value<string>()->default_value(
"record.sqlite"),
"database file to use")(
"generic-mode,g",
132 "test object type inference by removing object type and id from recognition input")(
"bin_size,s",
133 po::value<double>(&bin_size)->default_value(0.0001),
"recognizer bin_size")(
"pattern-name,p",
134 po::value<vector<string> >(),
"patters to validate instead of all")(
"onlyN,o",
135 po::value<int>(&
onlyN)->default_value(-1),
"only the n'th set")(
"maxRuns,m",
136 po::value<int>(&
maxRuns)->default_value(-1),
"test a maximum of m sets");
138 po::variables_map vm;
139 po::store(po::parse_command_line(argc, argv, desc), vm);
142 if (vm.count(
"help")) {
143 cout << desc <<
"\n";
149 if (vm.count(
"pattern-name")) {
150 vector<string> patternNames = vm[
"pattern-name"].as<vector<string> >();
151 for (
string& name : patternNames) {
154 cout <<
"Pattern " << name <<
" not found!";
161 for (
string& name : patternNames) {
164 cout <<
"Pattern " << name <<
" not found!";
void validatePattern(RecordedPatternPtr pattern, RecognizerPtr recognizer)
boost::shared_ptr< Recognizer > RecognizerPtr
boost::shared_ptr< RecordedPattern > RecordedPatternPtr
boost::shared_ptr< ObjectSet > ObjectSetPtr
boost::shared_ptr< RecognitionResult > RecognitionResultPtr
std::vector< std::string > getRecordedPatternNames() const
this namespace contains all generally usable classes.
boost::shared_ptr< Object > ObjectPtr
int main(int argc, char **argv)
const RecordedPatternPtr getRecordedPattern(const std::string &patternName) const