-
Notifications
You must be signed in to change notification settings - Fork 27
rambleBot Assignment #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c067bce
581d2bd
5afcc15
ba2e5aa
781fd4e
617b675
dac26a3
aca4509
45f880b
fb14083
46fa907
aed8543
db9d662
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| 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 | ||
| 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. | ||
|
|
@@ -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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,8 @@ | |
| import java.util.Scanner; | ||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| class LowercaseSentenceTokenizerTest { | ||
| class LowercaseSentenceTokenizerTest | ||
| { | ||
|
|
||
| // Wave 1 | ||
| @Test | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice test! |
||
|
|
||
|
|
||
|
|
||
| // Wave 3 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
| } | ||
|
|
||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -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); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gotta catch 'em all