Skip to content

Commit 8162d6c

Browse files
author
prayas7102
committed
checkstyle issues resolved
1 parent 1fabcc7 commit 8162d6c

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/main/java/com/thealgorithms/searches/BM25InvertedIndex.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Movie {
2828
* @param releaseYear Release year of the movie.
2929
* @param content Content or description of the movie.
3030
*/
31-
public Movie(int docId, String name, double imdbRating, int releaseYear, String content) {
31+
Movie(int docId, String name, double imdbRating, int releaseYear, String content) {
3232
this.docId = docId;
3333
this.name = name;
3434
this.imdbRating = imdbRating;
@@ -61,7 +61,7 @@ class SearchResult {
6161
* @param docId Document ID (movie) for this search result.
6262
* @param relevanceScore The relevance score based on BM25 scoring.
6363
*/
64-
public SearchResult(int docId, double relevanceScore) {
64+
SearchResult(int docId, double relevanceScore) {
6565
this.docId = docId;
6666
this.relevanceScore = relevanceScore;
6767
}
@@ -78,8 +78,12 @@ public String toString() {
7878

7979
@Override
8080
public boolean equals(Object o) {
81-
if (this == o) return true;
82-
if (o == null || getClass() != o.getClass()) return false;
81+
if (this == o) {
82+
return true;
83+
}
84+
if (o == null || getClass() != o.getClass()) {
85+
return false;
86+
}
8387
SearchResult that = (SearchResult) o;
8488
return docId == that.docId && Double.compare(that.relevanceScore, relevanceScore) == 0;
8589
}
@@ -99,14 +103,14 @@ public final class BM25InvertedIndex {
99103
private Map<Integer, Movie> movies; // Mapping of movie document IDs to Movie objects
100104
private int totalDocuments; // Total number of movies/documents
101105
private double avgDocumentLength; // Average length of documents (number of words)
102-
private static final double k = 1.5; // BM25 tuning parameter, controls term frequency saturation
103-
private static final double b = 0.75; // BM25 tuning parameter, controls length normalization
106+
private static final double K = 1.5; // BM25 tuning parameter, controls term frequency saturation
107+
private static final double B = 0.75; // BM25 tuning parameter, controls length normalization
104108

105109
/**
106110
* Constructor for BM25InvertedIndex.
107111
* Initializes the inverted index and movie storage.
108112
*/
109-
public BM25InvertedIndex() {
113+
BM25InvertedIndex() {
110114
index = new HashMap<>();
111115
movies = new HashMap<>();
112116
totalDocuments = 0;
@@ -192,8 +196,8 @@ public List<SearchResult> search(String term) {
192196
* @return The BM25 relevance score for the term in the document.
193197
*/
194198
private double computeBM25Score(int termFrequency, double docLength, double idf) {
195-
double numerator = termFrequency * (k + 1);
196-
double denominator = termFrequency + k * (1 - b + b * (docLength / avgDocumentLength));
199+
double numerator = termFrequency * (K + 1);
200+
double denominator = termFrequency + K * (1 - B + B * (docLength / avgDocumentLength));
197201
return idf * (numerator / denominator);
198202
}
199203

0 commit comments

Comments
 (0)