-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalysisPreProcessor.java
More file actions
80 lines (70 loc) · 2.91 KB
/
AnalysisPreProcessor.java
File metadata and controls
80 lines (70 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package ie.atu.sw;
import java.util.Scanner;
/**
* The AnalysisPreProcessor class is responsible for preparing the analysis
* by allowing the user to select a similarity calculator and perform
* any necessary preparations before the analysis process starts.
*
* The class interacts with the user to gather the preferred similarity
* metric (Cosine, Euclidean, Manhattan, or Pearson) and then passes the
* selected similarity calculator to the analysis executor.
*/
public class AnalysisPreProcessor {
private SimilarityCalculator similarityCalculator;
private final Scanner scanner;
/**
* Constructs a new AnalysisPreProcessor instance with the provided scanner
*
* @param scanner Instance used to capture user input
*/
public AnalysisPreProcessor(Scanner scanner) {
this.scanner = scanner;
}
/**
* Presenting a sub-menu to the user and allowing them to choose a similarity calculator
* SimilarityCalculator implementation is selected based on user's choice
*
*/
public void prepareAnalysis() { //Big O = O(1)
SubMenuDisplay.printMenu();
int max = 4;
int choice = MenuProcessInput.processInput(max, scanner);
switch (choice) {
case 1 -> {
similarityCalculator = new SimilarityCalculatorCosineImpl();
System.out.println("Cosine Similarity selected.");
}
case 2 -> {
similarityCalculator = new SimilarityCalculatorEuclideanDistanceImpl();
System.out.println("Euclidean Distance selected.");
}
case 3 -> {
similarityCalculator = new SimilarityCalculatorManhattanImpl();
System.out.println("Manhattan Distance selected.");
}
case 4 -> {
similarityCalculator = new SimilarityCalculatorPearsonImpl();
System.out.println("Pearson Distance selected.");
}
default ->{ // this won't happen anyway because option outside 1/4 are not allowed
similarityCalculator = new SimilarityCalculatorCosineImpl();
System.out.println("Invalid choice, defaulting to Cosine Similarity.");
}
}
System.out.println("");
// Now you can return the selected calculator
startAnalysis();
}
/**
* Starts the analysis with the selected SimilarityCalculator.
*/
private void startAnalysis() { //Big O = O(1)
// Pass the chosen similarityCalculator to the AnalysisExecutor
AnalysisExecutor executor = new AnalysisExecutor(similarityCalculator);
try {
executor.executeAnalysis(); // Execute the analysis
} catch (InterruptedException e) {
System.err.println("Analysis interrupted.");
}
}
}