Open
Conversation
… regardless of spacing.
…a, in order to verify proper map creation/sorting.
…hborMap, and connected them to neighborMap. Additionally, incorporated a null check.
…ed to fix index boundary issue.
auberonedu
reviewed
Feb 18, 2025
auberonedu
left a comment
There was a problem hiding this comment.
Great job! Looks like it's missing your output though
Comment on lines
+45
to
+46
| if (punctuationCheck.endsWith(".") || punctuationCheck.endsWith("?") || punctuationCheck.endsWith("!")) | ||
| { |
There was a problem hiding this comment.
Cool handling of other punctuation!
Comment on lines
+19
to
+30
| @Test | ||
| void testTokenizeSpaces() | ||
| { | ||
| // Arrange | ||
| LowercaseSentenceTokenizer tokenizer = new LowercaseSentenceTokenizer(); | ||
| Scanner scanner = new Scanner("hello hi hi hi hello hello"); | ||
| // Act | ||
| List<String> tokens = tokenizer.tokenize(scanner); | ||
| // Assert | ||
| assertEquals(List.of("hello", "hi", "hi", "hi", "hello", "hello"), tokens); | ||
|
|
||
| } |
Comment on lines
+151
to
+166
| try | ||
| { | ||
| // https://stackoverflow.com/questions/2885173/how-do-i-create-a-file-and-write-to-it | ||
| // Used the FileWriter section of the post by Derek Hill to get how to write to a file without overwriting. | ||
| FileWriter outputFile = new FileWriter("rambleOutput.txt", true); // Append true to continue writing to a file | ||
|
|
||
| if (nextWord.equals(".") || nextWord.equals("?") || nextWord.equals("!")) | ||
| { | ||
| outputFile.write(nextWord); | ||
| } | ||
| else | ||
| { | ||
| outputFile.write(" " + nextWord); | ||
| } | ||
|
|
||
| outputFile.close(); |
|
|
||
| // TODO: Convert the trainingWords into neighborMap here | ||
| // Map | ||
| Map<String, List<String>> prepNeighborMap = new HashMap<String, List<String>>(); |
There was a problem hiding this comment.
You can use <> here and Java will infer the type
Comment on lines
+61
to
+82
| for (int i = 0; i < trainingWords.size() -1; i++) | ||
| { | ||
| // Test for null | ||
| if (trainingWords.get(i + 1) == null) | ||
| { | ||
| break; | ||
| } | ||
| else if (!prepNeighborMap.containsKey(trainingWords.get(i))) // If the token from trainingWords doesn't exist as a key in prepNeighborMap, create one | ||
| { | ||
| List<String> addList = new ArrayList<String>(); | ||
| addList.add(trainingWords.get(i + 1)); // Add the next token from trainingWords to a new list | ||
|
|
||
| prepNeighborMap.put(trainingWords.get(i), addList); | ||
| } | ||
| else // If the token from trainingWords exists as a key in prepNeighborMap, add new token to list | ||
| { | ||
| List<String> addList = prepNeighborMap.get(trainingWords.get(i)); // Create a new list from the existing list based on the key | ||
| addList.add(trainingWords.get(i + 1)); // Add new list item | ||
|
|
||
| prepNeighborMap.put(trainingWords.get(i), addList); | ||
| } | ||
|
|
| public String predictNextWord(List<String> context) | ||
| { | ||
| // Generating list of next word options | ||
| List<String> contextList = neighborMap.get(context.getLast()); |
There was a problem hiding this comment.
I didn't know about getLast! Looks like it was introduced in a newer version of Java than my tests use, so that's why the tests aren't working on GitHub. Great job though!
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Completed all 6 waves.