Skip to content

Commit

Permalink
dkpro#1443 - Make BratReader more forgiving
Browse files Browse the repository at this point in the history
- Fix checkstyle issues
  • Loading branch information
reckart committed Dec 26, 2019
1 parent 277724a commit 2f61fbf
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.maven.model.PatternSet;
import org.apache.uima.UimaContext;
import org.apache.uima.cas.CAS;
import org.apache.uima.cas.Feature;
Expand Down Expand Up @@ -73,7 +72,6 @@
import org.dkpro.core.io.brat.internal.model.Offsets;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.Nulls;
import com.fasterxml.jackson.core.JsonParser;
Expand All @@ -93,7 +91,10 @@
public class BratReader
extends JCasResourceCollectionReader_ImplBase
{
public enum SourceLocationType {SINGLE_FILE, SINGLE_DIR, GLOB_PATTERN}
public enum SourceLocationType
{
SINGLE_FILE, SINGLE_DIR, GLOB_PATTERN
}

/**
* Name of configuration parameter that contains the character encoding used by the input files.
Expand Down Expand Up @@ -684,8 +685,9 @@ private boolean sourceLocationIsSingleDirectory() {
return false;
}

private void possiblyAddAnnFilePattern() {
if (!sourceLocationIsSingleFile()) {
private void possiblyAddAnnFilePattern()
{
if (!sourceLocationIsSingleFile()) {
// sourceLocation is not a single file. Make sure
// the file patterns includes *.ann
//
Expand All @@ -700,7 +702,7 @@ private void possiblyAddAnnFilePattern() {
}
}
if (!alreadyHasAnnPattern) {
String[] augmPatterns = new String[patterns.length+1];
String[] augmPatterns = new String[patterns.length + 1];
for (int ii = 0; ii < patterns.length; ii++) {
augmPatterns[ii] = patterns[ii];
}
Expand All @@ -725,7 +727,7 @@ private Mapping getDefaultMapping() {
"ProductDesc", "Quantity", "Substance", "Time", "WorkOfArt"
};
for (String typeName: nerTypeNames) {
String aType = "de.tudarmstadt.ukp.dkpro.core.api.ner.type."+typeName;
String aType = "de.tudarmstadt.ukp.dkpro.core.api.ner.type." + typeName;
txtTypeMappingLst.add(new TypeMapping(aType, typeName));
}
}
Expand All @@ -737,7 +739,8 @@ private Mapping getDefaultMapping() {
"StopWord", "SurfaceForm", "Token"
};
for (String typeName: segTypeNames) {
String aType = "de.tudarmstadt.ukp.dkpro.core.api.segmentation.type."+typeName;
String aType = "de.tudarmstadt.ukp.dkpro.core.api.segmentation.type."
+ typeName;
txtTypeMappingLst.add(new TypeMapping(aType, typeName));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -80,6 +80,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attribs) {
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult visitFileFailed(Path file, IOException io)
{
return FileVisitResult.SKIP_SUBTREE;
Expand Down Expand Up @@ -128,7 +129,9 @@ public static File[] listFiles(String[] patterns) {
Set<File> matchingFilesLst = new HashSet<File>();
for (String aPattern: patterns) {
File[] filesThisPattern = listFiles(aPattern);
for (File aFile: filesThisPattern) matchingFilesLst.add(aFile);
for (File aFile: filesThisPattern) {
matchingFilesLst.add(aFile);
}
}

File[] matchingFilesArr = matchingFilesLst.toArray(new File[matchingFilesLst.size()]);
Expand All @@ -154,7 +157,9 @@ public static void main(String[] args) {
String pattern = args[0];
System.out.println("Files matching: " + pattern);
File[] files = FileGlob.listFiles(pattern);
if (files.length == 0) System.out.println("No match found");
if (files.length == 0) {
System.out.println("No match found");
}
for (File aFile: files) {
System.out.println(aFile.getAbsolutePath());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import org.apache.commons.collections4.multimap.ArrayListValuedHashMap;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class Mapping
{
Expand Down Expand Up @@ -109,7 +107,8 @@ public static Mapping merge(Mapping customMapping, Mapping defaultMapping) {
List<TypeMapping> relTypeMapppingsLst = new ArrayList<TypeMapping>();
relTypeMapppingsLst.addAll(customMapping.getRelationTypeMapppings().getParsedMappings());
if (!justCustomMapping) {
relTypeMapppingsLst.addAll(defaultMapping.getRelationTypeMapppings().getParsedMappings());
relTypeMapppingsLst
.addAll(defaultMapping.getRelationTypeMapppings().getParsedMappings());
}
TypeMappings relTypeMapppings = new TypeMappings(relTypeMapppingsLst);

Expand All @@ -118,7 +117,8 @@ public static Mapping merge(Mapping customMapping, Mapping defaultMapping) {
List<RelationMapping> relations = new ArrayList<RelationMapping>();
List<CommentMapping> comments = new ArrayList<CommentMapping>();

Mapping merged = new Mapping(textTypeMapppings, relTypeMapppings, spans, relations, comments);
Mapping merged = new Mapping(textTypeMapppings, relTypeMapppings, spans, relations,
comments);

// Add the Text Annotations from both Mapping
for (String type: customMapping.textAnnotations.keySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public TypeMapping getMappingByBratType(String aBratType)

public Type getUimaType(TypeSystem aTs, BratAnnotation aAnno)
{
System.out.println("-- getUimaType: aAnno.getType()="+aAnno.getType());
System.out.println("-- getUimaType: aAnno.getType()=" + aAnno.getType());
Type t = brat2UimaMappingCache.get(aAnno.getType());

if (t == null) {
Expand All @@ -108,7 +108,7 @@ public Type getUimaType(TypeSystem aTs, BratAnnotation aAnno)
+ aAnno.getType() + "]");
}

System.out.println("-- getUimaType: returning t="+t);
System.out.println("-- getUimaType: returning t=" + t);

return t;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.collection.CollectionReader;
import org.apache.uima.fit.component.JCasAnnotator_ImplBase;
import org.apache.uima.fit.component.JCasCollectionReader_ImplBase;
import org.apache.uima.fit.pipeline.SimplePipeline;
import org.apache.uima.jcas.JCas;
import org.dkpro.core.api.io.JCasResourceCollectionReader_ImplBase;
import org.dkpro.core.io.brat.BratReader;
import org.dkpro.core.io.brat.BratWriter;
import org.dkpro.core.io.conll.Conll2009Reader;
import org.dkpro.core.io.conll.Conll2012Reader;
import org.dkpro.core.testing.DkproTestContext;
Expand All @@ -54,8 +50,6 @@
import org.junit.Rule;
import org.junit.Test;

import com.fasterxml.jackson.core.json.ReaderBasedJsonParser;

//NOTE: This file contains Asciidoc markers for partial inclusion of this file in the documentation
//Do not remove these tags!
public class BratReaderWriterTest
Expand Down Expand Up @@ -696,8 +690,9 @@ private File copyBratFilesToTempLocation(File bratDir)
return copyBratFilesToTempLocation(bratDir, null);
}

private File copyBratFilesToTempLocation(File bratDir, Boolean deleteAnnFiles)
throws IOException {
private File copyBratFilesToTempLocation(File bratDir, Boolean deleteAnnFiles)
throws IOException
{

if (deleteAnnFiles == null) {
deleteAnnFiles = false;
Expand All @@ -720,8 +715,9 @@ private File copyBratFilesToTempLocation(File bratDir, Boolean deleteAnnFiles)
}

private void assertFilesHaveSameContent(File expFileOrDir, File actualFileOrDir,
Boolean expectEmptyAnnFiles) throws IOException {

Boolean expectEmptyAnnFiles)
throws IOException
{
if (expectEmptyAnnFiles == null) {
expectEmptyAnnFiles = false;
}
Expand Down

0 comments on commit 2f61fbf

Please sign in to comment.