Skip to content

Jacob's PR#7

Open
JacobWoodbury wants to merge 17 commits intogrc-cohort-21:mainfrom
JacobWoodbury:main
Open

Jacob's PR#7
JacobWoodbury wants to merge 17 commits intogrc-cohort-21:mainfrom
JacobWoodbury:main

Conversation

@JacobWoodbury
Copy link

No description provided.

Copy link

@auberonedu auberonedu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job!

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){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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<>();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice test!

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);
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice logic!

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants