Commit 96e3f457 authored by Manuel  Segimon's avatar Manuel Segimon
Browse files

Refactor Corrector class to use private access modifier for detector field

parent 9c169b68
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -15,12 +15,16 @@ import java.util.HashMap;


public class Corrector {
    public TrieNode detector;
    private TrieNode detector;

    public Corrector() {
        detector = loadFile("metadata.ser");
    }

    public TrieNode getDetector() {
        return detector;
    }

    private TrieNode loadFile(String filePath) {
        TrieNode trie = new TrieNode();
        try (FileInputStream fis = new FileInputStream(filePath)) {
+2 −2
Original line number Diff line number Diff line
@@ -280,6 +280,7 @@ public class MainApp extends JFrame {
            resultArea.setText(result.toString());

            // Add a pop up to input the best correction for each sentence
            TrieNode node = corrector.getDetector();
            for (String sentence : sentences) {
                String sentenceNew = sentence.replaceAll("[^a-zA-Z0-9\\s]", "");
                String[] corrected = corrector.correct(sentenceNew);
@@ -306,7 +307,6 @@ public class MainApp extends JFrame {
                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) {
                    // Insert the selected correction into the trie for future reference
                    TrieNode node = corrector.detector;
                    List<String> phrases = TextProcessor.extractPhrases(selected, 2, 3);
                    for (String phrase : phrases) {
                        String[] words = phrase.split(" ");
@@ -318,7 +318,7 @@ public class MainApp extends JFrame {
            }

            // Serialize the trie
            byte[] serialized = corrector.detector.serialize();
            byte[] serialized = node.serialize();
            byte[] compressed = compress(serialized);
            writeToFile(compressed, "metadata.ser");