-
Notifications
You must be signed in to change notification settings - Fork 27
Jacob's PR #7
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?
Jacob's PR #7
Changes from all commits
5674da2
483ca02
bbb739e
bb1517c
ebb8712
9aeaac4
ab777c1
5ff575a
6ad6d5f
befbb47
a9c7fc1
b5191a5
9143580
d0fcee5
670d06e
a3049ac
9bd5f1c
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,5 @@ | ||
| In emerald groves, where sunlight dappled through the leaves like liquid gold, there dwelt a nymph of surpassing beauty. Her laughter, like the tinkling of crystal streams, echoed through the glades, and the very flowers bowed their heads in admiration as she passed. Her name was Elara, and she was beloved by all the creatures of the forest. The shy fawns would gather at her feet, unafraid, and the birds would weave their sweetest melodies in her honor. Even the mischievous sprites, who delighted in playing tricks on unsuspecting travelers, would never dream of harming a hair on her head. | ||
|
|
||
| One day, as Elara wandered through the woods, she came across a clearing bathed in an ethereal light. In the center stood a magnificent tree, its branches laden with blossoms of the purest white. Drawn by an irresistible force, Elara approached the tree and gently touched its bark. A shiver ran through her, and she felt a strange energy coursing through her veins. As she gazed up at the tree's crown, she saw a figure materialize amidst the blossoms. It was a young man, tall and handsome, with eyes that sparkled like the stars. He smiled down at Elara, and she felt her heart quicken with a feeling she had never known before. | ||
|
|
||
| The young man introduced himself as Orion, a celestial being who had descended to Earth in search of the most beautiful creature in the land. He had heard tales of Elara's beauty and grace, and he had come to see for himself if the rumors were true. Elara was captivated by Orion's charm and his otherworldly aura. They spent hours talking and laughing, and Elara felt as if she had known him for a lifetime. As the sun began to set, Orion confessed his love for Elara, and she, without hesitation, confessed her love for him. They vowed to meet every day in the clearing, and their love grew stronger with each passing moment. |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| InaguralAddress | ||
|
|
||
| thank you . (applause.) wow . so, as we will flourish and be respected again all over the world . america first . we will flourish and be respected again all over the world . (applause.) wow . soil, including our country will flourish and be respected again all over the world . iâ??m pleased to be respected again all over the world . together, we will flourish and be respected again all over the world . and be respected again all over the world . (applause.) wow . thatâ??s interesting . (applause.) wow . the world . (applause.) wow | ||
|
|
||
| --seams like it gets stuck repeating whole phrases(I know the original text is redundant and insubstantial, but the bot was even worse.) I did search on my txt documents for words in the repeating phrases, and it was choosing low priority words way too often. I think something is still off. | ||
|
|
||
| Geminis generation based on keats training | ||
|
|
||
| in emerald groves, where sunlight dappled through the leaves like liquid gold, there dwelt a nymph of surpassing beauty . they spent hours talking and the leaves like liquid gold, there dwelt a nymph of | ||
| surpassing beauty . he smiled down at her laughter, like liquid gold, there dwelt a nymph of surpassing beauty . one day, as she passed . the leaves like liquid gold, there dwelt a nymph of surpassing beauty . in emerald groves, where sunlight dappled through the leaves like liquid gold, there dwelt a nymph of surpassing beauty . they spent hours talking and the leaves like liquid gold, there dwelt a nymph of surpassing beauty . in emerald groves, where sunlight dappled through the leaves like liquid gold, there dwelt a nymph of surpassing beauty . they spent hours talking and the leaves like liquid gold, there dwelt a nymph of surpassing beauty . |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Scanner; | ||
|
|
||
|
|
@@ -30,7 +31,26 @@ public class LowercaseSentenceTokenizer implements Tokenizer { | |
| */ | ||
| 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<>(); | ||
| while (scanner.hasNext()) { | ||
| String token = scanner.next().toLowerCase(); | ||
| //I was struggling to remember what symbol means any character. I started to realize ".contains()" wasn't the right choice. | ||
| //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){ | ||
|
Comment on lines
+38
to
+41
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, this works! You could also consider using |
||
| String shortStr = ""; | ||
| char[] cArr = token.toCharArray(); | ||
| for(int i=0; i<token.length()-1; i++){ | ||
| shortStr += cArr[i]; | ||
| } | ||
| tokens.add(shortStr); | ||
| tokens.add("."); | ||
|
|
||
| }else{tokens.add(token);} | ||
|
|
||
| } | ||
| return tokens; | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,15 @@ void testTokenizeWithNoCapitalizationOrPeriod() { | |
| /* | ||
| * 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
+22
to
+28
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 |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.LinkedList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Scanner; | ||
| import java.util.Random; | ||
|
|
||
| /** | ||
| * A class for predicting the next word in a sequence using a unigram model. | ||
|
|
@@ -50,9 +52,64 @@ public UnigramWordPredictor(Tokenizer tokenizer) { | |
| */ | ||
| public void train(Scanner scanner) { | ||
| List<String> trainingWords = tokenizer.tokenize(scanner); | ||
|
|
||
| // TODO: Convert the trainingWords into neighborMap here | ||
| } | ||
| neighborMap = new HashMap<>(); | ||
|
|
||
|
|
||
| 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); | ||
| } | ||
| } | ||
|
Comment on lines
+60
to
+73
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! |
||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| // //check if the token has been completed and added. | ||
| // if(!neighborMap.containsKey(mKey)){ | ||
|
|
||
| // tempVals = new LinkedList<>(); | ||
| // //find the token and add the next word to tempVals | ||
| // for(int j=0; j<trainingWords.size(); j++){ | ||
|
|
||
| // //this little if statement was a nightmare for me. I wasn't failing any tests, but my map wasn't correct. I'm not sure if there is a bug in the test | ||
| // //I used 12 println statements with descriptions and variables and finally realized my if statement was running false when it should be true. | ||
| // //you can probably guess what I did wrong but I could not figure out why it was false. I finally found someone on stack overflow with a similar issue. | ||
| // //I forgot Strings are objects and I needed to use .equals() rather than == | ||
| // if(mKey.equals(trainingWords.get(j)) && j != (trainingWords.size()-1)){ | ||
| // tempVals.add(trainingWords.get(j+1)); | ||
|
|
||
| // //System.out.println("updating " + mKey + " with " + trainingWords.get(j+1)); | ||
| // //System.out.println(mKey + " = " + tempVals + " " + i + " " + j); | ||
| // } | ||
|
|
||
| // } | ||
| // //add in the token, and list of values stored | ||
| // neighborMap.put(mKey, tempVals); | ||
|
|
||
| // }else{ | ||
|
|
||
| // } | ||
|
|
||
| //System.out.println(getNeighborMap()); | ||
|
|
||
|
|
||
| /** | ||
| * Predicts the next word based on the given context. | ||
|
|
@@ -99,9 +156,19 @@ public void train(Scanner scanner) { | |
| * @return the predicted next word, or null if no prediction can be made | ||
| */ | ||
| 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; | ||
|
Comment on lines
158
to
+171
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! |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -119,7 +186,7 @@ public Map<String, List<String>> getNeighborMap() { | |
| List<String> newList = new ArrayList<>(entry.getValue()); | ||
| copy.put(entry.getKey(), newList); | ||
| } | ||
|
|
||
| System.out.println(copy); | ||
| return copy; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| a b c 1 a 1 b 1 c |
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.
Remember to use interface types where appropriate (List)