Commit cd22b153 authored by Seyed Reza  Sajjadinasab's avatar Seyed Reza Sajjadinasab
Browse files

fixCorrectorStuck

parent d8905749
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ public class HighlighterGUI extends JFrame {
        mainPanel.setPreferredSize(new Dimension(POPUP_WIDTH, POPUP_HEIGHT));

        this.isDutch = isDutch;
        setTitle("Text Highlighter");
        setTitle("Text Checker Highlighter");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(new BorderLayout());

+76 −20
Original line number Diff line number Diff line
@@ -52,6 +52,9 @@ public class StateMachine{
                flags.add(0);
            return TwoListStruct.of(actions, flags);
        }else{
            
            
            if(actions.size()<13){
                Set<String> allPaths = new HashSet<>();
                DFS dfs = DFS.of();
                allPaths.addAll(dfs.dfs(graph, actions.get(0), State.DOT, actions.size()+1, 4));
@@ -73,6 +76,59 @@ public class StateMachine{
                } catch (IOException e) {
                    System.err.println("An error occurred while writing to the file: " + e.getMessage());
                }
            }else{
                List<State> actions1 = new ArrayList<>();
                List<State> actions2 = new ArrayList<>();
                for (int i = 0; i < actions.size(); i++) {
                    if (i < actions.size()/2) {
                        actions1.add(actions.get(i));
                    } else {
                        actions2.add(actions.get(i));
                    }
                }
                Set<String> allPaths1 = new HashSet<>();
                DFS dfs1 = DFS.of();
                allPaths1.addAll(dfs1.dfs(graph, actions1.get(0), actions1.get(actions1.size()-1), actions1.size()+1, 4));
                StringFileWriter sfw1 = StringFileWriter.of("all_path.txt", "\n");
                for(String path: allPaths1)
                    sfw1.appendString(path);
                try {
                    sfw1.writeToFile();
                    TypoCorrector tc = TypoCorrector.of("all_path.txt", true, -6, 0, -3, -1);
                    ListToString lts = ListToString.of();
                    for(State action: actions1)
                        lts.addString(action);
                    String suggestedActionsString = tc.closestWord(lts.getString());
                    ////System.out.println(lts.getString() + " -> " + suggestedActionsString);
                    List<State> parts = StringToList.split(suggestedActionsString);
                    suggestedAction.addAll(parts);
                    flags.addAll(tc.traceBack());
                    //return TwoListStruct.of(suggestedAction, flags);
                } catch (IOException e) {
                    System.err.println("An error occurred while writing to the file: " + e.getMessage());
                }
                Set<String> allPaths2 = new HashSet<>();
                DFS dfs2 = DFS.of();
                allPaths2.addAll(dfs2.dfs(graph, actions2.get(0), actions2.get(actions2.size()-1), actions2.size()+1, 4));
                StringFileWriter sfw2 = StringFileWriter.of("all_path.txt", "\n");
                for(String path: allPaths2)
                    sfw2.appendString(path);
                try {
                    sfw2.writeToFile();
                    TypoCorrector tc = TypoCorrector.of("all_path.txt", true, -6, 0, -3, -1);
                    ListToString lts = ListToString.of();
                    for(State action: actions2)
                        lts.addString(action);
                    String suggestedActionsString = tc.closestWord(lts.getString());
                    ////System.out.println(lts.getString() + " -> " + suggestedActionsString);
                    List<State> parts = StringToList.split(suggestedActionsString);
                    suggestedAction.addAll(parts);
                    flags.addAll(tc.traceBack());
                    return TwoListStruct.of(suggestedAction, flags);
                } catch (IOException e) {
                    System.err.println("An error occurred while writing to the file: " + e.getMessage());
                }
            }

        }
        return TwoListStruct.of(suggestedAction, flags);
+6 −4
Original line number Diff line number Diff line
@@ -133,18 +133,20 @@ public class TypoCorrector {
            if(m>0){
                int n = dirMat[0].length;
                trace.addAll(traceBackRecursion(dirMat, trace, m-1, n-1));
                String[] closestWordList = closestWordString.split("\\.");
                //String[] closestWordList = closestWordString.split("\\.");
                String[] closestWordList = closestWordString.split("(?<=.)");
                List<Integer> traceInverse = new ArrayList<>();
                int traceCnt = 0;
                boolean flagDotSeen = false;
                int tempTrace = 0;
                for(int i=trace.size()-1; i>=0; i-=2){

                //for(int i=trace.size()-1; i>=0; i-=2){
                for(int i=trace.size()-1; i>=0; i-=1){
                    traceInverse.add(trace.get(i));
                }
                return traceInverse;
            }else{
                for(int i=closestWordString.length()-1; i>=0; i-=2){
                //for(int i=closestWordString.length()-1; i>=0; i-=2){
                for(int i=closestWordString.length()-1; i>=0; i-=1){
                    trace.add(0);
                }
                return trace;
+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ public class ListToString {
    }
    public void addString(State s){
        finalString.append(State.mapToChar(s));//.toString().substring(0,3));
        finalString.append(".");
       // finalString.append(".");
    }
    public String getString(){
        return finalString.toString();
+4 −3
Original line number Diff line number Diff line
@@ -57,13 +57,14 @@ public class StringFileWriter {
        File file = new File(fileName);
        if (file.exists()) {
            boolean deleted = file.delete();
            /* 
            if (deleted) {
                System.out.println("File '" + fileName + "' has been deleted successfully.");
            } else {
                System.out.println("Failed to delete the file '" + fileName + "'.");
            }
        } else {
            }*/
        } /*else {
            System.out.println("File '" + fileName + "' does not exist.");
        }
        }*/
    }
}
Loading