Commit 24f6a4e4 authored by Seyed Reza  Sajjadinasab's avatar Seyed Reza Sajjadinasab
Browse files

fixCorrectorBug

parent cd22b153
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -188,7 +188,7 @@ public class Corrector implements GUIListener {
            }
        }else if(argPars.isCheckSentence()){
            if(argPars.isCorrectionGUI()){  
                Corrector corrector = new Corrector(SentenceExtractor.of(StringProcessor.handleApostrophe(argPars.getSentence().toLowerCase())), argPars);  
                Corrector corrector = new Corrector(SentenceExtractor.ofLine(StringProcessor.handleApostrophe(argPars.getSentence().toLowerCase())), argPars);  
                corrector.start();
            }else{
                System.out.println("Sentence: " + argPars.getSentence());
+8 −7
Original line number Diff line number Diff line
@@ -152,7 +152,7 @@ public class DBinterface {
                                
                                initialConf += 5;
                                if(flagsCorrection.isEmpty()){
                                    sfw.appendString(token + " -> "+ tokenCorrected + "*");
                                    sfw.appendString(token + " (REPLACE WITH) -> "+ tokenCorrected + " | TYPO CORRECTION*");
                                }else if(!flagsCorrection.get(flagsCorrectioncnt) && isNotGUI){
                                    flagTypoCorrectionAccepted = false;
                                    //tokenList.set(i, "nan");
@@ -203,7 +203,8 @@ public class DBinterface {
                int biasToken = 0;
                
                //if(!isNotGUI)
                // System.out.println(flagsCorrection);
                //System.out.println(flags);
                //System.out.println(suggested);
                for(int i=0; i<suggested.size(); i++){
                    if(seenDot){
                        //indDotseen = i;
@@ -224,8 +225,8 @@ public class DBinterface {
                                if(i+biasToken<tokenList.size()){
                                    
                                    if(flagsCorrection.isEmpty()){
                                        sfw.appendString(tokenList.get(i) + " (REPLACE WITH) -> "+ word);
                                        tokenList.set(i+biasToken,word);
                                        sfw.appendString(tokenList.get(i) + " -> "+ word);
                                    }else if(flagsCorrection.get(flagsCorrectioncnt)){
                                        
                                        tokenList.set(i+biasToken,word);
@@ -234,7 +235,7 @@ public class DBinterface {
                                    
                                }else{
                                    if(flagsCorrection.isEmpty()){
                                        sfw.appendString("IND: "+ i + " -> "+ word);
                                        sfw.appendString("(INSERTION INTO INDEX): "+ i + " -> "+ word);
                                        tokenList.add(word);
                                    }else if(flagsCorrection.get(flagsCorrectioncnt)){
                                        tokenList.add(word);
@@ -247,7 +248,7 @@ public class DBinterface {
                    }else if(flags.get(i+delCnt)==2){
                        delCnt++;
                        if(flagsCorrection.isEmpty()){
                            sfw.appendString(tokenList.get(i) + " -> X");
                            sfw.appendString(tokenList.get(i) + "-> (REMOVE)");
                            tokenList.remove(i+biasToken);
                        }else if(flagsCorrection.get(flagsCorrectioncnt)){
                            tokenList.remove(i+biasToken);
@@ -267,7 +268,7 @@ public class DBinterface {
                                ////System.out.println("Here I am: "+ word);
                                
                                if(flagsCorrection.isEmpty()){
                                    sfw.appendString("IND: "+ i + " -> "+ word);
                                    sfw.appendString("(INSERTION INTO THE END) -> "+ word);
                                    if(i<tokenList.size()){
                                        tokenList.add(i+biasToken,word);
                                    }else{
+4 −4
Original line number Diff line number Diff line
@@ -168,11 +168,11 @@ public class BasicGraph {
        graph.addEdge(State.ADVERB,      State.VERB);
        edgeList.put(State.ADVERB.toString(), State.VERB.toString());

        graph.addEdge(State.NOUN,      State.NOUN);
        edgeList.put(State.NOUN.toString(), State.NOUN.toString());
        //graph.addEdge(State.NOUN,      State.NOUN);
        //edgeList.put(State.NOUN.toString(), State.NOUN.toString());

        graph.addEdge(State.ADJECTIVE,      State.ADJECTIVE);
        edgeList.put(State.ADJECTIVE.toString(), State.ADJECTIVE.toString());
        //graph.addEdge(State.ADJECTIVE,      State.ADJECTIVE);
        //edgeList.put(State.ADJECTIVE.toString(), State.ADJECTIVE.toString());
    }
    public DirectedGraph<State> getGraph() {
        return graph;
+2 −4
Original line number Diff line number Diff line
@@ -52,8 +52,6 @@ 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();
@@ -68,7 +66,7 @@ public class StateMachine{
                    for(State action: actions)
                        lts.addString(action);
                    String suggestedActionsString = tc.closestWord(lts.getString());
                    ////System.out.println(lts.getString() + " -> " + suggestedActionsString);
                    //System.out.println(lts.getString() + " -> " + suggestedActionsString);
                    List<State> parts = StringToList.split(suggestedActionsString);
                    suggestedAction.addAll(parts);
                    flags.addAll(tc.traceBack());
+18 −1
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ public class SentenceExtractor {
    }

    public static SentenceExtractor of(String filePath) {
        System.out.println(filePath);
        //System.out.println(filePath);
        List<String> sentences = new ArrayList<>();
        try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
            StringBuilder sb = new StringBuilder();
@@ -38,6 +38,23 @@ public class SentenceExtractor {
        return new SentenceExtractor(sentences);
    }

    public static SentenceExtractor ofLine(String line) {
        //System.out.println(filePath);
        List<String> sentences = new ArrayList<>();
        StringBuilder sb = new StringBuilder();
        String[] parts = line.split("\\.");
        for (String part : parts) {
                    // Append the part to the StringBuilder
            sb.append(part).append(".");
                    // If the StringBuilder contains a complete sentence, add it to the list
            if (sb.length() > 0 && sb.charAt(sb.length() - 1) == '.') {
                sentences.add(sb.toString().trim());
                sb.setLength(0);
            }
        }
        return new SentenceExtractor(sentences);
    }

    public List<String> getSentences() {
        return sentences;
    }
Loading