Commit c4fd30e0 authored by Manuel  Segimon's avatar Manuel Segimon
Browse files

Add pop-up for selecting the best correction for each sentence

parent cd776704
Loading
Loading
Loading
Loading
+35 −1
Original line number Diff line number Diff line
@@ -249,8 +249,10 @@ public class MainApp extends JFrame {
        List<Map.Entry<String, Integer>> sortedList = new ArrayList<>(changesMap.entrySet());
        sortedList.sort(Map.Entry.comparingByValue());

        int i = 1;
        for (Map.Entry<String, Integer> entry : sortedList) {
            result.append("    " + entry.getKey() + " | Changes: " + entry.getValue() + "\n");
            result.append("    " + i + ") " + entry.getKey() + " | Changes: " + entry.getValue() + "\n");
            i++;
        }
    }

@@ -273,6 +275,38 @@ public class MainApp extends JFrame {
            }

            resultArea.setText(result.toString());

            // Add a pop up to input the best correction for each sentence
            for (String sentence : sentences) {
                String sentenceNew = sentence.replaceAll("[^a-zA-Z0-9\\s]", "");
                String[] corrected = corrector.correct(sentenceNew);
                int correctedLength = corrected.length;
                for (String s : corrected) {
                    if (s == null || s.isEmpty()) {
                        correctedLength--;
                    }
                }
                //System.out.println(correctedLength);
                String[] options = new String[correctedLength + 1];
                options[0] = sentence;
                for (int i = 0; i < corrected.length; i++) {
                    //System.out.println(corrected[i]);
                    if (corrected[i] == null || corrected[i].isEmpty()) {
                        continue;
                    }

                    options[i + 1] = corrected[i];
                    //System.out.println(options[i]);
                    options[i + 1] = options[i + 1].split(" \\| Score: ")[0];
                    //System.out.println(options[i]);
                }
                String selected = (String) JOptionPane.showInputDialog(this, "Select the best correction for the following sentence:\n  " + sentence, "Correction Selection", JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
                if (selected != null) {
                    resultArea.setText(resultArea.getText().replace(sentence, selected));
                } else {
                    System.out.println("No correction selected");
                }
            }
        } catch (Exception e) {
            resultArea.setText("Error: " + e.getMessage());
        }