diff --git a/.project b/.project index 57e74ed..cbd0aee 100644 --- a/.project +++ b/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1732205428671 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/BL/FileBL.class b/BL/FileBL.class new file mode 100644 index 0000000..e08cbeb Binary files /dev/null and b/BL/FileBL.class differ diff --git a/DAL/IFileDAO.class b/DAL/IFileDAO.class new file mode 100644 index 0000000..d3e7334 Binary files /dev/null and b/DAL/IFileDAO.class differ diff --git a/DTO/FileDTO.class b/DTO/FileDTO.class new file mode 100644 index 0000000..0d5b392 Binary files /dev/null and b/DTO/FileDTO.class differ diff --git a/src/.classpath b/src/.classpath new file mode 100644 index 0000000..3f3893a --- /dev/null +++ b/src/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/.project b/src/.project new file mode 100644 index 0000000..df14eba --- /dev/null +++ b/src/.project @@ -0,0 +1,17 @@ + + + JavaTypers_src + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/src/BL/.classpath b/src/BL/.classpath new file mode 100644 index 0000000..ac37fb2 --- /dev/null +++ b/src/BL/.classpath @@ -0,0 +1,5 @@ + + + + + diff --git a/src/BL/.gitignore b/src/BL/.gitignore new file mode 100644 index 0000000..83879fd --- /dev/null +++ b/src/BL/.gitignore @@ -0,0 +1 @@ +/FileBL.class diff --git a/src/BL/.project b/src/BL/.project new file mode 100644 index 0000000..a868cff --- /dev/null +++ b/src/BL/.project @@ -0,0 +1,17 @@ + + + BL + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/src/BL/AnalysisManagerBL.class b/src/BL/AnalysisManagerBL.class new file mode 100644 index 0000000..c104697 Binary files /dev/null and b/src/BL/AnalysisManagerBL.class differ diff --git a/src/BL/AnalysisManagerBL.java b/src/BL/AnalysisManagerBL.java new file mode 100644 index 0000000..b53e783 --- /dev/null +++ b/src/BL/AnalysisManagerBL.java @@ -0,0 +1,147 @@ +package BL; +import java.util.*; +public class AnalysisManagerBL { + + public Map> analyzeIndividualFiles(List allFiles) { + Map> individualResults = new LinkedHashMap<>(); + + for (String content : allFiles) { + Map tfidf = calculateTFIDF(content, allFiles); + individualResults.put("TF-IDF", tfidf); + + Map pmi = calculatePMI(content, allFiles); + individualResults.put("PMI", pmi); + + Map pkl = calculatePKL(content); + individualResults.put("PKL", pkl); + } + return individualResults; + } + + public Map> analyzeAcrossAllFiles(List allFiles) { + String combinedContent = String.join(" ", allFiles); + + Map tfidf = calculateTFIDF(combinedContent, allFiles); + Map pmi = calculatePMI(combinedContent, allFiles); + Map pkl = calculatePKL(combinedContent); + + Map> overallResults = new LinkedHashMap<>(); + overallResults.put("TF-IDF", tfidf); + overallResults.put("PMI", pmi); + overallResults.put("PKL", pkl); + + return overallResults; + } + public Map calculateTFIDF(String content, List allFiles) { + Map termFrequency = calculateTermFrequency(content); + Map tfidfScores = new HashMap<>(); + int totalDocs = allFiles.size(); + + for (String term : termFrequency.keySet()) { + int docCount = (int) allFiles.stream().filter(file -> file.contains(term)).count(); + double tf = termFrequency.get(term) / (double) content.split("\\s+").length; + double idf = Math.log((double) totalDocs / (docCount + 1)); + tfidfScores.put(term, tf * idf); + } + return tfidfScores; + } + + public Map calculatePMI(String content, List allFiles) { + Map termFrequency = calculateTermFrequency(content); + Map pmiScores = new HashMap<>(); + int totalWords = content.split("\\s+").length; + + for (String term1 : termFrequency.keySet()) { + for (String term2 : termFrequency.keySet()) { + if (!term1.equals(term2)) { + double pXY = calculateJointProbability(term1, term2, allFiles); + double pX = termFrequency.get(term1) / (double) totalWords; + double pY = termFrequency.get(term2) / (double) totalWords; + + if (pX > 0 && pY > 0 && pXY > 0) { + pmiScores.put(term1 + " | " + term2, Math.log(pXY / (pX * pY))); + } + } + } + } + return pmiScores; + } + private Map calculateTermFrequency(String content) { + Map frequency = new HashMap<>(); + String[] words = content.split("\\s+"); + for (String word : words) { + frequency.put(word, frequency.getOrDefault(word, 0) + 1); + } + return frequency; + } + + private double calculateJointProbability(String term1, String term2, List allFiles) { + int count = 0; + for (String file : allFiles) { + if (file.contains(term1) && file.contains(term2)) { + count++; + } + } + return count / (double) allFiles.size(); + } + + // PKL Calculation (Pointwise Mutual Information - Latent) + public Map calculatePKL(String content) { + // Tokenize the content + List words = tokenize(content); + + // Create a map for word pairs + Map> coOccurrenceMap = new HashMap<>(); + Map wordCountMap = new HashMap<>(); + int totalWordCount = 0; + + // Build the word count and co-occurrence map + for (int i = 0; i < words.size(); i++) { + String word1 = words.get(i); + wordCountMap.put(word1, wordCountMap.getOrDefault(word1, 0) + 1); + totalWordCount++; + + for (int j = i + 1; j < words.size(); j++) { + String word2 = words.get(j); + coOccurrenceMap.putIfAbsent(word1, new HashMap<>()); + coOccurrenceMap.get(word1).put(word2, coOccurrenceMap.get(word1).getOrDefault(word2, 0) + 1); + } + } + + // Calculate PKL (Pointwise Mutual Information - Latent) between word pairs + Map pklResults = new HashMap<>(); + for (Map.Entry> entry : coOccurrenceMap.entrySet()) { + String word1 = entry.getKey(); + Map coOccurringWords = entry.getValue(); + + for (Map.Entry coOccurEntry : coOccurringWords.entrySet()) { + String word2 = coOccurEntry.getKey(); + int coOccurrenceCount = coOccurEntry.getValue(); + + // Calculate the individual probabilities + double pWord1 = (double) wordCountMap.get(word1) / totalWordCount; + double pWord2 = (double) wordCountMap.get(word2) / totalWordCount; + double pWord1AndWord2 = (double) coOccurrenceCount / totalWordCount; + + // Calculate PKL using the formula + double pkl = Math.log(pWord1AndWord2 / (pWord1 * pWord2)); + + // Save the PKL result in the map + pklResults.put(word1 + "|" + word2, pkl); + } + } + + return pklResults; + } + + // Helper method to tokenize the content (this could be improved with stemming, stop words removal, etc.) + private List tokenize(String content) { + String[] words = content.split("\\s+"); + return Arrays.asList(words); + } + + +} + + + diff --git a/src/BL/FileBL.class b/src/BL/FileBL.class index 10bc07b..edd2603 100644 Binary files a/src/BL/FileBL.class and b/src/BL/FileBL.class differ diff --git a/src/DAL/.classpath b/src/DAL/.classpath new file mode 100644 index 0000000..ac37fb2 --- /dev/null +++ b/src/DAL/.classpath @@ -0,0 +1,5 @@ + + + + + diff --git a/src/DAL/.gitignore b/src/DAL/.gitignore new file mode 100644 index 0000000..1f5fafb --- /dev/null +++ b/src/DAL/.gitignore @@ -0,0 +1,4 @@ +/DAOFactory.class +/FileDAO.class +/MongoDAOFactory.class +/MySQLDAOFactory.class diff --git a/src/DAL/.project b/src/DAL/.project new file mode 100644 index 0000000..5f79545 --- /dev/null +++ b/src/DAL/.project @@ -0,0 +1,17 @@ + + + DAL + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/src/DAL/FileDAO.class b/src/DAL/FileDAO.class index e33291c..98cdcac 100644 Binary files a/src/DAL/FileDAO.class and b/src/DAL/FileDAO.class differ diff --git a/src/DAL/FileDAO.java b/src/DAL/FileDAO.java index 4740c71..81714b4 100644 --- a/src/DAL/FileDAO.java +++ b/src/DAL/FileDAO.java @@ -157,6 +157,32 @@ public boolean isFileExists(String hashValue) throws SQLException { return rs.getInt(1) > 0; } } +//fetching file content +public List getAllFiles() throws Exception { + List files = new ArrayList<>(); + try (Connection conn = getConnection(); + PreparedStatement stmt = conn.prepareStatement("SELECT content FROM files"); + ResultSet rs = stmt.executeQuery()) { + while (rs.next()) { + files.add(rs.getString("content")); + } + } + return files; +} + +public String getFileContent(String fileName) throws Exception { + try (Connection conn = getConnection(); + PreparedStatement stmt = conn.prepareStatement("SELECT content FROM files WHERE name = ?")) { + stmt.setString(1, fileName); + try (ResultSet rs = stmt.executeQuery()) { + if (rs.next()) { + return rs.getString("content"); + } + } + } + return null; +} + } diff --git a/src/DAL/MongoDAOFactory.class b/src/DAL/MongoDAOFactory.class index 4298dd2..5b95fe6 100644 Binary files a/src/DAL/MongoDAOFactory.class and b/src/DAL/MongoDAOFactory.class differ diff --git a/src/DAL/MySQLDAOFactory.class b/src/DAL/MySQLDAOFactory.class index 4ff7a55..05538a2 100644 Binary files a/src/DAL/MySQLDAOFactory.class and b/src/DAL/MySQLDAOFactory.class differ diff --git a/src/DTO/.gitignore b/src/DTO/.gitignore new file mode 100644 index 0000000..42a4686 --- /dev/null +++ b/src/DTO/.gitignore @@ -0,0 +1 @@ +/FileDTO.class diff --git a/src/DTO/FileDTO.class b/src/DTO/FileDTO.class index ef8485f..bbccbaf 100644 Binary files a/src/DTO/FileDTO.class and b/src/DTO/FileDTO.class differ diff --git a/src/PL/.classpath b/src/PL/.classpath new file mode 100644 index 0000000..ac37fb2 --- /dev/null +++ b/src/PL/.classpath @@ -0,0 +1,5 @@ + + + + + diff --git a/src/PL/.gitignore b/src/PL/.gitignore new file mode 100644 index 0000000..98c3b41 --- /dev/null +++ b/src/PL/.gitignore @@ -0,0 +1 @@ +/TextEditorGUI.class diff --git a/src/PL/.project b/src/PL/.project new file mode 100644 index 0000000..0358a8c --- /dev/null +++ b/src/PL/.project @@ -0,0 +1,17 @@ + + + PL + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/src/PL/AnalysisManager.class b/src/PL/AnalysisManager.class new file mode 100644 index 0000000..e5d8446 Binary files /dev/null and b/src/PL/AnalysisManager.class differ diff --git a/src/PL/AnalysisManager.java b/src/PL/AnalysisManager.java new file mode 100644 index 0000000..a7ef06c --- /dev/null +++ b/src/PL/AnalysisManager.java @@ -0,0 +1,94 @@ +package PL; +import BL.AnalysisManagerBL; +import DAL.FileDAO; + +import javax.swing.*; +import java.awt.*; +import java.util.List; +import java.util.Map; + +public class AnalysisManager extends JFrame { + private AnalysisManagerBL analysisManager; + private FileDAO databaseManager; + private JTextArea resultArea; + + public AnalysisManager() { + setTitle("Text Analysis"); + setSize(800, 600); + setDefaultCloseOperation(EXIT_ON_CLOSE); + + analysisManager = new AnalysisManagerBL(); + databaseManager = new FileDAO(); + + resultArea = new JTextArea(); + resultArea.setEditable(false); + + JButton analyzeIndividualButton = new JButton("Analyze Individual Files"); + analyzeIndividualButton.addActionListener(e -> analyzeIndividualFiles()); + + JButton analyzeAllButton = new JButton("Analyze Across All Files"); + analyzeAllButton.addActionListener(e -> analyzeAcrossAllFiles()); + + JButton backButton = new JButton("Back"); + backButton.addActionListener(e -> navigateBack()); + + JPanel buttonPanel = new JPanel(); + buttonPanel.add(analyzeIndividualButton); + buttonPanel.add(analyzeAllButton); + buttonPanel.add(backButton); + + add(new JScrollPane(resultArea), BorderLayout.CENTER); + add(buttonPanel, BorderLayout.SOUTH); + + setVisible(true); + } + + private void navigateBack() { + this.setVisible(false); + new TextEditorGUI(); + } + + private void analyzeIndividualFiles() { + try { + List allFiles = databaseManager.getAllFiles(); + Map> results = analysisManager.analyzeIndividualFiles(allFiles); + + resultArea.setText("Individual File Analysis Results:\n\n"); + for (Map.Entry> entry : results.entrySet()) { + resultArea.append(entry.getKey() + ":\n"); + for (Map.Entry metric : entry.getValue().entrySet()) { + resultArea.append(metric.getKey() + ": " + metric.getValue() + "\n"); + } + resultArea.append("\n"); + } + } catch (Exception ex) { + ex.printStackTrace(); + JOptionPane.showMessageDialog(this, "Error analyzing individual files: " + ex.getMessage()); + } + } + + private void analyzeAcrossAllFiles() { + try { + List allFiles = databaseManager.getAllFiles(); + Map> results = analysisManager.analyzeAcrossAllFiles(allFiles); + + resultArea.setText("Overall Analysis Results Across All Files:\n\n"); + for (Map.Entry> entry : results.entrySet()) { + resultArea.append(entry.getKey() + ":\n"); + for (Map.Entry metric : entry.getValue().entrySet()) { + resultArea.append(metric.getKey() + ": " + metric.getValue() + "\n"); + } + resultArea.append("\n"); + } + } catch (Exception ex) { + ex.printStackTrace(); + JOptionPane.showMessageDialog(this, "Error analyzing across all files: " + ex.getMessage()); + } + } + + public static void main(String[] args) { + new AnalysisManager(); + } +} + + \ No newline at end of file diff --git a/src/PL/TextEditorGUI.class b/src/PL/TextEditorGUI.class index 57bbffc..4e9b905 100644 Binary files a/src/PL/TextEditorGUI.class and b/src/PL/TextEditorGUI.class differ diff --git a/src/PL/TextEditorGUI.java b/src/PL/TextEditorGUI.java index 103ddc7..4ec9fd7 100644 --- a/src/PL/TextEditorGUI.java +++ b/src/PL/TextEditorGUI.java @@ -95,6 +95,7 @@ private void initializeUI() { addButton(buttonPanel, "Delete File", new Color(75, 0, 130)); // Dark purple color addButton(buttonPanel, "Import File", new Color(75, 0, 130)); // Dark purple color addButton(buttonPanel, "Import Bulk Files", new Color(75, 0, 130)); // Dark purple color + addButton(buttonPanel, "Analysis", new Color(0, 128, 0)); // Green for analysis button add(buttonPanel, BorderLayout.SOUTH); @@ -154,6 +155,9 @@ private void handleButtonClick(String action) { case "Import Bulk Files": importBulkFiles(); break; + case "Analysis": + openAnalysisManager(); + break; } } catch (Exception ex) { setStatus("Error: " + ex.getMessage(), true); @@ -362,4 +366,10 @@ public static void main(String[] args) { ui.setVisible(true); }); } + // Methid to open analysis Manager + private void openAnalysisManager() { + SwingUtilities.invokeLater(() -> { + AnalysisManager analysisManager = new AnalysisManager(this); + analysisManager.setVisible(true); + }); }