Skip to content

Commit

Permalink
first-stage/PARSE: Remove two-part error messages
Browse files Browse the repository at this point in the history
These are messages where parts are printed to stderr followed by an
assertion failure. Now there is only an assertion failure (which converts
more cleanly into Python exceptions).
  • Loading branch information
dmcc committed Aug 11, 2015
1 parent c6c61fa commit 33343f3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
21 changes: 10 additions & 11 deletions first-stage/PARSE/InputTree.C
Expand Up @@ -12,21 +12,22 @@
* under the License.
*/

#include <assert.h>
#include <fstream>
#include <iostream>
#include <set>
#include <sstream>
#include "InputTree.h"
#include "headFinder.h"
#include "utils.h"
#include <assert.h>
#include <set>
#include "Term.h"


int InputTree::pageWidth = 75; //used for prettyPrinting
ECString InputTree::tempword[MAXSENTLEN];
int InputTree::tempwordnum = 0;

// reset internal state after reporting an error
// reset internal state before reporting an error
#define TREEREADINGERROR(message) \
{ InputTree::init(); error(__FILE__, __LINE__, message); }

Expand Down Expand Up @@ -93,8 +94,7 @@ readParse(istream& is)
if(!is) return;
if(temp != "(")
{
cerr << "Saw " << temp << endl;
TREEREADINGERROR("Should have seen an open paren here.");
TREEREADINGERROR("Saw '" + temp + "' instead of open paren here.");
}
/* get annotated symbols like NP-OBJ. term_ = NP ntInfo_ = OBJ */
temp = readNext(is);
Expand All @@ -110,8 +110,7 @@ readParse(istream& is)
if(temp == ")") return;
if(temp != "(")
{
cerr << "Saw " << temp << endl;
TREEREADINGERROR("Should have seen second open paren here.");
TREEREADINGERROR("Saw '" + temp + "' instead of second open paren here.");
}

for (;;)
Expand All @@ -125,8 +124,9 @@ readParse(istream& is)
if (temp==")") break;
if (temp!="(")
{
cerr << *this << endl;
TREEREADINGERROR("Should have open or closed paren here.");
stringstream message("Saw '");
message << *this << "' instead of open or closed paren here.";
TREEREADINGERROR(message.str());
}
}
}
Expand Down Expand Up @@ -176,8 +176,7 @@ newParse(istream& is, int& strt, InputTree* par)
const Term* ctrm = Term::get(trm);
if(!ctrm)
{
cerr << "No such term " << trm << endl;
assert(ctrm);
TREEREADINGERROR("No such term: " + trm);
}
if(wrd!="" && !(ctrm->terminal_p()))
{
Expand Down
7 changes: 7 additions & 0 deletions first-stage/PARSE/utils.C
Expand Up @@ -52,6 +52,13 @@ error(const char *s)
ERROR( s );
}

void
error(const char *filename, int filelinenum, string str)
{
const char* s = str.c_str();
error(filename, filelinenum, s);
}

ECString
langAwareToLower(ECString str)
{
Expand Down
5 changes: 3 additions & 2 deletions first-stage/PARSE/utils.h
Expand Up @@ -24,8 +24,9 @@
#define WARN( msg ) if (!Bchart::silent) { warn( __FILE__, __LINE__, msg ); }
#define ERROR( msg ) error( __FILE__, __LINE__, msg )

void warn( const char *filename, int filelinenum, const char *msg );
void error( const char *filename, int filelinenum, const char *msg );
void warn(const char *filename, int filelinenum, const char *msg);
void error(const char *filename, int filelinenum, const char *msg);
void error(const char *filename, int filelinenum, string str);
void error(const char *s); // backwards compatibility

ECString langAwareToLower(ECString str);
Expand Down
10 changes: 5 additions & 5 deletions python/tests/test_tree.py
Expand Up @@ -14,7 +14,7 @@ def test_tree_errors():
bllipparser.Tree('(())')
File "/usr/local/lib/python2.7/dist-packages/bllipparser/RerankingParser.py", line 63, in __init__
parser.inputTreeFromString(input_tree_or_string)
RuntimeError: [first-stage/PARSE/InputTree.C:260]: Saw paren rather than term
RuntimeError: [first-stage/PARSE/InputTree.C:259]: Saw paren rather than term
>>> bllipparser.Tree('(S1 (S (NP (DT This)) (VP (VBZ is) (NP (DT a) (ADJP (RB fairly) (JJ simple)) (NN parse) (NN tree))) (. .)))')
Tree('(S1 (S (NP (DT This)) (VP (VBZ is) (NP (DT a) (ADJP (RB fairly) (JJ simple)) (NN parse) (NN tree))) (. .)))')
>>> bllipparser.Tree('(S1 (S (NP (DT This)) (VP (VBZ is) (NP (DT a) (ADJP (RB fairly) (JJ simple)) (NN parse) (NN tree))) (. .)))')
Expand All @@ -36,7 +36,7 @@ def test_tree_errors():
bllipparser.Tree('Does not start with a paren')
File "/usr/local/lib/python2.7/dist-packages/bllipparser/RerankingParser.py", line 63, in __init__
parser.inputTreeFromString(input_tree_or_string)
RuntimeError: [first-stage/PARSE/InputTree.C:97]: Should have seen an open paren here.
RuntimeError: [first-stage/PARSE/InputTree.C:97]: Saw 'Does' instead of open paren here.
>>> bllipparser.Tree('(S1 eh)')
Traceback (most recent call last):
File "/usr/lib/python2.7/doctest.py", line 1315, in __run
Expand All @@ -45,7 +45,7 @@ def test_tree_errors():
bllipparser.Tree('(S1 eh)')
File "/usr/local/lib/python2.7/dist-packages/bllipparser/RerankingParser.py", line 63, in __init__
parser.inputTreeFromString(input_tree_or_string)
RuntimeError: [first-stage/PARSE/InputTree.C:114]: Should have seen second open paren here.
RuntimeError: [first-stage/PARSE/InputTree.C:113]: Saw 'eh' instead of second open paren here.
>>> bllipparser.Tree('(S1')
Traceback (most recent call last):
File "/usr/lib/python2.7/doctest.py", line 1315, in __run
Expand All @@ -54,7 +54,7 @@ def test_tree_errors():
bllipparser.Tree('(S1')
File "/usr/local/lib/python2.7/dist-packages/bllipparser/RerankingParser.py", line 63, in __init__
parser.inputTreeFromString(input_tree_or_string)
RuntimeError: [first-stage/PARSE/InputTree.C:114]: Should have seen second open paren here.
RuntimeError: [first-stage/PARSE/InputTree.C:113]: Saw '' instead of second open paren here.
>>> bllipparser.Tree('(S1 ((')
Traceback (most recent call last):
File "/usr/lib/python2.7/doctest.py", line 1315, in __run
Expand All @@ -63,7 +63,7 @@ def test_tree_errors():
bllipparser.Tree('(S1 ((')
File "/usr/local/lib/python2.7/dist-packages/bllipparser/RerankingParser.py", line 63, in __init__
parser.inputTreeFromString(input_tree_or_string)
RuntimeError: [first-stage/PARSE/InputTree.C:260]: Saw paren rather than term
RuntimeError: [first-stage/PARSE/InputTree.C:259]: Saw paren rather than term
>>> bllipparser.Tree('(S1 (NP')
Traceback (most recent call last):
File "/usr/lib/python2.7/doctest.py", line 1315, in __run
Expand Down

0 comments on commit 33343f3

Please sign in to comment.