You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by jo...@apache.org on 2016/12/26 13:34:30 UTC

[36/50] [abbrv] opennlp git commit: Improve error reporting on brat parser crashes

Improve error reporting on brat parser crashes

Parsing errors are now catched and wrapped in
an IOException containing the document id for
tracking down the actual file.

See issue OPENNLP-881


Project: http://git-wip-us.apache.org/repos/asf/opennlp/repo
Commit: http://git-wip-us.apache.org/repos/asf/opennlp/commit/0debe9c1
Tree: http://git-wip-us.apache.org/repos/asf/opennlp/tree/0debe9c1
Diff: http://git-wip-us.apache.org/repos/asf/opennlp/diff/0debe9c1

Branch: refs/heads/889
Commit: 0debe9c1fc70c31b491ac99c4373040177435ef3
Parents: 727964d
Author: J�rn Kottmann <jo...@apache.org>
Authored: Thu Nov 10 01:07:14 2016 +0100
Committer: Joern Kottmann <jo...@apache.org>
Committed: Wed Dec 21 10:54:53 2016 +0100

----------------------------------------------------------------------
 .../formats/brat/BratAnnotationStream.java      | 25 +++++++++++++-------
 1 file changed, 16 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/opennlp/blob/0debe9c1/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratAnnotationStream.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratAnnotationStream.java b/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratAnnotationStream.java
index 91a2916..125e662 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratAnnotationStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratAnnotationStream.java
@@ -82,9 +82,14 @@ public class BratAnnotationStream implements ObjectStream<BratAnnotation> {
         String coveredText = line.subSequence(values[firstTextTokenIndex].getStart(),
             values[values.length - 1].getEnd()).toString();
 
-        return new SpanAnnotation(id, type,
-            new Span(parseInt(values[BEGIN_OFFSET]
-                .getCoveredText(line).toString()), endOffset, type), coveredText);
+        try {
+          return new SpanAnnotation(id, type,
+                  new Span(parseInt(values[BEGIN_OFFSET]
+                          .getCoveredText(line).toString()), endOffset, type), coveredText);
+        }
+        catch (IllegalArgumentException e) {
+          throw new InvalidFormatException(e);
+        }
       }
       else {
         throw new InvalidFormatException("Line must have at least 5 fields");
@@ -172,18 +177,20 @@ public class BratAnnotationStream implements ObjectStream<BratAnnotation> {
         BratAnnotationParser parser = parsers.get(typeClass);
 
         if (parser == null) {
-          throw new IOException("Failed to parse ann document with id " + id +
+          throw new IOException("Failed to parse ann document with id " + id + ".ann" +
               " type class, no parser registered: " + tokens[BratAnnotationParser.TYPE_OFFSET]
               .getCoveredText(line).toString());
         }
 
-        return parser.parse(tokens, line);
+        try {
+          return parser.parse(tokens, line);
+        }
+        catch (IOException e)  {
+          throw new IOException(String.format("Failed to parse ann document with id [%s.ann]", id), e);
+        }
       }
     }
-    else {
-      return null;
-    }
-
+    
     return null;
   }