return new AnnotationConfiguration(typeToClassMap);
private BratNameSampleStream createNameSampleWith(String nameContainsFilter, Set<String> nameTypes) throws IOException { Map<String, String> typeToClassMap = new HashMap<>(); BratAnnotationStreamTest.addEntityTypes(typeToClassMap); AnnotationConfiguration config = new AnnotationConfiguration(typeToClassMap); File dir = new File(this.getClass().getResource("/opennlp/tools/formats/brat/").getFile()); FileFilter fileFilter = pathname -> pathname.getName().contains(nameContainsFilter); ObjectStream<BratDocument> bratDocumentStream = new BratDocumentStream(config, dir, false, fileFilter); return new BratNameSampleStream(new NewlineSentenceDetector(), WhitespaceTokenizer.INSTANCE, bratDocumentStream, nameTypes); }
@Test public void testParsingRelations() throws Exception { Map<String, String> typeToClassMap = new HashMap<>(); addEntityTypes(typeToClassMap); typeToClassMap.put("Related", AnnotationConfiguration.RELATION_TYPE); AnnotationConfiguration annConfig = new AnnotationConfiguration(typeToClassMap); ObjectStream<BratAnnotation> annStream = creatBratAnnotationStream(annConfig, "/opennlp/tools/formats/brat/voa-with-relations.ann"); // TODO: Test if we get the entities ... we expect! BratAnnotation ann; while ((ann = annStream.read()) != null) { System.out.println(ann); } } }
@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"); // TODO: Test if we get the entities ... we expect! BratAnnotation ann; while ((ann = annStream.read()) != null) { System.out.println(ann); } }
@Test public void testDocumentWithEntitiesParsing() throws IOException { Map<String, String> typeToClassMap = new HashMap<>(); BratAnnotationStreamTest.addEntityTypes(typeToClassMap); AnnotationConfiguration config = new AnnotationConfiguration(typeToClassMap); InputStream txtIn = BratDocumentTest.class.getResourceAsStream( "/opennlp/tools/formats/brat/voa-with-entities.txt"); InputStream annIn = BratDocumentTest.class.getResourceAsStream( "/opennlp/tools/formats/brat/voa-with-entities.ann"); BratDocument doc = BratDocument.parseDocument(config, "voa-with-entities", txtIn, annIn); Assert.assertEquals("voa-with-entities", doc.getId()); Assert.assertTrue(doc.getText().startsWith(" U . S . President ")); Assert.assertTrue(doc.getText().endsWith("multinational process . \n")); Assert.assertEquals(18, doc.getAnnotations().size()); BratAnnotation annotation = doc.getAnnotation("T2"); checkNote(annotation, "Barack Obama", "President Obama was the 44th U.S. president"); annotation = doc.getAnnotation("T3"); checkNote(annotation,"South Korea","The capital of South Korea is Seoul"); }
return new AnnotationConfiguration(typeToClassMap);
return new AnnotationConfiguration(typeToClassMap);
AnnotationConfiguration config = new AnnotationConfiguration(typeToClassMap);
Map<String, String> typeToClassMap = new HashMap<>(); BratAnnotationStreamTest.addEntityTypes(typeToClassMap); AnnotationConfiguration config = new AnnotationConfiguration(typeToClassMap);
typeToClassMap.put("Date", AnnotationConfiguration.ENTITY_TYPE); AnnotationConfiguration config = new AnnotationConfiguration(typeToClassMap); InputStream in = ObjectStreamUtils.class.getResourceAsStream(nameFinderSubjectOfTraining.getInputFile() + ".ann");