Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1732205428671</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
Binary file added BL/FileBL.class
Binary file not shown.
Binary file added DAL/IFileDAO.class
Binary file not shown.
Binary file added DTO/FileDTO.class
Binary file not shown.
6 changes: 6 additions & 0 deletions src/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path=""/>
<classpathentry kind="output" path=""/>
</classpath>
17 changes: 17 additions & 0 deletions src/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>JavaTypers_src</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
5 changes: 5 additions & 0 deletions src/BL/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions src/BL/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/FileBL.class
17 changes: 17 additions & 0 deletions src/BL/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>BL</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Binary file added src/BL/AnalysisManagerBL.class
Binary file not shown.
147 changes: 147 additions & 0 deletions src/BL/AnalysisManagerBL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package BL;
import java.util.*;
public class AnalysisManagerBL {

public Map<String, Map<String, Double>> analyzeIndividualFiles(List<String> allFiles) {
Map<String, Map<String, Double>> individualResults = new LinkedHashMap<>();

for (String content : allFiles) {
Map<String, Double> tfidf = calculateTFIDF(content, allFiles);
individualResults.put("TF-IDF", tfidf);

Map<String, Double> pmi = calculatePMI(content, allFiles);
individualResults.put("PMI", pmi);

Map<String, Double> pkl = calculatePKL(content);
individualResults.put("PKL", pkl);
}
return individualResults;
}

public Map<String, Map<String, Double>> analyzeAcrossAllFiles(List<String> allFiles) {
String combinedContent = String.join(" ", allFiles);

Map<String, Double> tfidf = calculateTFIDF(combinedContent, allFiles);
Map<String, Double> pmi = calculatePMI(combinedContent, allFiles);
Map<String, Double> pkl = calculatePKL(combinedContent);

Map<String, Map<String, Double>> overallResults = new LinkedHashMap<>();
overallResults.put("TF-IDF", tfidf);
overallResults.put("PMI", pmi);
overallResults.put("PKL", pkl);

return overallResults;
}
public Map<String, Double> calculateTFIDF(String content, List<String> allFiles) {
Map<String, Integer> termFrequency = calculateTermFrequency(content);
Map<String, Double> 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<String, Double> calculatePMI(String content, List<String> allFiles) {
Map<String, Integer> termFrequency = calculateTermFrequency(content);
Map<String, Double> 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<String, Integer> calculateTermFrequency(String content) {
Map<String, Integer> 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<String> 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<String, Double> calculatePKL(String content) {
// Tokenize the content
List<String> words = tokenize(content);

// Create a map for word pairs
Map<String, Map<String, Integer>> coOccurrenceMap = new HashMap<>();
Map<String, Integer> 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<String, Double> pklResults = new HashMap<>();
for (Map.Entry<String, Map<String, Integer>> entry : coOccurrenceMap.entrySet()) {
String word1 = entry.getKey();
Map<String, Integer> coOccurringWords = entry.getValue();

for (Map.Entry<String, Integer> 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<String> tokenize(String content) {
String[] words = content.split("\\s+");
return Arrays.asList(words);
}


}



Binary file modified src/BL/FileBL.class
Binary file not shown.
5 changes: 5 additions & 0 deletions src/DAL/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
4 changes: 4 additions & 0 deletions src/DAL/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/DAOFactory.class
/FileDAO.class
/MongoDAOFactory.class
/MySQLDAOFactory.class
17 changes: 17 additions & 0 deletions src/DAL/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>DAL</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Binary file modified src/DAL/FileDAO.class
Binary file not shown.
26 changes: 26 additions & 0 deletions src/DAL/FileDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,32 @@ public boolean isFileExists(String hashValue) throws SQLException {
return rs.getInt(1) > 0;
}
}
//fetching file content
public List<String> getAllFiles() throws Exception {
List<String> 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;
}


}

Binary file modified src/DAL/MongoDAOFactory.class
Binary file not shown.
Binary file modified src/DAL/MySQLDAOFactory.class
Binary file not shown.
1 change: 1 addition & 0 deletions src/DTO/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/FileDTO.class
Binary file modified src/DTO/FileDTO.class
Binary file not shown.
5 changes: 5 additions & 0 deletions src/PL/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions src/PL/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/TextEditorGUI.class
17 changes: 17 additions & 0 deletions src/PL/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>PL</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Binary file added src/PL/AnalysisManager.class
Binary file not shown.
Loading