Commit 7058b39c authored by Manuel  Segimon's avatar Manuel Segimon
Browse files

Merge branch '25-full-language-name-in-the-selection' into 'master'

Resolve "Full Language Name in the selection"

Closes #25

See merge request ec504/ec504_projects/group7!18
parents 8ace970f 15ed2a40
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -30,12 +30,12 @@ CLI Execution Instructions
  - Move into the project directory.
  - Run `chmod +x *.sh` if you have not done so already.
  - Run the modules separately using the following bash scripts:
    - `./crawlerCLI.sh $arguments`
    - `./crawlerCLI.sh --LF [metadataFile] $arguments`, builds or adds to the metadataFile.
      - `--file crawler_test_file.txt`, the file contains a list of links and the crawler will add content from these links to the trie.
      - `--build [en, gr, it, or gr]`, this will build the trie based on the text corpus for each language.
      - `--social [subreddit name]`, this will add content from a reddit post to the trie.
    - `./checkerCLI.sh --file checker_test_file.txt`
    - `./correctorCLI.sh --file checker_test_file.txt`
      - `--build [English, German, Italian, or Portuguese]`, this will build the trie based on the text corpus for each language.
      - `--social [subreddit name]`, this will add content from a subreddit to the trie.
    - `./checkerCLI.sh --LF [metadataFile] --file checker_test_file.txt`, build the metadataFile using the crawler module.
    - `./correctorCLI.sh --LF [metadataFile] --file checker_test_file.txt`, build the metadataFile using the crawler module.

Visual GUI Execution Instructions
  - Open a terminal.
+8 −0
Original line number Diff line number Diff line
@@ -236,6 +236,14 @@ Added executables to the project so that reviewers can easily run the program an

Implemented corrector feedback system in GUI, which allows the user to select the best correction from a list of suggestions

Implement no correction needed message in GUI for both corrector and checker

Implemented find closest word for words not in the TrieNode, when running the corrector

Added the metadata input functionality to all the modules

Implemented change language feature in GUI, which allows the user to switch between languages

### Tejas Singh
Worked on base functionality of crawler: implemented Jsoup, basic data structures (such as the URL queue), and CLI (for use with files).

+6 −5
Original line number Diff line number Diff line
@@ -11,10 +11,10 @@ import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;

public class Checker {
    public void analyze(String text) {
    public void analyze(String text, String metadataPath) {
        List<String> sentences = TextProcessor.extractSentences(text);

        TrieNode detector = loadFile("metadata.ser");
        TrieNode detector = loadFile(metadataPath);

        Map<String, Float> sentenceScores = new HashMap<>();
        Map<String, Float> phraseScores = new HashMap<>();
@@ -97,14 +97,15 @@ public class Checker {
    }

    public static void main(String[] args) {
        if (args.length > 1 && "--file".equals(args[0])) { // check syntax
            String path = args[1];
        if (args.length > 3 && "--LF".equals(args[0]) && "--file".equals(args[2])) { // check syntax
            String metadataPath = args[1];
            String path = args[3];
            try {
                // Read entire file
                String content = new String(Files.readAllBytes(Paths.get(path)));

                Checker checker = new Checker(); // Run checker
                checker.analyze(content);
                checker.analyze(content, metadataPath);
            } catch (IOException e) {
                System.err.println("Error reading file: " + e.getMessage());
            }
+6 −5
Original line number Diff line number Diff line
@@ -17,8 +17,8 @@ import java.util.HashMap;
public class Corrector {
    private TrieNode detector;

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

    public TrieNode getDetector() {
@@ -209,11 +209,12 @@ public class Corrector {
    }

    public static void main(String[] args) {
        if (args.length > 1 && "--file".equals(args[0])) {
            String path = args[1];
        if (args.length > 3 && "--LF".equals(args[0]) && "--file".equals(args[2])) {
            String metadataPath = args[1];
            String path = args[3];
            try {
                String content = new String(Files.readAllBytes(Paths.get(path)));
                Corrector corrector = new Corrector(); // Run corrector
                Corrector corrector = new Corrector(metadataPath); // Run corrector
                String[] sentences = TextProcessor.extractSentences(content).toArray(new String[0]);
                for (String sentence : sentences) {
                    sentence = sentence.replaceAll("[^a-zA-Z0-9\\s]", "");
+31 −6
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ import java.awt.*;
// import java.awt.event.ActionEvent;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.StringBufferInputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
@@ -33,8 +34,11 @@ public class MainApp extends JFrame {
    private JTextArea resultArea;
    private Highlighter.HighlightPainter myHighlightPainter;
    private final JButton runButton;
    private final JButton changeLanguageButton;
    private final JComboBox<String> moduleSelector;

    private String languageFile = "English.ser";

    public MainApp() {
        super("Language Correction Tool");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@@ -43,11 +47,12 @@ public class MainApp extends JFrame {
        setLayout(new BorderLayout());

        // Check if metadata file exists
        if (!Files.exists(Paths.get("metadata.ser"))) {
            String[] languages = {"en", "gr", "pt", "it"};
        if (!Files.exists(Paths.get(languageFile))) {
            String[] languages = {"English", "German", "Portuguese", "Italian"};
            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();
                languageFile = selectedLanguage + ".ser";
                crawler webCrawler = new crawler(languageFile);
                webCrawler.build(selectedLanguage);
            }
        }
@@ -86,10 +91,30 @@ public class MainApp extends JFrame {
                    JOptionPane.showMessageDialog(this, "Select a valid module");
            }
        });
        changeLanguageButton = new JButton("Change Language");
        changeLanguageButton.addActionListener(e -> {
            String[] languages = {"English", "German", "Portuguese", "Italian"};
            String selectedLanguage = (String) JOptionPane.showInputDialog(this, "Please choose a language to build off of.", "Language Selection", JOptionPane.PLAIN_MESSAGE, null, languages, languages[0]);
            if (selectedLanguage != null) {
                languageFile = selectedLanguage + ".ser";

                // Check if metadata file exists
                String extraText = "";
                if (!Files.exists(Paths.get(languageFile))) {
                    crawler webCrawler = new crawler(languageFile);
                    webCrawler.build(selectedLanguage);
                    extraText = "New metadata file created.\n";
                }

                JOptionPane.showMessageDialog(this, extraText + "Language changed to " + selectedLanguage + ".");
            }
        });

        JPanel northPanel = new JPanel(new BorderLayout());
        northPanel.add(moduleSelector, BorderLayout.WEST);
        northPanel.add(urlField, BorderLayout.CENTER);
        northPanel.add(runButton, BorderLayout.EAST);
        northPanel.add(changeLanguageButton, BorderLayout.NORTH);

        // Result area
        resultArea = new JTextArea();
@@ -102,7 +127,7 @@ public class MainApp extends JFrame {

    private void runCrawler(String input) {
        StringBuilder outputBuilder = new StringBuilder();
        crawler webCrawler = new crawler(output -> {
        crawler webCrawler = new crawler(languageFile, output -> {
            outputBuilder.append(output);
            SwingUtilities.invokeLater(() -> resultArea.setText(outputBuilder.toString()));
        });
@@ -150,7 +175,7 @@ public class MainApp extends JFrame {

            for (String sentence : sentences) {
                System.setOut(printStream);
                checker.analyze(sentence); // Analyze each sentence separately
                checker.analyze(sentence, languageFile); // Analyze each sentence separately

                // Reset System.out
                System.out.flush();
@@ -270,7 +295,7 @@ public class MainApp extends JFrame {
                content= new String(Files.readAllBytes(Paths.get(input)));
            else
                content = input;
            Corrector corrector = new Corrector();
            Corrector corrector = new Corrector(languageFile);
            String[] sentences = TextProcessor.extractSentences(content).toArray(new String[0]);

            StringBuilder result = new StringBuilder();
Loading