@Test public void testParsingEntities() throws Exception { Map<String, String> typeToClassMap = new HashMap<>(); addEntityTypes(typeToClassMap); AnnotationConfiguration annConfig = new AnnotationConfiguration(typeToClassMap); ObjectStream<BratAnnotation> annStream = creatBratAnnotationStream(annConfig, "/opennlp/tools/formats/brat/voa-with-entities.ann"); BratAnnotation ann; while ((ann = annStream.read()) != null) { System.out.println(ann); } }
public BratAnnotation read() throws IOException { String line = reader.readLine(); if (line != null) { Span[] tokens = WhitespaceTokenizer.INSTANCE.tokenizePos(line); if (tokens.length > 2) { String annId = tokens[BratAnnotationParser.ID_OFFSET].getCoveredText(line).toString(); if (annId.length() == 0) { throw new InvalidFormatException("annotation id is empty"); } final BratAnnotationParser parser; switch (annId.charAt(0)) { case 'T': parser = new SpanAnnotationParser(); break; case 'R': parser = new RelationAnnotationParser(); break; case 'A': parser = new AttributeAnnotationParser(); break; case 'E': parser = new EventAnnotationParser(); break; case '#': if ( tokens[BratAnnotationParser.TYPE_OFFSET].getCoveredText(line).toString().equals( BratAnnotationParser.NOTES_TYPE) ) { parser = new AnnotatorNoteParser(); } else { return read(); } break; default: return read(); } 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); } } } return null; }
BratAnnotationStream implements ObjectStream<BratAnnotation> { public BratAnnotation read() throws IOException { String line = reader.readLine(); if (line != null) { Span[] tokens = WhitespaceTokenizer.INSTANCE.tokenizePos(line); if (tokens.length > 2) { String annId = tokens[BratAnnotationParser.ID_OFFSET].getCoveredText(line).toString(); if (annId.length() == 0) { throw new InvalidFormatException("annotation id is empty"); } final BratAnnotationParser parser; switch (annId.charAt(0)) { case 'T': parser = new SpanAnnotationParser(); break; case 'R': parser = new RelationAnnotationParser(); break; case 'A': parser = new AttributeAnnotationParser(); break; case 'E': parser = new EventAnnotationParser(); break; case '#': if ( tokens[BratAnnotationParser.TYPE_OFFSET].getCoveredText(line).toString().equals( BratAnnotationParser.NOTES_TYPE) ) { parser = new AnnotatorNoteParser(); } else { return read(); } break; default: return read(); } 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); } } } return null; } }
BratAnnotationStream implements ObjectStream<BratAnnotation> { public BratAnnotation read() throws IOException { String line = reader.readLine(); if (line != null) { Span[] tokens = WhitespaceTokenizer.INSTANCE.tokenizePos(line); if (tokens.length > 2) { String annId = tokens[BratAnnotationParser.ID_OFFSET].getCoveredText(line).toString(); if (annId.length() == 0) { throw new InvalidFormatException("annotation id is empty"); } final BratAnnotationParser parser; switch (annId.charAt(0)) { case 'T': parser = new SpanAnnotationParser(); break; case 'R': parser = new RelationAnnotationParser(); break; case 'A': parser = new AttributeAnnotationParser(); break; case 'E': parser = new EventAnnotationParser(); break; case '#': if ( tokens[BratAnnotationParser.TYPE_OFFSET].getCoveredText(line).toString().equals( BratAnnotationParser.NOTES_TYPE) ) { parser = new AnnotatorNoteParser(); } else { return read(); } break; default: return read(); } 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); } } } return null; } BratAnnotationStream(AnnotationConfiguration config, String id, InputStream in); }
BratAnnotationStream implements ObjectStream<BratAnnotation> { public BratAnnotation read() throws IOException { String line = reader.readLine(); if (line != null) { Span[] tokens = WhitespaceTokenizer.INSTANCE.tokenizePos(line); if (tokens.length > 2) { String annId = tokens[BratAnnotationParser.ID_OFFSET].getCoveredText(line).toString(); if (annId.length() == 0) { throw new InvalidFormatException("annotation id is empty"); } final BratAnnotationParser parser; switch (annId.charAt(0)) { case 'T': parser = new SpanAnnotationParser(); break; case 'R': parser = new RelationAnnotationParser(); break; case 'A': parser = new AttributeAnnotationParser(); break; case 'E': parser = new EventAnnotationParser(); break; case '#': if ( tokens[BratAnnotationParser.TYPE_OFFSET].getCoveredText(line).toString().equals( BratAnnotationParser.NOTES_TYPE) ) { parser = new AnnotatorNoteParser(); } else { return read(); } break; default: return read(); } 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); } } } return null; } BratAnnotationStream(AnnotationConfiguration config, String id, InputStream in); BratAnnotation read(); void reset(); void close(); }
BratAnnotationStream implements ObjectStream<BratAnnotation> { public BratAnnotation read() throws IOException { String line = reader.readLine(); if (line != null) { Span[] tokens = WhitespaceTokenizer.INSTANCE.tokenizePos(line); if (tokens.length > 2) { String annId = tokens[BratAnnotationParser.ID_OFFSET].getCoveredText(line).toString(); if (annId.length() == 0) { throw new InvalidFormatException("annotation id is empty"); } final BratAnnotationParser parser; switch (annId.charAt(0)) { case 'T': parser = new SpanAnnotationParser(); break; case 'R': parser = new RelationAnnotationParser(); break; case 'A': parser = new AttributeAnnotationParser(); break; case 'E': parser = new EventAnnotationParser(); break; case '#': if ( tokens[BratAnnotationParser.TYPE_OFFSET].getCoveredText(line).toString().equals( BratAnnotationParser.NOTES_TYPE) ) { parser = new AnnotatorNoteParser(); } else { return read(); } break; default: return read(); } 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); } } } return null; } BratAnnotationStream(AnnotationConfiguration config, String id, InputStream in); BratAnnotation read(); void reset(); void close();  }