// Path: src/main/java/it/uniud/ailab/dcore/io/GramPrinter.java
// public class GramPrinter implements FileWriterStage {
// 
//     @Override
//     public String getFileSuffix() {
//         return "grams";
//     }
// 
//     @Override
//     public void writeFile(String file, Blackboard b) {
//         CsvPrinter printer = new CsvPrinter();
//         printer.writeGrams(file, b);
//     }
// }
// 
// Path: src/main/java/it/uniud/ailab/dcore/io/SentencePrinter.java
// public class SentencePrinter  implements FileWriterStage {
// 
//     @Override
//     public String getFileSuffix() {
//         return "sentences";
//     }
// 
//     @Override
//     public void writeFile(String file, Blackboard b) {
//         CsvPrinter printer = new CsvPrinter();
//         printer.writeSentences(file, b);
//     }
//     
// }
// 
// Path: src/main/java/it/uniud/ailab/dcore/utils/FileSystem.java
// public class FileSystem {
// 
//     /**
//      * Get an {@link java.io.InputStreamReader} from the provided path, where
//      * the path can point both to the underlying OS' file system or to a file
//      * contained inside a JAR file.
//      *
//      * @param path the path which needs to be converted to an InputStream
//      * @return the resulting {@link java.io.InputStreamReader}
//      * @throws FileNotFoundException if the file does not exists
//      */
//     public static InputStreamReader getInputStreamReaderFromPath(String path)
//             throws FileNotFoundException {
//         InputStreamReader isr;
// 
//         // running from command-line and loading inside the JAR
//         if (path.contains("!")) {
//             isr = new InputStreamReader(
//                     (new FileSystem()).getClass().getResourceAsStream(
//                             path.substring(
//                                     path.lastIndexOf("!") + 1)));
//         } else {
//             // normal operation
//             isr = new FileReader(path);
//         }
// 
//         return isr;
//     }
// 
//     /**
//      * Get an {@link java.io.InputStream} from the provided path, where the path
//      * can point both to the underlying OS' file system or to a file contained
//      * inside a JAR file.
//      *
//      * @param path the path which needs to be converted to an InputStream
//      * @return the resulting {@link java.io.InputStream}
//      * @throws FileNotFoundException if the file does not exists
//      */
//     public static InputStream getInputStreamFromPath(String path) throws FileNotFoundException {
// 
//         InputStream is;
// 
//         // running from command-line and loading inside the JAR
//         if (path.contains("!")) {
//             is = (new FileSystem()).getClass().getResourceAsStream(
//                     path.substring(
//                             path.lastIndexOf("!") + 1));
//         } else {
//             // normal operation
//             is = new FileInputStream(path);
//         }
// 
//         return is;
//     }
// 
//     /**
//      * Get the temporary directory path of the underlying file system. On
//      * Windows, it should return the value of the %TMP% (or %TEMP%) environment
//      * variable.
//      *
//      * @return the temporary directory path.
//      * @see
//      * <a href="https://blogs.msdn.microsoft.com/oldnewthing/20150417-00/?p=44213/">
//      * Why are there both TMP and TEMP environment variables, and which one is
//      * right?</a>
//      */
//     public static String getTmpPath() {
//         return System.getProperty("java.io.tmpdir");
//     }
// 
//     /**
//      * Get the separator for the underlying OS.
//      *
//      * @return the path separator for the underlying OS.
//      */
//     public static String getSeparator() {
//         return java.io.File.separator;
//     }
// 
//     /**
//      * Creates an empty directory in the specified path. If the directory
//      * already exists, nothing is performed.
//      * 
//      * @param directoryPath the path where the new directory will be created
//      */
//     public static void createDirectoryIfNotExists(String directoryPath) {
//         File newDir = new File(directoryPath);
// 
//         // if the directory does not exist, create it
//         if (!newDir.exists()) {
//             newDir.mkdir();
//         }
//     }
//     
//     /**
//      * Get the path where the Distiller puts temporary files. NOTE: you should
//      * check if the directory exists before trying to put something inside.
//      * 
//      * @return the path of the temporary folder of the Distiller.
//      */
//     public static String getDistillerTmpPath() {
//         return getTmpPath().concat(getSeparator()).concat("distiller-tmp");
//         
//     }
// }


import it.uniud.ailab.dcore.annotation.annotators.*;
import it.uniud.ailab.dcore.io.GramPrinter;
import it.uniud.ailab.dcore.io.SentencePrinter;
import it.uniud.ailab.dcore.utils.FileSystem;
import it.uniud.ailab.dcore.wrappers.external.*;
import java.io.File;
import java.io.IOException;
import java.util.Locale;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

     *
     * @return a Distiller ready to work.
     */
    public static Distiller getDefaultXML() {
        ApplicationContext context = new ClassPathXmlApplicationContext("config.xml");
        return (Distiller) context.getBean("distiller");
    }

    /**
     * Instantiates a Distiller object using a configuration packaged in the
     * Distiller JAR file and returns it.
     *
     * @param configPath the path of the pipeline
     * @return a Distiller ready to work.
     */
    public static Distiller loadFromPackagedXML(String configPath) {
        
        ApplicationContext context = new ClassPathXmlApplicationContext(configPath);
        return (Distiller) context.getBean("distiller");
    }

    public static Distiller getDefaultCode() {
        Distiller d = new Distiller();

        // set the language detector tool
        d.setLanguageDetector(new CybozuLanguageDetectorAnnotator());

        // build the pipeline
        Pipeline p = new Pipeline();
        // split the text

// Path: src/main/java/it/uniud/ailab/dcore/io/GramPrinter.java
// public class GramPrinter implements FileWriterStage {
// 
//     @Override
//     public String getFileSuffix() {
//         return "grams";
//     }
// 
//     @Override
//     public void writeFile(String file, Blackboard b) {
//         CsvPrinter printer = new CsvPrinter();
//         printer.writeGrams(file, b);
//     }
// }
// 
// Path: src/main/java/it/uniud/ailab/dcore/io/SentencePrinter.java
// public class SentencePrinter  implements FileWriterStage {
// 
//     @Override
//     public String getFileSuffix() {
//         return "sentences";
//     }
// 
//     @Override
//     public void writeFile(String file, Blackboard b) {
//         CsvPrinter printer = new CsvPrinter();
//         printer.writeSentences(file, b);
//     }
//     
// }
// 
// Path: src/main/java/it/uniud/ailab/dcore/utils/FileSystem.java
// public class FileSystem {
// 
//     /**
//      * Get an {@link java.io.InputStreamReader} from the provided path, where
//      * the path can point both to the underlying OS' file system or to a file
//      * contained inside a JAR file.
//      *
//      * @param path the path which needs to be converted to an InputStream
//      * @return the resulting {@link java.io.InputStreamReader}
//      * @throws FileNotFoundException if the file does not exists
//      */
//     public static InputStreamReader getInputStreamReaderFromPath(String path)
//             throws FileNotFoundException {
//         InputStreamReader isr;
// 
//         // running from command-line and loading inside the JAR
//         if (path.contains("!")) {
//             isr = new InputStreamReader(
//                     (new FileSystem()).getClass().getResourceAsStream(
//                             path.substring(
//                                     path.lastIndexOf("!") + 1)));
//         } else {
//             // normal operation
//             isr = new FileReader(path);
//         }
// 
//         return isr;
//     }
// 
//     /**
//      * Get an {@link java.io.InputStream} from the provided path, where the path
//      * can point both to the underlying OS' file system or to a file contained
//      * inside a JAR file.
//      *
//      * @param path the path which needs to be converted to an InputStream
//      * @return the resulting {@link java.io.InputStream}
//      * @throws FileNotFoundException if the file does not exists
//      */
//     public static InputStream getInputStreamFromPath(String path) throws FileNotFoundException {
// 
//         InputStream is;
// 
//         // running from command-line and loading inside the JAR
//         if (path.contains("!")) {
//             is = (new FileSystem()).getClass().getResourceAsStream(
//                     path.substring(
//                             path.lastIndexOf("!") + 1));
//         } else {
//             // normal operation
//             is = new FileInputStream(path);
//         }
// 
//         return is;
//     }
// 
//     /**
//      * Get the temporary directory path of the underlying file system. On
//      * Windows, it should return the value of the %TMP% (or %TEMP%) environment
//      * variable.
//      *
//      * @return the temporary directory path.
//      * @see
//      * <a href="https://blogs.msdn.microsoft.com/oldnewthing/20150417-00/?p=44213/">
//      * Why are there both TMP and TEMP environment variables, and which one is
//      * right?</a>
//      */
//     public static String getTmpPath() {
//         return System.getProperty("java.io.tmpdir");
//     }
// 
//     /**
//      * Get the separator for the underlying OS.
//      *
//      * @return the path separator for the underlying OS.
//      */
//     public static String getSeparator() {
//         return java.io.File.separator;
//     }
// 
//     /**
//      * Creates an empty directory in the specified path. If the directory
//      * already exists, nothing is performed.
//      * 
//      * @param directoryPath the path where the new directory will be created
//      */
//     public static void createDirectoryIfNotExists(String directoryPath) {
//         File newDir = new File(directoryPath);
// 
//         // if the directory does not exist, create it
//         if (!newDir.exists()) {
//             newDir.mkdir();
//         }
//     }
//     
//     /**
//      * Get the path where the Distiller puts temporary files. NOTE: you should
//      * check if the directory exists before trying to put something inside.
//      * 
//      * @return the path of the temporary folder of the Distiller.
//      */
//     public static String getDistillerTmpPath() {
//         return getTmpPath().concat(getSeparator()).concat("distiller-tmp");
//         
//     }
// }


// Path: src/main/java/it/uniud/ailab/dcore/DistillerFactory.java
import it.uniud.ailab.dcore.annotation.annotators.*;
import it.uniud.ailab.dcore.io.GramPrinter;
import it.uniud.ailab.dcore.io.SentencePrinter;
import it.uniud.ailab.dcore.utils.FileSystem;
import it.uniud.ailab.dcore.wrappers.external.*;
import java.io.File;
import java.io.IOException;
import java.util.Locale;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

     *
     * @return a Distiller ready to work.
     */
    public static Distiller getDefaultXML() {
        ApplicationContext context = new ClassPathXmlApplicationContext("config.xml");
        return (Distiller) context.getBean("distiller");
    }

    /**
     * Instantiates a Distiller object using a configuration packaged in the
     * Distiller JAR file and returns it.
     *
     * @param configPath the path of the pipeline
     * @return a Distiller ready to work.
     */
    public static Distiller loadFromPackagedXML(String configPath) {
        
        ApplicationContext context = new ClassPathXmlApplicationContext(configPath);
        return (Distiller) context.getBean("distiller");
    }

    public static Distiller getDefaultCode() {
        Distiller d = new Distiller();

        // set the language detector tool
        d.setLanguageDetector(new CybozuLanguageDetectorAnnotator());

        // build the pipeline
        Pipeline p = new Pipeline();
        // split the text

        p.addStage(new OpenNlpBootstrapperAnnotator());
