Skip to content

Commit

Permalink
Added ErrorTokenError, now properly raised on buildpattern() with all…
Browse files Browse the repository at this point in the history
…owunknown=false, closes issue #25
  • Loading branch information
proycon committed Aug 19, 2016
1 parent afd4b54 commit 7caaa31
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,11 @@ class KeyError: public std::exception {
return "Colibri KeyError";
}
};

class UnknownTokenError: public std::exception {
virtual const char* what() const throw()
{
return "The input contained an unknown token";
}
};
#endif
2 changes: 1 addition & 1 deletion src/classencoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ int ClassEncoder::encodestring(const string & line, unsigned char * outputbuffer
added[cls] = word;
} else if (!allowunknown) {
//cerr << "ERROR: Unknown word '" << word << "', does not occur in model. You may want to pass either option -U or option -e to colibri-classencode to deal with unknown words." << endl;
return 0;
throw UnknownTokenError();
} else {
//cerr << "WARNING: Unknown word '" << word << "', does not occur in model. Replacing with placeholder" << endl;
cls = unknownclass;
Expand Down
4 changes: 2 additions & 2 deletions src/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,13 +496,13 @@ int main( int argc, char *argv[] ) {
bool caught = false;
try {
Pattern unkgram = encoder.buildpattern(unkstring);
} catch (const InternalError &e) {
} catch (const UnknownTokenError &e) {
caught = true;
}
test(caught,true);

Pattern unkgram2 = encoder.buildpattern(unkstring, true);
cerr << "Encode as unknown when allowunknown=true"; test(unkgram2.decode(classdecoder),"To {?} {?} or not");
cerr << "Encode as unknown when allowunknown=true"; test(unkgram2.decode(classdecoder),"to {?} {?} or not");

cerr << endl << "************************** Skipgram tests ***************************************" << endl << endl;

Expand Down

0 comments on commit 7caaa31

Please sign in to comment.