Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Pokemonthemesong.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
I wanna be the very best
Like no one ever was
To catch them is my real test
To train them is my cause
I will travel across the land
Searching far and wide
Teach Pokémon to understand
The power that's inside
Pokémon (gotta catch 'em all), it's you and me
I know it's my destiny (Pokémon)
Oh, you're my best friend
In a world we must defend
Pokémon (gotta catch 'em all), a heart so true
Our courage will pull us through
You teach me and I'll teach you
Pokémon (gotta catch 'em all)
Gotta catch 'em all, yeah
Every challenge along the way
With courage I will face
I will battle every day
To claim my rightful place
Come with me, the time is right
There's no better team
Arm in arm, we'll win the fight
It's always been our dream
Pokémon (gotta catch 'em all), it's you and me
I know it's my destiny (Pokémon)
Oh, you're my best friend
In a world we must defend
Pokémon (gotta catch 'em all), a heart so true
Our courage will pull us through
You teach me and I'll teach you
Pokémon (gotta catch 'em all)
Gotta catch 'em all
Gotta catch 'em all
Gotta catch 'em all
Gotta catch 'em all
Yeah
Pokémon (gotta catch 'em all), it's you and me
I know it's my destiny (Pokémon)
Oh, you're my best friend
In a world we must defend
Pokémon (gotta catch 'em all), a heart so true
Our courage will pull us through
You teach me and I'll teach you
Pokémon (gotta catch 'em all)
Gotta catch 'em all, Pokémon
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,6 @@ Consider doing any of the following (some are very hard!):
## Submitting
Submit your project by making a PR and copying the link to the canvas assignment.

TURN SOMETHING IN BY THE DUE DATE EVEN IF YOU'RE NOT FINISHED.
TURN SOMETHING IN BY THE DUE DATE EVEN IF YOU'RE NOT FINISHED.

//The End.
4 changes: 3 additions & 1 deletion keatsTraining.txt
Original file line number Diff line number Diff line change
Expand Up @@ -404,4 +404,6 @@ Were foil'd, who watch'd to trace them to their house:
And but the flitter-winged verse must tell,
For truth's sake, what woe afterwards befel,
'Twould humour many a heart to leave them thus,
Shut from the busy world of more incredulous.
Shut from the busy world of more incredulous.

.....End
1 change: 1 addition & 0 deletions rambleBotOutput.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
i will pull us through you pokémon (gotta catch 'em all) gotta catch 'em all) gotta catch 'em all), it's you pokémon (gotta catch 'em all gotta catch 'em all), it's my best friend in a world we must defend pokémon (gotta catch 'em all), it's you teach me i know it's always been our courage will pull us through you and i'll teach you and me i will pull us through you pokémon (gotta catch 'em all, yeah pokémon (gotta catch 'em all), a world we must defend pokémon (gotta catch 'em all), it's you teach pokémon (gotta catch

Choose a reason for hiding this comment

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

gotta catch 'em all

28 changes: 25 additions & 3 deletions src/LowercaseSentenceTokenizer.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
* A tokenizer that converts text input to lowercase and splits it
* into a list of tokens, where each token is either a word or a period.
*/
public class LowercaseSentenceTokenizer implements Tokenizer {
public class LowercaseSentenceTokenizer implements Tokenizer
{
/**
* Tokenizes the text from the given Scanner. The method should
* convert the text to lowercase and split it into words and periods.
Expand All @@ -28,9 +30,29 @@ public class LowercaseSentenceTokenizer implements Tokenizer {
* @param scanner the Scanner to read the input text from
* @return a list of tokens, where each token is a word or a period
*/
public List<String> tokenize(Scanner scanner) {
public List<String> tokenize(Scanner scanner) //scanner object named object
{
// TODO: Implement this function to convert the scanner's input to a list of words and periods
return null;
List<String> list = new ArrayList<>(); //creating


while(scanner.hasNext()) //looking at the first word and putting it into the list
{
String word = scanner.next().toLowerCase(); //looks at the beginning of the word to see if it exists then adds with .add.
//.toLowerCase sets the string to all lower case letters

if (word.endsWith(".")) //we want to check the period. at the end of the sentence

Choose a reason for hiding this comment

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

Nice!

{
list.add(word.substring(0, word.length() -1)); // adding the word w/o period. //set the first one the way you want inclusive. word.length returns the entire word. word.length() - 1 will be exclusive
list.add(".");//adding the period
}
else
{
list.add(word); //now just add the word
}
}

return list;
}
}

17 changes: 13 additions & 4 deletions src/LowercaseSentenceTokenizerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import java.util.Scanner;
import static org.junit.jupiter.api.Assertions.*;

class LowercaseSentenceTokenizerTest {
class LowercaseSentenceTokenizerTest
{

// Wave 1
@Test
Expand All @@ -16,9 +17,17 @@ void testTokenizeWithNoCapitalizationOrPeriod() {
}

// Wave 2
/*
* Write your test here!
*/
@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 +20 to +29

Choose a reason for hiding this comment

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

Nice test!




// Wave 3
Expand Down
67 changes: 56 additions & 11 deletions src/UnigramWordPredictor.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
import java.util.Map;
import java.util.Scanner;


/**
* A class for predicting the next word in a sequence using a unigram model.
* The model is trained on input text and maps each word to a list of
* words that directly follow it in the text.
*/
public class UnigramWordPredictor implements WordPredictor {
private Map<String, List<String>> neighborMap;
private Tokenizer tokenizer;
public class UnigramWordPredictor implements WordPredictor
{
private Map<String, List<String>> neighborMap; //Map instance variable named neighborhoodMap
private Tokenizer tokenizer; //instance variable named tokenizer

/**
* Constructs a UnigramWordPredictor with the specified tokenizer.
*
* @param tokenizer the tokenizer used to process the input text
*/
public UnigramWordPredictor(Tokenizer tokenizer) {
public UnigramWordPredictor(Tokenizer tokenizer)
{
this.tokenizer = tokenizer;
}

Expand Down Expand Up @@ -48,10 +51,39 @@ public UnigramWordPredictor(Tokenizer tokenizer) {
*
* @param scanner the Scanner to read the training text from
*/
public void train(Scanner scanner) {
List<String> trainingWords = tokenizer.tokenize(scanner);
public void train(Scanner scanner) //method called train passing in Scanner named scanner
{
List<String> trainingWords = tokenizer.tokenize(scanner); //traingWords will contain list of strings from a file, since we cant pass a file. Training words object is now the cup that holds the string of words here..
neighborMap = new HashMap<>(); //initialize neighborMap...neighborMap is the whole key, value map of strings.
//[1][2][3][4][5] number qty size
//[0][1][2][3][4] number index

for (int i = 0; i < trainingWords.size(); i++) //iterate through the list
{
String keyWord = trainingWords.get(i); //creating keyword // String keyWordNext = trainingWords.get(i + 1); //creating next keyword

if(!neighborMap.containsKey(keyWord))
{

List<String> keyValue = new ArrayList<>(); //creating a list called keyValue

for(int j = 0; j < trainingWords.size(); j++)
{

// TODO: Convert the trainingWords into neighborMap here

if(keyWord.equals(trainingWords.get(j)) && j + 1 < trainingWords.size()) //checks the values that are in keyWord and trainingWords and see if the values in index j matches.
{
int k = j + 1; //storing index j + 1 to a variable
keyValue.add(trainingWords.get(k)); //actually doing something after the iterating. with .add by adding the string in the position of keyWordNext.
}
Comment on lines +70 to +78

Choose a reason for hiding this comment

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

Nice logic!


}
neighborMap.put(keyWord, keyValue); //the key in the map will be the strings from training words named keyWord. The value in this position is an arrayList named keyValue.
//how do i extract the words from trainingWords and put the unique words into neighborMap
}
}


}

/**
Expand Down Expand Up @@ -97,11 +129,22 @@ public void train(Scanner scanner) {
*
* @param context a list of words representing the current context
* @return the predicted next word, or null if no prediction can be made
*
* //[1][2][3][4][5] number qty size
//[0][1][2][3][4] number index
*/
public String predictNextWord(List<String> context) {
public String predictNextWord(List<String> context) //list of Strings named context
{
// TODO: Return a predicted word given the words preceding it

String lastWord = context.get(context.size() -1); //size will start with 1. index is 0. Get will want to get a number.

List<String> chosenList = neighborMap.get(lastWord); //getting last
int randomly = (int)(Math.random() * chosenList.size()); //using math.random to autogenerate
return chosenList.get(randomly);
Comment on lines +140 to +144

Choose a reason for hiding this comment

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

great logic!


// Hint: only the last word in context should be looked at
return null;
//return null;
}

/**
Expand All @@ -112,10 +155,12 @@ public String predictNextWord(List<String> context) {
*
* @return a copy of the neighbor map
*/
public Map<String, List<String>> getNeighborMap() {
public Map<String, List<String>> getNeighborMap()
{
Map<String, List<String>> copy = new HashMap<>();

for (Map.Entry<String, List<String>> entry : neighborMap.entrySet()) {
for (Map.Entry<String, List<String>> entry : neighborMap.entrySet())
{
List<String> newList = new ArrayList<>(entry.getValue());
copy.put(entry.getKey(), newList);
}
Expand Down
6 changes: 4 additions & 2 deletions src/UnigramWordPredictorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import java.util.Map;
import static org.junit.jupiter.api.Assertions.*;

class UnigramWordPredictorTest {
class UnigramWordPredictorTest
{

// Wave 4
/**
Expand All @@ -25,7 +26,8 @@ class UnigramWordPredictorTest {
* The test does not care about the order of the map or the lists.
*/
@Test
void testTrainAndGetNeighborMap() {
void testTrainAndGetNeighborMap()
{
// Use a fake tokenizer with predefined tokens
FakeTokenizer fakeTokenizer = new FakeTokenizer(
List.of("the", "cat", "sat", ".", "the", "cat", "slept", ".", "the", "dog", "barked", ".")
Expand Down