/** * Performs some basic processing of the input source and target files. The input files are also * copied to the /input folder. This is necessary because the some tools (e.g., the MADA * morphological analyser) produce their output in the same folder as the input file, which may * cause problems if the right access rights are not available for that particular folder */ protected void preprocessing() { String sourceInputFolder = input + File.separator + sourceLang; String targetInputFolder = input + File.separator + targetLang; File origSourceFile = new File(getSourceFile()); File inputSourceFile = new File(sourceInputFolder + File.separator + origSourceFile.getName()); System.out.println("source input:" + getSourceFile()); System.out.println("target input:" + getTargetFile()); File origTargetFile = new File(getTargetFile()); File inputTargetFile = new File(targetInputFolder + File.separator + origTargetFile.getName()); try { System.out.println("copying input to " + inputSourceFile.getPath()); copyFile(origSourceFile, inputSourceFile); System.out.println("copying input to " + inputTargetFile.getPath()); copyFile(origTargetFile, inputTargetFile); setSourceFile(inputSourceFile.getPath()); setTargetFile(inputTargetFile.getPath()); } catch (Exception e) { e.printStackTrace(); } }
/** * makes a copy of one file into another * * @param sourceFile the source file path * @param destFile the destination file path * @throws IOException */ private static void copyFile(File sourceFile, File destFile) throws IOException { if (sourceFile.equals(destFile)) { System.out.println("source=dest"); return; } if (!destFile.exists()) { destFile.createNewFile(); } java.nio.channels.FileChannel source = null; java.nio.channels.FileChannel destination = null; try { source = new FileInputStream(sourceFile).getChannel(); destination = new FileOutputStream(destFile).getChannel(); destination.transferFrom(source, 0, source.size()); } finally { if (source != null) { source.close(); } if (destination != null) { destination.close(); } } }
/** * constructs the folders required by the application. These are, typically: <br> * * <ul> * <li>/input and subfolders * <ul> * <li>/input/<i>sourceLang</i>, /input/<i>targetLang</i> (for storing the results of * processing the input files with various tools, such as pos tagger, transliterator, * morphological analyser),<br> * <li>/input/systems/<i>systemName</i> (for storing system specific resources - for * example, the compiled and processed word lattices in the case of the IBM system * </ul> * <li>/output (for storing the resulting feature files), * </ul> * * Subclasses can override this method to construct, for example, subfolders of the systems folder * for each available MT system, or temporary folders */ public void constructFolders() { File f = new File(input); if (!f.exists()) { f.mkdir(); System.out.println("folder created " + f.getPath()); } f = new File(input + File.separator + sourceLang); if (!f.exists()) { f.mkdir(); System.out.println("folder created " + f.getPath()); } f = new File(input + File.separator + targetLang); if (!f.exists()) { f.mkdir(); System.out.println("folder created " + f.getPath()); } f = new File(input + File.separator + targetLang + File.separator + "temp"); if (!f.exists()) { f.mkdir(); System.out.println("folder created " + f.getPath()); } f = new File(input + File.separator + "systems"); if (!f.exists()) { f.mkdir(); System.out.println("folder created " + f.getPath()); } String output = resourceManager.getString("output"); f = new File(output); if (!f.exists()) { f.mkdir(); System.out.println("folder created " + f.getPath()); } }