Skip to content

Commit

Permalink
change output score to 0-1
Browse files Browse the repository at this point in the history
  • Loading branch information
austin007008 committed May 9, 2024
1 parent f25999b commit 389fcd2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,17 @@ public String getWordToOutput() {
/**
* Converts the score into a number from 0-1000 (higher is better) so that it is easier for the user to understand.
*/
private int userReadable(int score) {
return Math.max(1000 - (score / 50000), 0);
private String userReadable(int score) {
// return Math.max(1000 - (score / 50000), 0);
int x = Math.max(1000 - (score / 50000), 0);
if (x == 0) {
return String.valueOf(0);
} else if (x == 1000) {
return String.valueOf(1);
} else {
String y = String.format("%.3f", (float) x / 1000);
return y.substring(1);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class WordsAndScoresTest {
public void testSingleWordScoreAdd() {
WordsAndScores ws = new WordsAndScores();
ws.addTerm("test", 100, hitTermsList);
assertEquals("test(1000)", ws.getWordToOutput());
assertEquals("test(1)", ws.getWordToOutput());
assertTrue(ws.getUseScores());
}

Expand All @@ -42,7 +42,7 @@ public void testReturnSmallestScore() {
ws.addTerm("here", 49883548, hitTermsList);
ws.addTerm("datawave", 24734968, hitTermsList);
ws.addTerm("cat", 4999951, hitTermsList);
assertEquals("cat(901)", ws.getWordToOutput());
assertEquals("cat(.901)", ws.getWordToOutput());
assertTrue(ws.getUseScores());
}

Expand All @@ -68,7 +68,7 @@ public void testReturnMixedAddScoreFirst() {
ws.addTerm("here", 5239977, hitTermsList);
ws.addTerm("datawave", hitTermsList);
ws.addTerm("cat", 9707535, hitTermsList);
assertEquals("test(924)", ws.getWordToOutput());
assertEquals("test(.924)", ws.getWordToOutput());
assertTrue(ws.getUseScores());
}

Expand All @@ -81,7 +81,7 @@ public void testReturnMixedAddNoScoreFirst() {
ws.addTerm("here", 730921, hitTermsList);
ws.addTerm("datawave", hitTermsList);
ws.addTerm("cat", 11232252, hitTermsList);
assertEquals("here(986)", ws.getWordToOutput());
assertEquals("here(.986)", ws.getWordToOutput());
assertTrue(ws.getUseScores());
}

Expand Down Expand Up @@ -150,14 +150,14 @@ public void testReturnSingleHit() {
public void testReturnSingleHitWithScore() {
WordsAndScores ws = new WordsAndScores();
ws.addTerm("hit", 9120447, hitTermsList);
assertEquals("[hit](818)", ws.getWordToOutput());
assertEquals("[hit](.818)", ws.getWordToOutput());
ws.addTerm("try", 41315662, hitTermsList);
assertEquals("[hit](818)", ws.getWordToOutput());
assertEquals("[hit](.818)", ws.getWordToOutput());
ws.reset();
ws.addTerm("hello", 31334736, hitTermsList);
assertEquals("hello(374)", ws.getWordToOutput());
assertEquals("hello(.374)", ws.getWordToOutput());
ws.addTerm("hit", 29938894, hitTermsList);
assertEquals("[hit](402)", ws.getWordToOutput());
assertEquals("[hit](.402)", ws.getWordToOutput());
}

@Test
Expand Down Expand Up @@ -199,7 +199,7 @@ public void testReturnScoreMultipleHit() {
ws.addTerm("here", 17286266, temp);
ws.addTerm("term", 37536662, temp);
ws.addTerm("cat", temp);
assertEquals("[hit](695)", ws.getWordToOutput());
assertEquals("[hit](.695)", ws.getWordToOutput());
}

@Test
Expand Down

0 comments on commit 389fcd2

Please sign in to comment.