Loading .gitignore +1 −0 Original line number Diff line number Diff line Loading @@ -11,5 +11,6 @@ Crawler/target/classes/ScratchCrawler.class Crawler/target/classes/crawledData.txt *.db *.java *.class !CheckerCorrector/manifest* !CheckerCorrector/**/*.java CheckerCorrector/DBinterface/DBinterface.java +1 −1 Original line number Diff line number Diff line Loading @@ -85,7 +85,7 @@ public class DBinterface { int confidence = SM.isStateMachineFollowed(graph, actions, initialState, initialConf); //System.out.print("The confidence score is: "+ confidence + "\n"); return confidence; return ((int)((double)confidence*100.0/(actions.size()*15))); } catch (SQLException e) { e.printStackTrace(); } Loading CheckerCorrector/GUI/ColorSpectrumPanel.java 0 → 100644 +34 −0 Original line number Diff line number Diff line package GUI; import javax.swing.*; import java.awt.*; public class ColorSpectrumPanel extends JPanel { private int width; private int height; public ColorSpectrumPanel(int width, int height) { this.width = width; this.height = height; setPreferredSize(new Dimension(width, height)); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; // Draw color spectrum for (int i = 0; i < width; i++) { float saturation = (float) i / (float) width; Color color = Color.getHSBColor(0, saturation, 1); g2d.setColor(color); g2d.drawLine(i, 0, i, height); } // Add labels g2d.setColor(Color.BLACK); g2d.drawString("Confidence=0", 5, height - 5); g2d.drawString("Confidence=100 ", width - 110, height - 5); } } CheckerCorrector/GUI/HighlighterGUI.java +51 −15 Original line number Diff line number Diff line Loading @@ -5,7 +5,9 @@ import javax.swing.text.DefaultHighlighter; import DBinterface.DBinterface; import DirectedGraph.BasicGraph; import HashTableMaker.HashTableMaker; import java.sql.SQLException; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; Loading @@ -15,9 +17,16 @@ import java.util.Random; public class HighlighterGUI extends JFrame { private JTextArea textArea; private JPanel mainPanel; private JButton highlightButton; public boolean isDutch; private static final int POPUP_WIDTH = 800; private static final int POPUP_HEIGHT = 300; public HighlighterGUI(boolean isDutch) { mainPanel = new JPanel(new BorderLayout()); mainPanel.setPreferredSize(new Dimension(POPUP_WIDTH, POPUP_HEIGHT)); this.isDutch = isDutch; setTitle("Text Highlighter"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Loading @@ -35,8 +44,24 @@ public class HighlighterGUI extends JFrame { JPanel buttonPanel = new JPanel(); buttonPanel.add(highlightButton); add(new JScrollPane(textArea), BorderLayout.CENTER); add(buttonPanel, BorderLayout.SOUTH); JFrame frame = new JFrame("Color Spectrum Panel"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); int panelWidth = POPUP_WIDTH; int panelHeight = POPUP_HEIGHT/10; ColorSpectrumPanel colorSpectrumPanel = new ColorSpectrumPanel(panelWidth, panelHeight); mainPanel.add(new JScrollPane(textArea), BorderLayout.NORTH); mainPanel.add(colorSpectrumPanel, BorderLayout.CENTER); mainPanel.add(buttonPanel, BorderLayout.SOUTH); add(mainPanel); //add(, BorderLayout.CENTER); //add(buttonPanel, BorderLayout.SOUTH); pack(); setLocationRelativeTo(null); Loading @@ -52,7 +77,7 @@ public class HighlighterGUI extends JFrame { private List<String> extractPhrases(String text, int phraseLength) { List<String> phrases = new ArrayList<>(); String[] words = text.split("\\s+"); for (int i = 0; i <= words.length - phraseLength; i+=phraseLength) { for (int i = 0; i <= words.length - phraseLength; i+=1) { StringBuilder phraseBuilder = new StringBuilder(); for (int j = 0; j < phraseLength; j++) { phraseBuilder.append(words[i + j]); Loading @@ -66,21 +91,32 @@ public class HighlighterGUI extends JFrame { } private void highlightPhrases(List<String> phrases) { try{ DBinterface dbInterface; HashTableMaker manager; if(!this.isDutch){ dbInterface = new DBinterface("SQLite/token_database_english.db", "SQLite/smallDic.txt"); manager = new HashTableMaker("SQLite/hash_database_english.db"); }else{ dbInterface = new DBinterface("SQLite/token_database_dutch.db", "SQLite/DutchTranslation.txt"); manager = new HashTableMaker("SQLite/hash_database_dutch.db"); } BasicGraph basicGraphClass = new BasicGraph(); for (String phrase : phrases) { highlightPhrase(phrase, dbInterface.checkTokenInDatabase(phrase, basicGraphClass.getGraph())); double conf = dbInterface.checkTokenInDatabase(phrase, basicGraphClass.getGraph())*0.8; conf += manager.nGram(phrase, 3)*0.2; //System.out.println(phrase + "| "+ conf); highlightPhrase(phrase, (int)conf); } } catch (SQLException e) { e.printStackTrace(); } } private Color getColorForNumber(int number) { float hue = (float) number / 100; // Hue ranges from 0 to 1 return Color.getHSBColor(hue, 1, 1); float hue = ((float) number / 100); // Hue ranges from 0 to 1 //System.out.println(hue); return Color.getHSBColor(0, hue, 1); } private void highlightPhrase(String phrase, int colorInd) { Loading Crawler/target/classes/Makefile 0 → 100644 +20 −0 Original line number Diff line number Diff line JAVAC=javac JFLAGS=-Xlint:none -Xlint:-deprecation LIBS=tika-app-2.9.2.jar default: ScratchCrawler.class Debug.class RobotsTXT.class RegexParser.class ScratchCrawler.class: ScratchCrawler.java $(JAVAC) $(JFLAGS) -cp $(LIBS) ScratchCrawler.java Debug.class: Debug.java $(JAVAC) $(JFLAGS) -cp $(LIBS) Debug.java RobotsTXT.class: RobotsTXT.java $(JAVAC) $(JFLAGS) -cp $(LIBS) RobotsTXT.java RegexParser.class: RegexParser.java $(JAVAC) $(JFLAGS) -cp $(LIBS) RegexParser.java clean: del *.class Loading
.gitignore +1 −0 Original line number Diff line number Diff line Loading @@ -11,5 +11,6 @@ Crawler/target/classes/ScratchCrawler.class Crawler/target/classes/crawledData.txt *.db *.java *.class !CheckerCorrector/manifest* !CheckerCorrector/**/*.java
CheckerCorrector/DBinterface/DBinterface.java +1 −1 Original line number Diff line number Diff line Loading @@ -85,7 +85,7 @@ public class DBinterface { int confidence = SM.isStateMachineFollowed(graph, actions, initialState, initialConf); //System.out.print("The confidence score is: "+ confidence + "\n"); return confidence; return ((int)((double)confidence*100.0/(actions.size()*15))); } catch (SQLException e) { e.printStackTrace(); } Loading
CheckerCorrector/GUI/ColorSpectrumPanel.java 0 → 100644 +34 −0 Original line number Diff line number Diff line package GUI; import javax.swing.*; import java.awt.*; public class ColorSpectrumPanel extends JPanel { private int width; private int height; public ColorSpectrumPanel(int width, int height) { this.width = width; this.height = height; setPreferredSize(new Dimension(width, height)); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; // Draw color spectrum for (int i = 0; i < width; i++) { float saturation = (float) i / (float) width; Color color = Color.getHSBColor(0, saturation, 1); g2d.setColor(color); g2d.drawLine(i, 0, i, height); } // Add labels g2d.setColor(Color.BLACK); g2d.drawString("Confidence=0", 5, height - 5); g2d.drawString("Confidence=100 ", width - 110, height - 5); } }
CheckerCorrector/GUI/HighlighterGUI.java +51 −15 Original line number Diff line number Diff line Loading @@ -5,7 +5,9 @@ import javax.swing.text.DefaultHighlighter; import DBinterface.DBinterface; import DirectedGraph.BasicGraph; import HashTableMaker.HashTableMaker; import java.sql.SQLException; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; Loading @@ -15,9 +17,16 @@ import java.util.Random; public class HighlighterGUI extends JFrame { private JTextArea textArea; private JPanel mainPanel; private JButton highlightButton; public boolean isDutch; private static final int POPUP_WIDTH = 800; private static final int POPUP_HEIGHT = 300; public HighlighterGUI(boolean isDutch) { mainPanel = new JPanel(new BorderLayout()); mainPanel.setPreferredSize(new Dimension(POPUP_WIDTH, POPUP_HEIGHT)); this.isDutch = isDutch; setTitle("Text Highlighter"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Loading @@ -35,8 +44,24 @@ public class HighlighterGUI extends JFrame { JPanel buttonPanel = new JPanel(); buttonPanel.add(highlightButton); add(new JScrollPane(textArea), BorderLayout.CENTER); add(buttonPanel, BorderLayout.SOUTH); JFrame frame = new JFrame("Color Spectrum Panel"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); int panelWidth = POPUP_WIDTH; int panelHeight = POPUP_HEIGHT/10; ColorSpectrumPanel colorSpectrumPanel = new ColorSpectrumPanel(panelWidth, panelHeight); mainPanel.add(new JScrollPane(textArea), BorderLayout.NORTH); mainPanel.add(colorSpectrumPanel, BorderLayout.CENTER); mainPanel.add(buttonPanel, BorderLayout.SOUTH); add(mainPanel); //add(, BorderLayout.CENTER); //add(buttonPanel, BorderLayout.SOUTH); pack(); setLocationRelativeTo(null); Loading @@ -52,7 +77,7 @@ public class HighlighterGUI extends JFrame { private List<String> extractPhrases(String text, int phraseLength) { List<String> phrases = new ArrayList<>(); String[] words = text.split("\\s+"); for (int i = 0; i <= words.length - phraseLength; i+=phraseLength) { for (int i = 0; i <= words.length - phraseLength; i+=1) { StringBuilder phraseBuilder = new StringBuilder(); for (int j = 0; j < phraseLength; j++) { phraseBuilder.append(words[i + j]); Loading @@ -66,21 +91,32 @@ public class HighlighterGUI extends JFrame { } private void highlightPhrases(List<String> phrases) { try{ DBinterface dbInterface; HashTableMaker manager; if(!this.isDutch){ dbInterface = new DBinterface("SQLite/token_database_english.db", "SQLite/smallDic.txt"); manager = new HashTableMaker("SQLite/hash_database_english.db"); }else{ dbInterface = new DBinterface("SQLite/token_database_dutch.db", "SQLite/DutchTranslation.txt"); manager = new HashTableMaker("SQLite/hash_database_dutch.db"); } BasicGraph basicGraphClass = new BasicGraph(); for (String phrase : phrases) { highlightPhrase(phrase, dbInterface.checkTokenInDatabase(phrase, basicGraphClass.getGraph())); double conf = dbInterface.checkTokenInDatabase(phrase, basicGraphClass.getGraph())*0.8; conf += manager.nGram(phrase, 3)*0.2; //System.out.println(phrase + "| "+ conf); highlightPhrase(phrase, (int)conf); } } catch (SQLException e) { e.printStackTrace(); } } private Color getColorForNumber(int number) { float hue = (float) number / 100; // Hue ranges from 0 to 1 return Color.getHSBColor(hue, 1, 1); float hue = ((float) number / 100); // Hue ranges from 0 to 1 //System.out.println(hue); return Color.getHSBColor(0, hue, 1); } private void highlightPhrase(String phrase, int colorInd) { Loading
Crawler/target/classes/Makefile 0 → 100644 +20 −0 Original line number Diff line number Diff line JAVAC=javac JFLAGS=-Xlint:none -Xlint:-deprecation LIBS=tika-app-2.9.2.jar default: ScratchCrawler.class Debug.class RobotsTXT.class RegexParser.class ScratchCrawler.class: ScratchCrawler.java $(JAVAC) $(JFLAGS) -cp $(LIBS) ScratchCrawler.java Debug.class: Debug.java $(JAVAC) $(JFLAGS) -cp $(LIBS) Debug.java RobotsTXT.class: RobotsTXT.java $(JAVAC) $(JFLAGS) -cp $(LIBS) RobotsTXT.java RegexParser.class: RegexParser.java $(JAVAC) $(JFLAGS) -cp $(LIBS) RegexParser.java clean: del *.class