diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 5974b4e..9bb3bb5 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,2 +1,2 @@ # Done for Review -* @sasharmagrid +* @SajjadSidd diff --git a/SCA/Readme.md b/SCA/Readme.md new file mode 100644 index 0000000..f6fc33d --- /dev/null +++ b/SCA/Readme.md @@ -0,0 +1 @@ +Screenshot 2025-02-11 at 2 07 46 PM diff --git a/SCA/pom.xml b/SCA/pom.xml new file mode 100644 index 0000000..7a4f8d3 --- /dev/null +++ b/SCA/pom.xml @@ -0,0 +1,68 @@ + + 4.0.0 + + org.example + com.testReport + 1.0-SNAPSHOT + jar + + com.testReport + http://maven.apache.org + + + UTF-8 + + + + + + org.apache.commons + commons-lang3 + 3.12.0 + + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.6.0 + + + validate + + check + + + + + + google_checks.xml + + true + true + + + + com.github.spotbugs + spotbugs-maven-plugin + 4.8.6.6 + + target/spotbugs-report + true + true + + + + org.apache.maven.plugins + maven-compiler-plugin + + 10 + 10 + + + + + diff --git a/SCA/src/main/java/org/example/search/Main.java b/SCA/src/main/java/org/example/search/Main.java new file mode 100644 index 0000000..3e90b0a --- /dev/null +++ b/SCA/src/main/java/org/example/search/Main.java @@ -0,0 +1,16 @@ +package search; + +import search.SimpleSearchEngine.Search; + +class Main{ + public static void main(String[] args) { + if (args.length == 2 && "--data".equals(args[0])) { + String fileName = args[1]; +// String fileName = "/Users/hasingh/IdeaProjects/Simple Search Engine (Java)/Simple Search Engine (Java)/task/names.txt"; + Search search = new Search(); + search.getInput(fileName); + } else { + System.out.println("Usage: java Search --data "); + } + } +} \ No newline at end of file diff --git a/SCA/src/main/java/org/example/search/SearchEngineInterface/AllSearchStrategy.java b/SCA/src/main/java/org/example/search/SearchEngineInterface/AllSearchStrategy.java new file mode 100644 index 0000000..d370d06 --- /dev/null +++ b/SCA/src/main/java/org/example/search/SearchEngineInterface/AllSearchStrategy.java @@ -0,0 +1,18 @@ +package org.example.search.SearchEngineInterface; + + +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class AllSearchStrategy implements SimpleSearchEngine { + + @Override + public Set search(String[] queryWords, Map> invertedIndex) { + Set resultIndexes = new HashSet<>(invertedIndex.getOrDefault(queryWords[0], Set.of())); + for (int i = 1; i < queryWords.length; i++) { + resultIndexes.retainAll(invertedIndex.getOrDefault(queryWords[i], Set.of())); + } + return resultIndexes; + } +} \ No newline at end of file diff --git a/SCA/src/main/java/org/example/search/SearchEngineInterface/AnySearchStrategy.java b/SCA/src/main/java/org/example/search/SearchEngineInterface/AnySearchStrategy.java new file mode 100644 index 0000000..0e1446a --- /dev/null +++ b/SCA/src/main/java/org/example/search/SearchEngineInterface/AnySearchStrategy.java @@ -0,0 +1,17 @@ +package org.example.search.SearchEngineInterface; + +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class AnySearchStrategy implements SimpleSearchEngine { + + @Override + public Set search(String[] queryWords, Map> invertedIndex) { + Set resultIndexes = new HashSet<>(); + for (String word : queryWords) { + resultIndexes.addAll(invertedIndex.getOrDefault(word, Set.of())); + } + return resultIndexes; + } +} \ No newline at end of file diff --git a/SCA/src/main/java/org/example/search/SearchEngineInterface/NoneSearchStrategy.java b/SCA/src/main/java/org/example/search/SearchEngineInterface/NoneSearchStrategy.java new file mode 100644 index 0000000..2e9964d --- /dev/null +++ b/SCA/src/main/java/org/example/search/SearchEngineInterface/NoneSearchStrategy.java @@ -0,0 +1,21 @@ +package org.example.search.SearchEngineInterface; + + +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class NoneSearchStrategy implements SimpleSearchEngine { + + @Override + public Set search(String[] queryWords, Map> invertedIndex) { + Set allIndexes = new HashSet<>(); + invertedIndex.values().forEach(allIndexes::addAll); + + Set resultIndexes = new HashSet<>(allIndexes); + for (String word : queryWords) { + resultIndexes.removeAll(invertedIndex.getOrDefault(word, Set.of())); + } + return resultIndexes; + } +} \ No newline at end of file diff --git a/SCA/src/main/java/org/example/search/SearchEngineInterface/SimpleSearchEngine.java b/SCA/src/main/java/org/example/search/SearchEngineInterface/SimpleSearchEngine.java new file mode 100644 index 0000000..f6a099c --- /dev/null +++ b/SCA/src/main/java/org/example/search/SearchEngineInterface/SimpleSearchEngine.java @@ -0,0 +1,10 @@ +package org.example.search.SearchEngineInterface; + +import java.util.Map; +import java.util.Set; + +public interface SimpleSearchEngine { + public Set search(String[] queryWords, Map> invertedIndex); + +} + diff --git a/SCA/src/main/java/org/example/search/SimpleSearchEngine/Search.java b/SCA/src/main/java/org/example/search/SimpleSearchEngine/Search.java new file mode 100644 index 0000000..dd9b767 --- /dev/null +++ b/SCA/src/main/java/org/example/search/SimpleSearchEngine/Search.java @@ -0,0 +1,143 @@ +package org.example.search.SimpleSearchEngine; + +import org.example.search.SearchEngineInterface.AllSearchStrategy; +import org.example.search.SearchEngineInterface.AnySearchStrategy; +import org.example.search.SearchEngineInterface.NoneSearchStrategy; +import org.example.search.SearchEngineInterface.SimpleSearchEngine; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.*; + +public class Search { + + private SimpleSearchEngine searchStrategy; + + // Set the search strategy at runtime + public void setSearchStrategy(SimpleSearchEngine searchStrategy) { + this.searchStrategy = searchStrategy; + } + + public void getInput(String fileName) { + // Use a Scanner with UTF-8 encoding + Scanner sc = new Scanner(System.in, StandardCharsets.UTF_8); + ArrayList nameWithMail = readFile(fileName); + if (nameWithMail.isEmpty()) { + System.out.println("No data found in the file."); + return; + } + + Map> invertedIndex = buildInvertedIndex(nameWithMail); + + while (true) { + System.out.println("\n=== MENU ==="); + System.out.println("1. Find a person"); + System.out.println("2. Print all people"); + System.out.println("0. Exit"); + + int userChoice = sc.nextInt(); + sc.nextLine(); // Consume the newline character + + switch (userChoice) { + case 1: + System.out.println("\nSelect a matching strategy: ALL, ANY, NONE"); + System.out.print("> "); + String strategy = sc.nextLine().toUpperCase().trim(); + + // Dynamically set the search strategy based on user input + switch (strategy) { + case "ALL": + setSearchStrategy(new AllSearchStrategy()); + break; + case "ANY": + setSearchStrategy(new AnySearchStrategy()); + break; + case "NONE": + setSearchStrategy(new NoneSearchStrategy()); + break; + default: + System.out.println("Invalid strategy! Defaulting to ANY."); + setSearchStrategy(new AnySearchStrategy()); + break; + } + + System.out.println("\nEnter a name or email to search all suitable people."); + System.out.print("> "); + String query = sc.nextLine().toLowerCase().trim(); + + ArrayList foundPeople = searchFoundPeople(query, invertedIndex, nameWithMail); + displayFoundPeople(foundPeople); + break; + + case 2: + System.out.println("\n=== List of people ==="); + displayFoundPeople(nameWithMail); + break; + + case 0: + System.out.print("\nBye!"); + return; + + default: + System.out.println("\nIncorrect option! Try again."); + break; + } + } + } + + private ArrayList readFile(String fileName) { + ArrayList nameWithMail = new ArrayList<>(); + try (BufferedReader reader = new BufferedReader(new FileReader(fileName, StandardCharsets.UTF_8))) { + String line; + while ((line = reader.readLine()) != null) { + nameWithMail.add(line.trim()); + } + } catch (IOException e) { + System.out.println("Error reading file: " + e.getMessage()); + } + return nameWithMail; + } + + private Map> buildInvertedIndex(ArrayList nameWithMail) { + Map> invertedIndex = new HashMap<>(); + + for (int index = 0; index < nameWithMail.size(); index++) { + String line = nameWithMail.get(index); + String[] words = line.toLowerCase().split(" "); + + for (String word : words) { + invertedIndex.putIfAbsent(word, new HashSet<>()); + invertedIndex.get(word).add(index); + } + } + + return invertedIndex; + } + + public ArrayList searchFoundPeople(String query, Map> invertedIndex, ArrayList nameWithMail) { + String[] queryWords = query.split(" "); + + // Use the current strategy to perform the search + Set resultIndexes = searchStrategy.search(queryWords, invertedIndex); + + ArrayList foundPeople = new ArrayList<>(); + for (int index : resultIndexes) { + foundPeople.add(nameWithMail.get(index)); + } + return foundPeople; + } + + public void displayFoundPeople(ArrayList foundPeople) { + if (foundPeople.isEmpty()) { + System.out.println("No matching people found."); + } else { + System.out.println(foundPeople.size() + " persons found:"); + for (String person : foundPeople) { + System.out.println(person); + } + } + } +} diff --git a/SCA/src/test/java/org/example/AppTest.java b/SCA/src/test/java/org/example/AppTest.java new file mode 100644 index 0000000..cee4539 --- /dev/null +++ b/SCA/src/test/java/org/example/AppTest.java @@ -0,0 +1,8 @@ +package org.example; + + +/** + * Unit test for simple App. + */ +public class AppTest { +} diff --git a/SCA/target/checkstyle-cachefile b/SCA/target/checkstyle-cachefile new file mode 100644 index 0000000..b82238e --- /dev/null +++ b/SCA/target/checkstyle-cachefile @@ -0,0 +1,4 @@ +#Tue Feb 11 11:09:05 IST 2025 +configuration*?=DF49F0FE5B9B10DC7D619307077AB41F3A1D6CA4 +module-resource*?\:checkstyle-xpath-suppressions.xml=FA903F3273968553608AED7EAA3A7AD969B0A598 +module-resource*?\:checkstyle-suppressions.xml=8E483F9CA10CB1377DC49BE8CF79425FD801210 diff --git a/SCA/target/checkstyle-checker.xml b/SCA/target/checkstyle-checker.xml new file mode 100644 index 0000000..515a844 --- /dev/null +++ b/SCA/target/checkstyle-checker.xml @@ -0,0 +1,364 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SCA/target/checkstyle-result.xml b/SCA/target/checkstyle-result.xml new file mode 100644 index 0000000..61daa3e --- /dev/null +++ b/SCA/target/checkstyle-result.xml @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SCA/target/classes/search/Main.class b/SCA/target/classes/search/Main.class new file mode 100644 index 0000000..253f772 Binary files /dev/null and b/SCA/target/classes/search/Main.class differ diff --git a/SCA/target/classes/search/SerachEngineInterface/AllSearchStrategy.class b/SCA/target/classes/search/SerachEngineInterface/AllSearchStrategy.class new file mode 100644 index 0000000..f17a6f5 Binary files /dev/null and b/SCA/target/classes/search/SerachEngineInterface/AllSearchStrategy.class differ diff --git a/SCA/target/classes/search/SerachEngineInterface/AnySearchStrategy.class b/SCA/target/classes/search/SerachEngineInterface/AnySearchStrategy.class new file mode 100644 index 0000000..55df279 Binary files /dev/null and b/SCA/target/classes/search/SerachEngineInterface/AnySearchStrategy.class differ diff --git a/SCA/target/classes/search/SerachEngineInterface/NoneSearchStrategy.class b/SCA/target/classes/search/SerachEngineInterface/NoneSearchStrategy.class new file mode 100644 index 0000000..b5e3639 Binary files /dev/null and b/SCA/target/classes/search/SerachEngineInterface/NoneSearchStrategy.class differ diff --git a/SCA/target/classes/search/SerachEngineInterface/SimpleSearchEngine.class b/SCA/target/classes/search/SerachEngineInterface/SimpleSearchEngine.class new file mode 100644 index 0000000..696f546 Binary files /dev/null and b/SCA/target/classes/search/SerachEngineInterface/SimpleSearchEngine.class differ diff --git a/SCA/target/classes/search/SimpleSearchEngine/Search.class b/SCA/target/classes/search/SimpleSearchEngine/Search.class new file mode 100644 index 0000000..2835d98 Binary files /dev/null and b/SCA/target/classes/search/SimpleSearchEngine/Search.class differ diff --git a/SCA/target/com.testReport-1.0-SNAPSHOT.jar b/SCA/target/com.testReport-1.0-SNAPSHOT.jar new file mode 100644 index 0000000..1ea69af Binary files /dev/null and b/SCA/target/com.testReport-1.0-SNAPSHOT.jar differ diff --git a/SCA/target/maven-archiver/pom.properties b/SCA/target/maven-archiver/pom.properties new file mode 100644 index 0000000..30756e2 --- /dev/null +++ b/SCA/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=com.testReport +groupId=org.example +version=1.0-SNAPSHOT diff --git a/SCA/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/SCA/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..12c92c9 --- /dev/null +++ b/SCA/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,6 @@ +search/Main.class +search/SerachEngineInterface/NoneSearchStrategy.class +search/SerachEngineInterface/AnySearchStrategy.class +search/SimpleSearchEngine/Search.class +search/SerachEngineInterface/AllSearchStrategy.class +search/SerachEngineInterface/SimpleSearchEngine.class diff --git a/SCA/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/SCA/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..786e683 --- /dev/null +++ b/SCA/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,6 @@ +/Users/hasingh/IdeaProjects/com.testReport/src/main/java/org/example/search/Main.java +/Users/hasingh/IdeaProjects/com.testReport/src/main/java/org/example/search/SerachEngineInterface/AllSearchStrategy.java +/Users/hasingh/IdeaProjects/com.testReport/src/main/java/org/example/search/SerachEngineInterface/AnySearchStrategy.java +/Users/hasingh/IdeaProjects/com.testReport/src/main/java/org/example/search/SerachEngineInterface/NoneSearchStrategy.java +/Users/hasingh/IdeaProjects/com.testReport/src/main/java/org/example/search/SerachEngineInterface/SimpleSearchEngine.java +/Users/hasingh/IdeaProjects/com.testReport/src/main/java/org/example/search/SimpleSearchEngine/Search.java diff --git a/SCA/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/SCA/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000..f097085 --- /dev/null +++ b/SCA/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1 @@ +org/example/AppTest.class diff --git a/SCA/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/SCA/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..f55f4cf --- /dev/null +++ b/SCA/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +/Users/hasingh/IdeaProjects/com.testReport/src/test/java/org/example/AppTest.java diff --git a/SCA/target/spotbugs-report/spotbugs.html b/SCA/target/spotbugs-report/spotbugs.html new file mode 100644 index 0000000..5c49fcc --- /dev/null +++ b/SCA/target/spotbugs-report/spotbugs.html @@ -0,0 +1,149 @@ + + + + + + SpotBugs Report + + + + +

+ SpotBugs Report

+

Project Information

+

Project: + com.testReport

+

SpotBugs version: 4.8.6

+

Code analyzed:

+
    +
  • /Users/hasingh/IdeaProjects/com.testReport/target/classes
  • +
+

+
+
+

+

Metrics

+

119 lines of code analyzed, + in 6 classes, + in 3 packages.

+ + + + + + + + + + + + + + + + + + + +
MetricTotalDensity*
High Priority Warnings + 0.00
Medium Priority Warnings + 0.00
+ Total Warnings + + 0 + + 0.00 +
+

+ (* Defects per Thousand lines of non-commenting source statements) +

+

+
+
+

+

Contents

+ +

Summary

+ + + + + + + + + +
Warning TypeNumber
+ Total + + 0 +
+

Warnings

+

Click on a warning row to see full context information.

+

+ Details +

+ + diff --git a/SCA/target/spotbugs.xml b/SCA/target/spotbugs.xml new file mode 100644 index 0000000..f3b09d9 --- /dev/null +++ b/SCA/target/spotbugs.xml @@ -0,0 +1,2 @@ + +/Users/hasingh/IdeaProjects/com.testReport/src/main/java/Users/hasingh/IdeaProjects/com.testReport/src/test/java \ No newline at end of file diff --git a/SCA/target/spotbugsXml.xml b/SCA/target/spotbugsXml.xml new file mode 100644 index 0000000..e03b811 --- /dev/null +++ b/SCA/target/spotbugsXml.xml @@ -0,0 +1,2 @@ + +/Users/hasingh/IdeaProjects/com.testReport/target/classes/Users/hasingh/.m2/repository/org/apache/commons/commons-lang3/3.12.0/commons-lang3-3.12.0.jar/Users/hasingh/IdeaProjects/com.testReport/src/main/java/Users/hasingh/IdeaProjects/com.testReport/target \ No newline at end of file diff --git a/SCA/target/surefire-reports/TEST-org.example.AppTest.xml b/SCA/target/surefire-reports/TEST-org.example.AppTest.xml new file mode 100644 index 0000000..ecf54fc --- /dev/null +++ b/SCA/target/surefire-reports/TEST-org.example.AppTest.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SCA/target/surefire-reports/org.example.AppTest.txt b/SCA/target/surefire-reports/org.example.AppTest.txt new file mode 100644 index 0000000..289f47d --- /dev/null +++ b/SCA/target/surefire-reports/org.example.AppTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: org.example.AppTest +------------------------------------------------------------------------------- +Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 s -- in org.example.AppTest diff --git a/SCA/target/test-classes/org/example/AppTest.class b/SCA/target/test-classes/org/example/AppTest.class new file mode 100644 index 0000000..09368e9 Binary files /dev/null and b/SCA/target/test-classes/org/example/AppTest.class differ