Commit 2bf2c37d authored by Manuel  Segimon's avatar Manuel Segimon
Browse files

Add logic to write metadata.ser file only if a correction is selected

parent 37d7ef02
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -281,6 +281,7 @@ public class MainApp extends JFrame {

            // Add a pop up to input the best correction for each sentence
            TrieNode node = corrector.getDetector();
            boolean changeMade = false;
            for (String sentence : sentences) {
                String sentenceNew = sentence.replaceAll("[^a-zA-Z0-9\\s]", "");
                String[] corrected = corrector.correct(sentenceNew);
@@ -312,16 +313,18 @@ public class MainApp extends JFrame {
                        String[] words = phrase.split(" ");
                        node.insert(words);
                    }
                    changeMade = true;
                } else {
                    System.out.println("No correction selected");
                }
            }

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

            }
        } catch (Exception e) {
            resultArea.setText("Error: " + e.getMessage());
        }
+1 −1
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ public class TrieNode implements Serializable, Cloneable {
            logProb += Math.log((probability(currentPhrase)));
        }
        float perplexity = (float) Math.pow(2, -logProb);
        //System.out.println("Perplexity of phrase (" + phrase + ") : " + perplexity);
        System.out.println("Perplexity of phrase (" + phrase + ") : " + perplexity);
        return perplexity;
    }