Skip to content

Completed RambleApp#24

Open
maple-johnson wants to merge 13 commits intogrc-cohort-21:mainfrom
maple-johnson:main
Open

Completed RambleApp#24
maple-johnson wants to merge 13 commits intogrc-cohort-21:mainfrom
maple-johnson:main

Conversation

@maple-johnson
Copy link

Completed all 6 waves.

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.

Great job! Looks like it's missing your output though

Comment on lines +45 to +46
if (punctuationCheck.endsWith(".") || punctuationCheck.endsWith("?") || punctuationCheck.endsWith("!"))
{

Choose a reason for hiding this comment

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

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

}

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

Choose a reason for hiding this comment

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

Fun changes!


// TODO: Convert the trainingWords into neighborMap here
// Map
Map<String, List<String>> prepNeighborMap = new HashMap<String, List<String>>();

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

Nice logic!

public String predictNextWord(List<String> context)
{
// Generating list of next word options
List<String> contextList = neighborMap.get(context.getLast());

Choose a reason for hiding this comment

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

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!

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