-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update hit term extractor to use scores when considering hit terms
- Loading branch information
1 parent
b087ac9
commit 7327e3d
Showing
6 changed files
with
204 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
warehouse/query-core/src/main/java/datawave/query/iterator/logic/WordsAndScores.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package datawave.query.iterator.logic; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Set; | ||
|
||
public class WordsAndScores { | ||
private final ArrayList<String> words; | ||
private final ArrayList<Integer> scores; | ||
|
||
private int longestWordIndex; | ||
private int biggestScoreIndex; | ||
private int arrSize; | ||
|
||
public static final Set<String> STOP_WORD_LIST = Set.of("<eps>"); | ||
|
||
public WordsAndScores() { | ||
words = new ArrayList<>(); | ||
scores = new ArrayList<>(); | ||
longestWordIndex = -1; | ||
biggestScoreIndex = -1; | ||
arrSize = 0; | ||
} | ||
|
||
public void addTerm(String word, int score) { | ||
arrSize++; | ||
words.add(word); | ||
scores.add(score); | ||
if (arrSize > 1) { | ||
if (word.length() > words.get(arrSize - 2).length()) { | ||
longestWordIndex = arrSize - 1; | ||
} | ||
if (score <= scores.get(arrSize - 2) && score >= 0) { | ||
if (score < scores.get((arrSize - 2))) { | ||
biggestScoreIndex = arrSize - 1; | ||
} else { | ||
if (word.length() > words.get(biggestScoreIndex).length()) { | ||
biggestScoreIndex = arrSize - 1; | ||
} | ||
} | ||
} | ||
} else { | ||
longestWordIndex = 0; | ||
biggestScoreIndex = 0; | ||
} | ||
} | ||
|
||
public void addTerm(String word) { | ||
arrSize++; | ||
words.add(word); | ||
scores.add(-1); | ||
if (arrSize > 1) { | ||
if (word.length() > words.get(arrSize - 2).length()) { | ||
longestWordIndex = arrSize - 1; | ||
} | ||
} else { | ||
longestWordIndex = 0; | ||
} | ||
} | ||
|
||
public String getWordToOutput() { | ||
if (biggestScoreIndex != -1 && scores.get(biggestScoreIndex) != -1) { | ||
return words.get(biggestScoreIndex); | ||
} else { | ||
return words.get(longestWordIndex); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters