Skip to content

Finished Ramblebot project#9

Open
HunterYates wants to merge 7 commits intogrc-cohort-21:mainfrom
HunterYates:main
Open

Finished Ramblebot project#9
HunterYates wants to merge 7 commits intogrc-cohort-21:mainfrom
HunterYates:main

Conversation

@HunterYates
Copy link

My training data is quite large but I believe it is 100% worth it.

Hunter Y added 7 commits January 27, 2025 15:48
…fixed a bug in how periods were handled in the tokenize method
…test in UnigramWordPredictorTest is passing
…/fear_and_loathing.txt for having the entire Fear And Loathing book in .txt format free online) and ensured the results were ridiculous. working as intended
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 +1 to +4
Fear And Loathing In Las Vegas
A Savage Journey To The Heart Of The American Dream

By Hunter S. Thompson

Choose a reason for hiding this comment

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

I've been meaning to read this! I liked what I read of Fear and Loathing on the Campaign Trail.

Comment on lines +1 to +2
fear and beat cooling down at a grey formica shelf where my attorney's naked fourteen year of vegas for a doctor of course, that the ship's bells tolled frantically, the chp and i wondered if the wheel . "jesus christ," he said . a series of their shotguns,
about ten - was a polynesian bar, drinking singapore slings with his eyes were coming to try to boulder highway . "i'm the ford was shocked to catch us under the silver blade away and scour the fbi make that skunk from her trailer last long as he finally . some

Choose a reason for hiding this comment

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

Deep

return null;
}
}
// I referenced this to remember string methods https://www.w3schools.com/java/java_ref_string.asp

Choose a reason for hiding this comment

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

Thanks for citing your source!

Comment on lines +36 to +47
while (scanner.hasNext()) {
String token = scanner.next().toLowerCase();
// I originally used a -1 to target the index at the end of the string but soon realized that is used for python but not java
if (token.endsWith(".")) {
token = token.substring(0, (token.length() - 1));
tokenList.add(token);
tokenList.add(".");
}
else {
tokenList.add(token);
}
}

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 +22 to +29
@Test
void testTokenizeWithManySpaces() {
LowercaseSentenceTokenizer tokenizer = new LowercaseSentenceTokenizer();
Scanner scanner = new Scanner("hello hi hi hi hello hello this text has many spaces");
List<String> tokens = tokenizer.tokenize(scanner);

assertEquals(List.of("hello", "hi", "hi", "hi", "hello", "hello", "this", "text", "has", "many", "spaces"), tokens);
}

Choose a reason for hiding this comment

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

Nice test!

*/
public void train(Scanner scanner) {
List<String> trainingWords = tokenizer.tokenize(scanner);
this.neighborMap = 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 just use <> and Java should infer the generic types.

Comment on lines +56 to +66
for (String token : trainingWords) {
if (!this.neighborMap.containsKey(token)) {
List<String> followingTokens = new ArrayList<String>();
for (int i = 0; i < trainingWords.size(); i++) {
if (trainingWords.get(i).equals(token) && i != (trainingWords.size() - 1)) {
followingTokens.add(trainingWords.get(i + 1));
}
}
this.neighborMap.put(token, followingTokens);
}
}

Choose a reason for hiding this comment

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

Nice!

Comment on lines +116 to +120
Random gen = new Random();
String currentWord = context.get(context.size() - 1);
int randomSelection = gen.nextInt(this.neighborMap.get(currentWord).size());
String predictedWord = this.neighborMap.get(currentWord).get(randomSelection);
return predictedWord;

Choose a reason for hiding this comment

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

Good variable names

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