Search in sources :

Example 1 with InputModelReaders

use of com.sri.ai.praise.lang.translate.util.InputModelReaders in project aic-praise by aic-sri-international.

the class RunTranslationsCLI method main.

/**
	 * Translate Probabilistic Models based on given command line arguments.
	 * 
	 * @param args
	 *        pass '--help' to see description of expected program arguments.
	 */
public static void main(String[] args) {
    TranslationArgs translationArgs = getArgs(args);
    for (Translator translator : translationArgs.translators) {
        File sourceDirectory = new File(translationArgs.rootModelOutputDirectory, translator.getSource().getCode());
        if (!sourceDirectory.isDirectory()) {
            throw new IllegalArgumentException("Source Directory " + sourceDirectory + " does not exist");
        }
        File targetDirectory = new File(translationArgs.rootModelOutputDirectory, translator.getTarget().getCode());
        if (!targetDirectory.isDirectory()) {
            targetDirectory.mkdir();
        }
        String sourceModelFileExtension = translator.getInputFileExtensions()[0];
        for (File sourceModelFile : sourceDirectory.listFiles((dir, name) -> name.endsWith(sourceModelFileExtension))) {
            System.out.println("Translating " + sourceModelFile.getName() + " from " + translator.getSource().getCode() + " to " + translator.getTarget().getCode());
            String sourceModelFileNameWithNoExtension = translator.getInputModelFileNameWithNoExtension(sourceModelFile);
            Stopwatch sw = Stopwatch.createStarted();
            try (InputModelReaders inputModelReaders = new InputModelReaders(translator, sourceModelFile, sourceModelFileExtension);
                TranslatedOutputs translatedOutputs = new TranslatedOutputs(translator, sourceModelFile, sourceModelFileExtension)) {
                translator.translate(sourceModelFileNameWithNoExtension, inputModelReaders.readers, translatedOutputs.writers, new TranslatorOptions());
            } catch (Exception ex) {
                System.err.println("Error during translation");
                ex.printStackTrace();
                System.exit(-1);
            }
            sw.stop();
            System.out.println("Took " + sw.toString());
        // TODO - append the time it took to translate the file to a .csv file				
        }
    }
}
Also used : TranslatedOutputs(com.sri.ai.praise.lang.translate.util.TranslatedOutputs) Translator(com.sri.ai.praise.lang.translate.Translator) Stopwatch(com.google.common.base.Stopwatch) TranslatorOptions(com.sri.ai.praise.lang.translate.TranslatorOptions) InputModelReaders(com.sri.ai.praise.lang.translate.util.InputModelReaders) File(java.io.File)

Aggregations

Stopwatch (com.google.common.base.Stopwatch)1 Translator (com.sri.ai.praise.lang.translate.Translator)1 TranslatorOptions (com.sri.ai.praise.lang.translate.TranslatorOptions)1 InputModelReaders (com.sri.ai.praise.lang.translate.util.InputModelReaders)1 TranslatedOutputs (com.sri.ai.praise.lang.translate.util.TranslatedOutputs)1 File (java.io.File)1