Conversation
…igure out I was itteration on i in my second loop instead of j. Also fixed the issue with tempVals not clearing after a key was finished.
…hy we are using a List to pass in context rather than a word.
auberonedu
reviewed
Feb 18, 2025
Comment on lines
+38
to
+41
| //I started searching the matches method on w3Schools and came across the lastIndexOf() Method | ||
| //https://www.w3schools.com/java/ref_string_lastindexof.asp | ||
|
|
||
| if(token.lastIndexOf(".") == token.length()-1){ |
There was a problem hiding this comment.
Nice, this works! You could also consider using endsWith
| public List<String> tokenize(Scanner scanner) { | ||
| // TODO: Implement this function to convert the scanner's input to a list of words and periods | ||
| return null; | ||
| ArrayList<String> tokens = new ArrayList<>(); |
There was a problem hiding this comment.
Remember to use interface types where appropriate (List)
Comment on lines
+22
to
+28
| @Test | ||
| void testTokenizeWithSpaces(){ | ||
| LowercaseSentenceTokenizer tokenizer = new LowercaseSentenceTokenizer(); | ||
| Scanner scanner = new Scanner("hello hi hi hi hello hello"); | ||
| List<String> tokens = tokenizer.tokenize(scanner); | ||
| assertEquals(List.of("hello", "hi", "hi", "hi", "hello", "hello"), tokens); | ||
| } |
Comment on lines
+60
to
+73
| for(int i=0; i < trainingWords.size()-1; i++){ | ||
| //create a variable to store map keys and next word. | ||
| String mKey = trainingWords.get(i); | ||
| String nextWord = trainingWords.get(i+1); | ||
| List<String> tempVals = new LinkedList<>(); | ||
|
|
||
| //update temp with previous values. | ||
| if(neighborMap.containsKey(mKey)){ | ||
| neighborMap.get(mKey).add(nextWord); | ||
| }else{ | ||
| tempVals.add(nextWord); | ||
| neighborMap.put(mKey, tempVals); | ||
| } | ||
| } |
Comment on lines
158
to
+171
| public String predictNextWord(List<String> context) { | ||
| List<String> vals = new LinkedList<>(); | ||
| String lastWord = context.get(context.size()-1); | ||
| // random number research: https://www.tutorialspoint.com/java/util/random_nextint_inc_exc.htm | ||
| Random picker = new Random(); | ||
| String choice =""; | ||
| // TODO: Return a predicted word given the words preceding it | ||
| if(neighborMap.containsKey(lastWord)){ | ||
| vals = neighborMap.get(lastWord); | ||
| choice = vals.get(picker.nextInt(vals.size())); | ||
| } | ||
|
|
||
| // Hint: only the last word in context should be looked at | ||
| return null; | ||
| return choice; |
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.
No description provided.