Commit e71c097c authored by Moises Bensadon's avatar Moises Bensadon
Browse files

added language build dialog box to choose corpus

parent 566b6762
Loading
Loading
Loading
Loading
+20 −17
Original line number Diff line number Diff line
@@ -25,13 +25,11 @@ public class MainApp extends JFrame {
        // Check if metadata file exists
        if (!Files.exists(Paths.get("metadata.ser"))) {
            String[] languages = {"en", "es", "pt", "it"};
            String selectedLanguage = (String) JOptionPane.showInputDialog(this, "Metadata file not found. Please choose a language to build off of.", "Language Selection", JOptionPane.PLAIN_MESSAGE, null, languages, languages[0]);
            if (selectedLanguage == null) {
                System.exit(0);
            }
            String selectedLanguage = (String) JOptionPane.showInputDialog(this, "Metadata file not found. Please choose a language to build off of. \n(If you want to build from scratch just click Cancel)", "Language Selection", JOptionPane.PLAIN_MESSAGE, null, languages, languages[0]);
            if (selectedLanguage != null) {
                crawler webCrawler = new crawler();
                webCrawler.build(selectedLanguage);

            }
        }

        // Module selector
@@ -109,26 +107,31 @@ public class MainApp extends JFrame {
        crawlerThread.start();
    }

    private void runChecker(String filePath) {
    private void runChecker(String text, boolean isFile) {
        try {
            String content = new String(Files.readAllBytes(Paths.get(filePath)));
            String content;
            if (isFile) {
                content = new String(Files.readAllBytes(Paths.get(text)));
            } else 
                content = text;
            Checker checker = new Checker();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            PrintStream ps = new PrintStream(baos);
            PrintStream old = System.out;
            System.setOut(ps);
            checker.analyze(content);
            System.out.flush();
            System.setOut(old);
            resultArea.setText(baos.toString());

            // Redirect output to the GUI
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            
        } catch (Exception e) {
            resultArea.setText("Error: " + e.getMessage());
        }
    }

    private void runCorrector(String filePath) {
    private void runCorrector(String input, boolean isFile) {
        try {
            String content = new String(Files.readAllBytes(Paths.get(filePath)));
            String content;
            if (isFile) 
                content= new String(Files.readAllBytes(Paths.get(input)));
            else
                content = input;
            Corrector corrector = new Corrector();
            String corrected = corrector.correct(content);
            resultArea.setText("Corrected Text:\n" + corrected);