gt: 		List<String[]> matrix = new LinkedList<>();
context: package eu.transkribus.core.util;
  
  import java.io.File;
  import java.io.FileFilter;
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.LinkedList;
  import java.util.List;
  import java.util.regex.Matcher;
  import java.util.regex.Pattern;
  
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  import eu.transkribus.core.model.beans.HtrModel;
  import eu.transkribus.core.model.beans.WordHypothesis;
  import eu.transkribus.core.model.beans.job.enums.JobImpl;
  
  public class HtrUtils {
  	private static final Logger logger = LoggerFactory.getLogger(HtrUtils.class);
  
  	/**
  	 * use Transkribus storage instead
  	 */
  	@Deprecated
  	public static final String MODEL_PATH = "/mnt/dea_scratch/TRP/HTR/models/";
  
  	public static final String SEP = ".";
  	public static final String SEP_PATTERN = "\\.";
  
  	// the file extension of line imgs
  	public static final String LINE_IMG_EXT = ".png";
  	// preprocessed lines have to be stored as pgm file!
  	public static final String PREPROC_LINE_EXT = ".pgm";
  	// files containing features of line imgs
  	public static final String FEAT_FILE_EXT = ".fea";
  	// this file stores relative (to lineImgDir i.e. workdir) paths to feature
  	// files
  	public static final String TEST_LIST_NAME = "list.test";
  
  	// 300 594 recapitulatory -7436.380371
  	private static final String REC_LINE_PATTERN = "[0-9]+\\s[0-9]+\\s(.*)\\s-?[0-9]+\\.[0-9]+";
  	public static final String FILENAME_PATTERN = "([A-Z]{24})" + SEP_PATTERN + "([0-9]+)" + SEP_PATTERN + "([0-9]+)"
  			+ SEP_PATTERN + "([a-zA-Z0-9[_-]]+)" + SEP_PATTERN + "([a-zA-Z0-9[_-]]+)";
  
  	private static final String FLOAT_NR = "[+-]?(?:[0-9]*\\.[0-9]+|[0-9]+)"; // regex
  																				// for
  																				// floating
  																				// point
  																				// nr.
  																				// with
  																				// optional
  																				// -
  																				// sign
  	// private static final String LATTICE_TOOL_LINE_PATTERN_STR =
  	// "-?[0-9]+\\.[0-9]+\\s-?[0-9]+\\.[0-9]+\\s[0-9]+\\s<s>\\s(.*)\\s</s>";
  	private static final String LATTICE_TOOL_LINE_PATTERN_STR = FLOAT_NR + "\\s" + FLOAT_NR
  			+ "\\s[0-9]+\\s<s>\\s(.*)\\s</s>";
  	static final Pattern LATTICE_TOOL_LINE_PATTERN = Pattern.compile(LATTICE_TOOL_LINE_PATTERN_STR);
  
  	/**
  	 * Each extracted line image is named with the PAGE file's ID plus the
  	 * positional number of region and line according to the reading order, and
  	 * the original IDs of region and line appearing in the PAGE file.
  	 * 
  	 * TODO implement mapping of name schema in both directions, e.g. for
  	 * mapping the results back to entities
  	 */
  	public static String buildFileName(final String pageFileId, final int regIndex, final int lineIndex,
  			final String regId, final String lineId, String fileExt) throws IllegalArgumentException {
  		fileExt = fileExt.startsWith(".") ? fileExt : "." + fileExt;
  		final String fileName = buildBaseFileName(pageFileId, regIndex, lineIndex, regId, lineId);
  		// TODO check pattern
  		return fileName + fileExt;
  	}
  
  	public static String buildBaseFileName(final String pageFileId, final int regIndex, final int lineIndex,
  			final String regId, final String lineId) throws IllegalArgumentException {
  		if (regId.contains(SEP) || lineId.contains(SEP)) {
  			throw new IllegalArgumentException(
  					"A regionID contains the illegal character \"" + SEP + "\":" + regId + " | " + lineId);
  		}
  		final String fileName = pageFileId + SEP + regIndex + SEP + lineIndex + SEP + regId + SEP + lineId;
  		// TODO check pattern
  		return fileName;
  	}
  
  	public static String readRecFile(File rec) throws IOException {
  		final String fileText = DeaFileUtils.readFileAsString(rec);
  		final String text = extractRecText(fileText);
  		return text;
  	}
  
  	public static String readFeaGzFile(File rec) throws IOException {
  		final String fileText = DeaFileUtils.readGzFileAsString(rec);
  		final String text = extractRecText(fileText);
  		return text;
  	}
  
  	// public static TrpWordgraph decodeFilename()
  
  	private static String extractRecText(String fileText) {
  		String[] lines = fileText.split("\n");
  		Pattern p = Pattern.compile(REC_LINE_PATTERN);
  		StringBuffer sb = new StringBuffer();
  		for (String l : lines) {
  			Matcher m = p.matcher(l);
  			if (m.find()) {
  				final String word = m.group(1);
  				logger.debug("extracted word: " + word);
  				sb.append(word + " ");
  			} else {
  				logger.error("found NO word in line: " + l);
  			}
  		}
  		return sb.toString().trim();
  	}
  
  	// private static void test(){
  	// final String n = "ULQSYKGJXPMXQQFUHRGLEPDT_2_12_r2_r136";
  	// final String regex = HtrUtils.FILENAME_PATTERN;
  	// Pattern p = Pattern.compile(regex);
  	// Matcher m = p.matcher(n);
  	//
  	// if(m.find()){
  	// String xmlKey = m.group(1);
  	// String lineId = m.group(5);
  	// logger.info("xmlKey = " + xmlKey + " | lineId = " + lineId);
  	// } else {
  	// logger.error("Filename is corrupt: " + n);
  	// }
  	//
  	// }
  
  	// public static ArrayList<> getNBestMatrix(String latticeToolOutput) {
  	// String[] lines = latticeToolOutput.split("\n");
  	// ArrayList<String[]> wordsList = new ArrayList<>();
  	//
  	// int maxWords = 0;
  	// for(String l : lines) {
  	// Matcher m = LATTICE_TOOL_LINE_PATTERN.matcher(l);
  	// String transcript;
  	// if(m.find()) {
  	// transcript = m.group(1);
  	// logger.debug("transcript: " + transcript);
  	// } else {
  	// logger.error("found NO words in line: " + l);
  	// continue;
  	// }
  	// String[] words = transcript.split(" ");
  	// if (words.length > maxWords)
  	// maxWords = words.length;
  	// wordsList.add(words);
  	// }
  	//
  	//
  	// for (String[] words : wordsList) {
  	//
  	//
  	//
  	//
  	// }
  	//
  	//
  	// }
  
  	@Deprecated
  	public static String[][] getnBestMatrix(String latticeToolOutput, boolean removeDuplicate) {
  		List<String[]> matrix = new LinkedList<>();
  
  		String[] lines = latticeToolOutput.split("\n");
  		Pattern p = Pattern.compile(LATTICE_TOOL_LINE_PATTERN_STR);
  		for (String l : lines) {
  			Matcher m = p.matcher(l);
  			String transcript;
  			if (m.find()) {
  				transcript = m.group(1);
  				logger.debug("extracted transcript: " + transcript);
  			} else {
  				logger.error("found NO word in line: " + l);
  				continue;
  			}
  			String[] words = transcript.split(" ");
  			int dupl = 0;
  			if (!matrix.isEmpty()) {
  				// check occurrence of words..
  				for (int i = 0; i < words.length; i++) {
  					for (int j = 0; j < matrix.size(); j++) {
  						String[] tmp = matrix.get(j);
  						if (i < tmp.length) {
  							if (!tmp[i].isEmpty() && tmp[i].equals(words[i]) && removeDuplicate) {
  								logger.trace("Removing duplicate: " + words[i]);
  								words[i] = "";
  								dupl++;
  							} else {
  								if (!words[i].isEmpty())
  									logger.trace("Keeping word: " + words[i]);
  							}
  						}
  					}
  				}
  			}
  			if (words.length > dupl) {
  				matrix.add(words);
  			}
  		}
  		return matrix.toArray(new String[matrix.size()][]);
  	}
  
  	public static String[][] getnBestMatrixUpvlc(String upvlcToolOutput, boolean removeDuplicate) {
  