From 4642057fe68629f5869cec96229d7bdea2e700fa Mon Sep 17 00:00:00 2001 From: Jon May Date: Mon, 23 Nov 2015 17:10:13 -0800 Subject: [PATCH 1/2] relative pathname, proper handling of error case --- src/amr.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/amr.py b/src/amr.py index 49aa5b0..c634a3b 100755 --- a/src/amr.py +++ b/src/amr.py @@ -21,12 +21,14 @@ from collections import defaultdict, namedtuple, Counter, Container from parsimonious.grammar import Grammar +from parsimonious.exceptions import ParseError from nltk.parse import DependencyGraph def clean_grammar_file(s): return re.sub('\n[ \t]+', ' ', re.sub(r'#.*','',s.replace('\t',' ').replace('`','_backtick'))) -with open('amr.peg') as inF: +scriptdir = os.path.dirname(os.path.abspath(__file__)) +with open(os.path.join(scriptdir, 'amr.peg')) as inF: grammar = Grammar(clean_grammar_file(inF.read())) @@ -255,7 +257,10 @@ def __init__(self, anno, tokens=None): self.nodes[TOP]['type'] = 'TOP' if anno: self._anno = anno - p = grammar.parse(anno) + try: + p = grammar.parse(anno) + except ParseError as e: + raise AMRSyntaxError('Bad parse: '+str(e)) if p is None: raise AMRSyntaxError('Well-formedness error in annotation:\n'+anno.strip()) self._analyze(p) From 4205ec5a3b38069217a67d22933f7587b9233fd2 Mon Sep 17 00:00:00 2001 From: Jon May Date: Mon, 23 Nov 2015 17:15:37 -0800 Subject: [PATCH 2/2] test case to show problem with parsing negative value --- src/amr.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/amr.py b/src/amr.py index c634a3b..322baad 100755 --- a/src/amr.py +++ b/src/amr.py @@ -558,7 +558,9 @@ def walk(n): # (v / concept...) :calendar (c2 / country :wiki "Japan" :name (n2 / name :op1 "Japan"))))''', ''' (d / date-entity :polite + - :time (a / amr-unknown))''' + :time (a / amr-unknown))''', +'''( o / have-01 :ARG0 o :value 2)''', +#'''( o / have-01 :ARG0 o :value -2)''' # causes errors if uncommented ] sembad_tests = [ # not a syntax error, but malformed in terms of variables