Loading CheckerCorrector/Corrector.java +18 −7 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ import util.StringFileWriter; import util.StringProcessor; import Translator.*; import StateMachine.*; import SimilarityCorrector.WordPairDatabase; public class Corrector implements GUIListener { Loading @@ -27,11 +28,13 @@ public class Corrector implements GUIListener { private DirectedGraph<State> graphGUI; private int senteceIndGUI; public void start() { WordPairDatabase wordPairDatabaseGUI; if(!this.argParsGUI.isDutch()){ this.dbInterfaceGUI = new DBinterface("SQLite/token_database_english.db", "SQLite/smallDic.txt"); wordPairDatabaseGUI = WordPairDatabase.of("SQLite/word_similarity_english.db"); this.dbInterfaceGUI = new DBinterface("SQLite/token_database_english.db", "SQLite/smallDic.txt", wordPairDatabaseGUI); }else{ this.dbInterfaceGUI = new DBinterface("SQLite/token_database_dutch.db", "SQLite/DutchTranslation.txt"); wordPairDatabaseGUI = WordPairDatabase.of("SQLite/word_similarity_dutch.db"); this.dbInterfaceGUI = new DBinterface("SQLite/token_database_dutch.db", "SQLite/DutchTranslation.txt", wordPairDatabaseGUI); } this.graphGUI = new BasicGraph().getGraph(); this.stringWriterGUI = StringFileWriter.of("corrected.txt"); Loading Loading @@ -98,17 +101,25 @@ public class Corrector implements GUIListener { ArgumentParser argPars = ArgumentParser.of(args); BasicGraph basicGraphClass = new BasicGraph(); DBinterface dbInterface; WordPairDatabase wordPairDatabase; if(!argPars.isDutch()){ dbInterface = new DBinterface("SQLite/token_database_english.db", "SQLite/smallDic.txt"); wordPairDatabase = WordPairDatabase.of("SQLite/word_similarity_english.db"); dbInterface = new DBinterface("SQLite/token_database_english.db", "SQLite/smallDic.txt", wordPairDatabase); }else{ dbInterface = new DBinterface("SQLite/token_database_dutch.db", "SQLite/DutchTranslation.txt"); wordPairDatabase = WordPairDatabase.of("SQLite/word_similarity_dutch.db"); dbInterface = new DBinterface("SQLite/token_database_dutch.db", "SQLite/DutchTranslation.txt", wordPairDatabase); } DirectedGraph graph = basicGraphClass.getGraph(); StringFileWriter stringWriter = StringFileWriter.of("corrected.txt"); StringFileWriter.deleteFile("correction_details.txt"); if(argPars.isTranslateToDutch()){ if(argPars.isUpdateWordSimilarity()){ if(argPars.isCheckFile()){ wordPairDatabase.createTable(); wordPairDatabase.processSentences(argPars.getFileName()); } }else if(argPars.isTranslateToDutch()){ DirectTranslatorEnglishToDutch directTranslator = DirectTranslatorEnglishToDutch.make(); directTranslator.loadWordMapFromFile("SQLite/DutchTranslation.txt"); if(argPars.isCheckFile()){ Loading CheckerCorrector/DBinterface/DBinterface.java +44 −1 Original line number Diff line number Diff line Loading @@ -13,20 +13,28 @@ import DirectedGraph.DirectedGraph; import java.sql.*; import StateMachine.*; import TypoCorrector.FilePrefixComparator; import TypoCorrector.TypoCorrector; import util.TwoListStruct; import util.StringFileWriter; import util.StringProcessor; import GUI.SelectCorrectionHandler; import SimilarityCorrector.WordPairDatabase; public class DBinterface { String url; String dicFileName; WordPairDatabase wordPairDatabase; public DBinterface(String url, String dicFileName){ this.url = "jdbc:sqlite:./"+url; this.dicFileName = dicFileName; } public DBinterface(String url, String dicFileName, WordPairDatabase wordPairDatabase){ this.url = "jdbc:sqlite:./"+url; this.dicFileName = dicFileName; this.wordPairDatabase = wordPairDatabase; } public int checkTokenInDatabase(String sentence, DirectedGraph<State> graph){ StateMachine SM = new StateMachine(); sentence = sentence.replaceAll("\\p{Punct}", " $0"); Loading Loading @@ -185,6 +193,7 @@ public class DBinterface { //////System.out.println(); } int indDotseen = tokenList.size()+1; boolean flagStructureCorrection = true; if(flagTypoCorrectionAccepted){ List<State> actions = new ArrayList<>(); Loading Loading @@ -295,6 +304,40 @@ public class DBinterface { } } } if(flagStructureCorrection){ for(int i=0; i<tokenList.size()-1; i++){ String nextToken = tokenList.get(i+1); try (Statement statement = connection.createStatement()) { String query = "SELECT role FROM word_roles WHERE word = '" + nextToken + "';"; ResultSet resultSet = statement.executeQuery(query); if (resultSet.next()) { String roleNext = resultSet.getString("role"); if(roleNext.equals("verb")){// || roleNext.equals("noun") || roleNext.equals("adjective") || roleNext.equals("adverb")){ wordPairDatabase.bfsAndGetWords(tokenList.get(i), 2); FilePrefixComparator findSimilarity = FilePrefixComparator.of("similarity_words.txt"); String tokenCorrected = findSimilarity.findBestMatchingPrefix(nextToken); if(!nextToken.equals(tokenCorrected)){ String queryNext = "SELECT role FROM word_roles WHERE word = '" + tokenCorrected + "';"; ResultSet resultSetNext = statement.executeQuery(queryNext); if(resultSetNext.next()){ String roleNextNext = resultSet.getString("role"); if(roleNextNext.equals("verb")){ if(flagsCorrection.isEmpty()){ sfw.appendString(nextToken + " (REPLACE WITH) -> "+ tokenCorrected); tokenList.set(i+1, tokenCorrected); }else if(flagsCorrection.get(flagsCorrectioncnt)){ tokenList.set(i+1, tokenCorrected); } flagsCorrectioncnt++; } } } } } } } } } try { Loading CheckerCorrector/GUI/SelectCorrectionGUI.java +1 −1 Original line number Diff line number Diff line Loading @@ -124,7 +124,7 @@ public class SelectCorrectionGUI extends JFrame { private void updateCounter(String label){ emptyLabel = new JLabel(" "); emptyLabel.setHorizontalAlignment(SwingConstants.CENTER); noteLabel = new JLabel("Rejection of suggestion with * will result in a new set of suggestions regardless of other choices."); noteLabel = new JLabel("Rejection of suggestions with * may result in a new set of suggestions regardless of other choices."); noteLabel.setHorizontalAlignment(SwingConstants.CENTER); counterLabel = new JLabel(label); counterLabel.setHorizontalAlignment(SwingConstants.CENTER); Loading CheckerCorrector/HashTableMaker/HashTableMaker.java +3 −2 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ public class HashTableMaker { private void createTableIfNotExists() throws SQLException { try (Statement statement = connection.createStatement()) { statement.executeUpdate("CREATE TABLE IF NOT EXISTS hashes (hash TEXT PRIMARY KEY, count INTEGER)"); statement.executeUpdate("CREATE TABLE IF NOT EXISTS hashes (hash TEXT PRIMARY KEY, count INTEGER, phrase TEXT)"); } } Loading Loading @@ -53,9 +53,10 @@ public class HashTableMaker { updateStatement.setString(2, hash); updateStatement.executeUpdate(); } else { PreparedStatement insertStatement = connection.prepareStatement("INSERT INTO hashes (hash, count) VALUES (?, ?)"); PreparedStatement insertStatement = connection.prepareStatement("INSERT INTO hashes (hash, count, phrase) VALUES (?, ?, ?)"); insertStatement.setString(1, hash); insertStatement.setInt(2, 1); insertStatement.setString(3, phrase); insertStatement.executeUpdate(); } } Loading CheckerCorrector/SQLite/hash_database_dutch.db +8 KiB (104 KiB) File changed.No diff preview for this file type. View original file View changed file Loading
CheckerCorrector/Corrector.java +18 −7 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ import util.StringFileWriter; import util.StringProcessor; import Translator.*; import StateMachine.*; import SimilarityCorrector.WordPairDatabase; public class Corrector implements GUIListener { Loading @@ -27,11 +28,13 @@ public class Corrector implements GUIListener { private DirectedGraph<State> graphGUI; private int senteceIndGUI; public void start() { WordPairDatabase wordPairDatabaseGUI; if(!this.argParsGUI.isDutch()){ this.dbInterfaceGUI = new DBinterface("SQLite/token_database_english.db", "SQLite/smallDic.txt"); wordPairDatabaseGUI = WordPairDatabase.of("SQLite/word_similarity_english.db"); this.dbInterfaceGUI = new DBinterface("SQLite/token_database_english.db", "SQLite/smallDic.txt", wordPairDatabaseGUI); }else{ this.dbInterfaceGUI = new DBinterface("SQLite/token_database_dutch.db", "SQLite/DutchTranslation.txt"); wordPairDatabaseGUI = WordPairDatabase.of("SQLite/word_similarity_dutch.db"); this.dbInterfaceGUI = new DBinterface("SQLite/token_database_dutch.db", "SQLite/DutchTranslation.txt", wordPairDatabaseGUI); } this.graphGUI = new BasicGraph().getGraph(); this.stringWriterGUI = StringFileWriter.of("corrected.txt"); Loading Loading @@ -98,17 +101,25 @@ public class Corrector implements GUIListener { ArgumentParser argPars = ArgumentParser.of(args); BasicGraph basicGraphClass = new BasicGraph(); DBinterface dbInterface; WordPairDatabase wordPairDatabase; if(!argPars.isDutch()){ dbInterface = new DBinterface("SQLite/token_database_english.db", "SQLite/smallDic.txt"); wordPairDatabase = WordPairDatabase.of("SQLite/word_similarity_english.db"); dbInterface = new DBinterface("SQLite/token_database_english.db", "SQLite/smallDic.txt", wordPairDatabase); }else{ dbInterface = new DBinterface("SQLite/token_database_dutch.db", "SQLite/DutchTranslation.txt"); wordPairDatabase = WordPairDatabase.of("SQLite/word_similarity_dutch.db"); dbInterface = new DBinterface("SQLite/token_database_dutch.db", "SQLite/DutchTranslation.txt", wordPairDatabase); } DirectedGraph graph = basicGraphClass.getGraph(); StringFileWriter stringWriter = StringFileWriter.of("corrected.txt"); StringFileWriter.deleteFile("correction_details.txt"); if(argPars.isTranslateToDutch()){ if(argPars.isUpdateWordSimilarity()){ if(argPars.isCheckFile()){ wordPairDatabase.createTable(); wordPairDatabase.processSentences(argPars.getFileName()); } }else if(argPars.isTranslateToDutch()){ DirectTranslatorEnglishToDutch directTranslator = DirectTranslatorEnglishToDutch.make(); directTranslator.loadWordMapFromFile("SQLite/DutchTranslation.txt"); if(argPars.isCheckFile()){ Loading
CheckerCorrector/DBinterface/DBinterface.java +44 −1 Original line number Diff line number Diff line Loading @@ -13,20 +13,28 @@ import DirectedGraph.DirectedGraph; import java.sql.*; import StateMachine.*; import TypoCorrector.FilePrefixComparator; import TypoCorrector.TypoCorrector; import util.TwoListStruct; import util.StringFileWriter; import util.StringProcessor; import GUI.SelectCorrectionHandler; import SimilarityCorrector.WordPairDatabase; public class DBinterface { String url; String dicFileName; WordPairDatabase wordPairDatabase; public DBinterface(String url, String dicFileName){ this.url = "jdbc:sqlite:./"+url; this.dicFileName = dicFileName; } public DBinterface(String url, String dicFileName, WordPairDatabase wordPairDatabase){ this.url = "jdbc:sqlite:./"+url; this.dicFileName = dicFileName; this.wordPairDatabase = wordPairDatabase; } public int checkTokenInDatabase(String sentence, DirectedGraph<State> graph){ StateMachine SM = new StateMachine(); sentence = sentence.replaceAll("\\p{Punct}", " $0"); Loading Loading @@ -185,6 +193,7 @@ public class DBinterface { //////System.out.println(); } int indDotseen = tokenList.size()+1; boolean flagStructureCorrection = true; if(flagTypoCorrectionAccepted){ List<State> actions = new ArrayList<>(); Loading Loading @@ -295,6 +304,40 @@ public class DBinterface { } } } if(flagStructureCorrection){ for(int i=0; i<tokenList.size()-1; i++){ String nextToken = tokenList.get(i+1); try (Statement statement = connection.createStatement()) { String query = "SELECT role FROM word_roles WHERE word = '" + nextToken + "';"; ResultSet resultSet = statement.executeQuery(query); if (resultSet.next()) { String roleNext = resultSet.getString("role"); if(roleNext.equals("verb")){// || roleNext.equals("noun") || roleNext.equals("adjective") || roleNext.equals("adverb")){ wordPairDatabase.bfsAndGetWords(tokenList.get(i), 2); FilePrefixComparator findSimilarity = FilePrefixComparator.of("similarity_words.txt"); String tokenCorrected = findSimilarity.findBestMatchingPrefix(nextToken); if(!nextToken.equals(tokenCorrected)){ String queryNext = "SELECT role FROM word_roles WHERE word = '" + tokenCorrected + "';"; ResultSet resultSetNext = statement.executeQuery(queryNext); if(resultSetNext.next()){ String roleNextNext = resultSet.getString("role"); if(roleNextNext.equals("verb")){ if(flagsCorrection.isEmpty()){ sfw.appendString(nextToken + " (REPLACE WITH) -> "+ tokenCorrected); tokenList.set(i+1, tokenCorrected); }else if(flagsCorrection.get(flagsCorrectioncnt)){ tokenList.set(i+1, tokenCorrected); } flagsCorrectioncnt++; } } } } } } } } } try { Loading
CheckerCorrector/GUI/SelectCorrectionGUI.java +1 −1 Original line number Diff line number Diff line Loading @@ -124,7 +124,7 @@ public class SelectCorrectionGUI extends JFrame { private void updateCounter(String label){ emptyLabel = new JLabel(" "); emptyLabel.setHorizontalAlignment(SwingConstants.CENTER); noteLabel = new JLabel("Rejection of suggestion with * will result in a new set of suggestions regardless of other choices."); noteLabel = new JLabel("Rejection of suggestions with * may result in a new set of suggestions regardless of other choices."); noteLabel.setHorizontalAlignment(SwingConstants.CENTER); counterLabel = new JLabel(label); counterLabel.setHorizontalAlignment(SwingConstants.CENTER); Loading
CheckerCorrector/HashTableMaker/HashTableMaker.java +3 −2 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ public class HashTableMaker { private void createTableIfNotExists() throws SQLException { try (Statement statement = connection.createStatement()) { statement.executeUpdate("CREATE TABLE IF NOT EXISTS hashes (hash TEXT PRIMARY KEY, count INTEGER)"); statement.executeUpdate("CREATE TABLE IF NOT EXISTS hashes (hash TEXT PRIMARY KEY, count INTEGER, phrase TEXT)"); } } Loading Loading @@ -53,9 +53,10 @@ public class HashTableMaker { updateStatement.setString(2, hash); updateStatement.executeUpdate(); } else { PreparedStatement insertStatement = connection.prepareStatement("INSERT INTO hashes (hash, count) VALUES (?, ?)"); PreparedStatement insertStatement = connection.prepareStatement("INSERT INTO hashes (hash, count, phrase) VALUES (?, ?, ?)"); insertStatement.setString(1, hash); insertStatement.setInt(2, 1); insertStatement.setString(3, phrase); insertStatement.executeUpdate(); } } Loading
CheckerCorrector/SQLite/hash_database_dutch.db +8 KiB (104 KiB) File changed.No diff preview for this file type. View original file View changed file