From b238a4d2948d0c0d442e6a1e780beede5d15f9ad Mon Sep 17 00:00:00 2001 From: xavierb <194048107+xavierb117@users.noreply.github.com> Date: Tue, 21 Jan 2025 11:48:05 -0800 Subject: [PATCH 01/11] Added a sentence in README for a test --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e57375e..a725fce 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # ramblebot +(THIS IS A TEST!!!) + A project to exercise Java, JUnit, git, GitHub, and code-reading skills. Students will create a language model to generate text. ## Expectations From 44664b17643eeca13d56b3990bf74c6d28c51742 Mon Sep 17 00:00:00 2001 From: xavierb <194048107+xavierb117@users.noreply.github.com> Date: Fri, 24 Jan 2025 23:00:11 -0800 Subject: [PATCH 02/11] Wave 1 - Implemented tokenize method --- src/LowercaseSentenceTokenizer.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/LowercaseSentenceTokenizer.java b/src/LowercaseSentenceTokenizer.java index cc8285d..5a4d723 100644 --- a/src/LowercaseSentenceTokenizer.java +++ b/src/LowercaseSentenceTokenizer.java @@ -1,3 +1,4 @@ +import java.util.ArrayList; import java.util.List; import java.util.Scanner; @@ -30,7 +31,14 @@ public class LowercaseSentenceTokenizer implements Tokenizer { */ public List tokenize(Scanner scanner) { // TODO: Implement this function to convert the scanner's input to a list of words and periods - return null; + List tokenizedList = new ArrayList<>(); + + while (scanner.hasNext()) { + String token = scanner.next(); + tokenizedList.add(token); + } + + return tokenizedList; } } From d78316a7ba857fdbc2a9100adf9e6fbaeb4af3e7 Mon Sep 17 00:00:00 2001 From: xavierb <194048107+xavierb117@users.noreply.github.com> Date: Fri, 24 Jan 2025 23:31:28 -0800 Subject: [PATCH 03/11] Wave 2 - Added another test for many spaces --- src/LowercaseSentenceTokenizerTest.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/LowercaseSentenceTokenizerTest.java b/src/LowercaseSentenceTokenizerTest.java index 85ac3a2..32b2704 100644 --- a/src/LowercaseSentenceTokenizerTest.java +++ b/src/LowercaseSentenceTokenizerTest.java @@ -16,10 +16,14 @@ void testTokenizeWithNoCapitalizationOrPeriod() { } // Wave 2 - /* - * Write your test here! - */ - + @Test + void testTokenizeWithManySpaces() { + LowercaseSentenceTokenizer tokenizer = new LowercaseSentenceTokenizer(); + Scanner scanner = new Scanner("hello hi hi hi hello hello"); + List tokens = tokenizer.tokenize(scanner); + + assertEquals(List.of("hello", "hi", "hi", "hi", "hello", "hello"), tokens); + } // Wave 3 @Test From f74850ca4ebfc4a128e170db4f1e5f6c9aba7e7a Mon Sep 17 00:00:00 2001 From: xavierb <194048107+xavierb117@users.noreply.github.com> Date: Sun, 26 Jan 2025 22:03:43 -0800 Subject: [PATCH 04/11] Wave 3 - Added toLowerCase for case sensitivity --- src/LowercaseSentenceTokenizer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/LowercaseSentenceTokenizer.java b/src/LowercaseSentenceTokenizer.java index 5a4d723..7ebb1c4 100644 --- a/src/LowercaseSentenceTokenizer.java +++ b/src/LowercaseSentenceTokenizer.java @@ -35,9 +35,10 @@ public List tokenize(Scanner scanner) { while (scanner.hasNext()) { String token = scanner.next(); + token = token.toLowerCase(); tokenizedList.add(token); } - + return tokenizedList; } } From da1fa09ba6abf55d57d79ffc47ceb953f0f22c8f Mon Sep 17 00:00:00 2001 From: xavierb <194048107+xavierb117@users.noreply.github.com> Date: Sun, 26 Jan 2025 22:27:03 -0800 Subject: [PATCH 05/11] Wave 3 - Initial solution for periods --- src/LowercaseSentenceTokenizer.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/LowercaseSentenceTokenizer.java b/src/LowercaseSentenceTokenizer.java index 7ebb1c4..f38a7a0 100644 --- a/src/LowercaseSentenceTokenizer.java +++ b/src/LowercaseSentenceTokenizer.java @@ -36,9 +36,15 @@ public List tokenize(Scanner scanner) { while (scanner.hasNext()) { String token = scanner.next(); token = token.toLowerCase(); - tokenizedList.add(token); + if (token.charAt(token.length() - 1) == '.') { + String period = token.charAt(token.length() - 1) + ""; + tokenizedList.add(token); + tokenizedList.add(period); + } + else { + tokenizedList.add(token); + } } - return tokenizedList; } } From c48ef65ffd371a123acbf7ca98631cf42d5e6a0d Mon Sep 17 00:00:00 2001 From: xavierb <194048107+xavierb117@users.noreply.github.com> Date: Sun, 26 Jan 2025 22:32:50 -0800 Subject: [PATCH 06/11] Wave 3 - Fixed bug with saving period on same word instead of removing it --- src/LowercaseSentenceTokenizer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LowercaseSentenceTokenizer.java b/src/LowercaseSentenceTokenizer.java index f38a7a0..e8ce7ee 100644 --- a/src/LowercaseSentenceTokenizer.java +++ b/src/LowercaseSentenceTokenizer.java @@ -38,7 +38,7 @@ public List tokenize(Scanner scanner) { token = token.toLowerCase(); if (token.charAt(token.length() - 1) == '.') { String period = token.charAt(token.length() - 1) + ""; - tokenizedList.add(token); + tokenizedList.add(token.substring(0, token.length() - 1)); tokenizedList.add(period); } else { From 33e274caa4ecd412b33c99190a6a07bee5e0bd9d Mon Sep 17 00:00:00 2001 From: xavierb <194048107+xavierb117@users.noreply.github.com> Date: Mon, 27 Jan 2025 19:35:55 -0800 Subject: [PATCH 07/11] Wave 4 - Initial solution for the train method --- src/UnigramWordPredictor.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/UnigramWordPredictor.java b/src/UnigramWordPredictor.java index d713250..714c81e 100644 --- a/src/UnigramWordPredictor.java +++ b/src/UnigramWordPredictor.java @@ -50,8 +50,20 @@ public UnigramWordPredictor(Tokenizer tokenizer) { */ public void train(Scanner scanner) { List trainingWords = tokenizer.tokenize(scanner); + neighborMap = new HashMap<>(); - // TODO: Convert the trainingWords into neighborMap here + for (int i = 0; i < trainingWords.size(); i++) { + if (!neighborMap.containsKey(trainingWords.get(i))) { + List newList = new ArrayList<>(); + newList.add(trainingWords.get(i+1)); + neighborMap.put(trainingWords.get(i), newList); + } + else { + List value = neighborMap.get(trainingWords.get(i)); + value.add(trainingWords.get(i+1)); + neighborMap.put(trainingWords.get(i), value); + } + } } /** @@ -122,4 +134,4 @@ public Map> getNeighborMap() { return copy; } -} +} \ No newline at end of file From 85088cbef1d0105380fa6c0789f334568118169a Mon Sep 17 00:00:00 2001 From: xavierb <194048107+xavierb117@users.noreply.github.com> Date: Mon, 27 Jan 2025 19:56:57 -0800 Subject: [PATCH 08/11] Wave 4 - Fixed the length of the arraylist --- src/UnigramWordPredictor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/UnigramWordPredictor.java b/src/UnigramWordPredictor.java index 714c81e..b846493 100644 --- a/src/UnigramWordPredictor.java +++ b/src/UnigramWordPredictor.java @@ -52,7 +52,7 @@ public void train(Scanner scanner) { List trainingWords = tokenizer.tokenize(scanner); neighborMap = new HashMap<>(); - for (int i = 0; i < trainingWords.size(); i++) { + for (int i = 0; i < trainingWords.size() - 1; i++) { if (!neighborMap.containsKey(trainingWords.get(i))) { List newList = new ArrayList<>(); newList.add(trainingWords.get(i+1)); From 0ac223198aec791e52ec2f00122c9c1c6bff6a07 Mon Sep 17 00:00:00 2001 From: xavierb <194048107+xavierb117@users.noreply.github.com> Date: Tue, 28 Jan 2025 12:39:44 -0800 Subject: [PATCH 09/11] Wave 5 - Implemented predictNextWord with random --- src/UnigramWordPredictor.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/UnigramWordPredictor.java b/src/UnigramWordPredictor.java index b846493..c351406 100644 --- a/src/UnigramWordPredictor.java +++ b/src/UnigramWordPredictor.java @@ -3,6 +3,7 @@ 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. @@ -113,7 +114,13 @@ public void train(Scanner scanner) { public String predictNextWord(List context) { // TODO: Return a predicted word given the words preceding it // Hint: only the last word in context should be looked at - return null; + String word = ""; + List choices = neighborMap.get(context.get(context.size() - 1)); + Random random = new Random(); + int randomNum = random.nextInt(choices.size()); + word = choices.get(randomNum); + + return word; } /** From c247f5dec9164cc346e6ffe71eaafe0a2ea7f7f8 Mon Sep 17 00:00:00 2001 From: xavierb <194048107+xavierb117@users.noreply.github.com> Date: Tue, 28 Jan 2025 22:52:56 -0800 Subject: [PATCH 10/11] Wave 6 - Added tellTaleHeart.txt for ramblebot --- tellTaleHeart.txt | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tellTaleHeart.txt diff --git a/tellTaleHeart.txt b/tellTaleHeart.txt new file mode 100644 index 0000000..89a3cba --- /dev/null +++ b/tellTaleHeart.txt @@ -0,0 +1,35 @@ +TRUE! -- nervous -- very, very dreadfully nervous I had been and am; but why will you say that I am mad? The disease had sharpened my senses -- not destroyed -- not dulled them. Above all was the sense of hearing acute. I heard all things in the heaven and in the earth. I heard many things in hell. How, then, am I mad? Hearken! and observe how healthily -- how calmly I can tell you the whole story. + + It is impossible to say how first the idea entered my brain; but once conceived, it haunted me day and night. Object there was none. Passion there was none. I loved the old man. He had never wronged me. He had never given me insult. For his gold I had no desire. I think it was his eye! yes, it was this! He had the eye of a vulture --a pale blue eye, with a film over it. Whenever it fell upon me, my blood ran cold; and so by degrees -- very gradually --I made up my mind to take the life of the old man, and thus rid myself of the eye forever. + + Now this is the point. You fancy me mad. Madmen know nothing. But you should have seen me. You should have seen how wisely I proceeded --with what caution --with what foresight --with what dissimulation I went to work! I was never kinder to the old man than during the whole week before I killed him. And every night, about midnight, I turned the latch of his door and opened it --oh so gently! And then, when I had made an opening sufficient for my head, I put in a dark lantern, all closed, closed, so that no light shone out, and then I thrust in my head. Oh, you would have laughed to see how cunningly I thrust it in! I moved it slowly --very, very slowly, so that I might not disturb the old man's sleep. It took me an hour to place my whole head within the opening so far that I could see him as he lay upon his bed. Ha! --would a madman have been so wise as this? And then, when my head was well in the room, I undid the lantern cautiously --oh, so cautiously --cautiously (for the hinges creaked) --I undid it just so much that a single thin ray fell upon the vulture eye. And this I did for seven long nights --every night just at midnight --but I found the eye always closed; and so it was impossible to do the work; for it was not the old man who vexed me, but his Evil Eye. And every morning, when the day broke, I went boldly into the chamber, and spoke courageously to him, calling him by name in a hearty tone, and inquiring how he has passed the night. So you see he would have been a very profound old man, indeed, to suspect that every night, just at twelve, I looked in upon him while he slept. + + Upon the eighth night I was more than usually cautious in opening the door. A watch's minute hand moves more quickly than did mine. Never before that night had I felt the extent of my own powers --of my sagacity. I could scarcely contain my feelings of triumph. To think that there I was, opening the door, little by little, and he not even to dream of my secret deeds or thoughts. I fairly chuckled at the idea; and perhaps he heard me; for he moved on the bed suddenly, as if startled. Now you may think that I drew back --but no. His room was as black as pitch with the thick darkness, (for the shutters were close fastened, through fear of robbers,) and so I knew that he could not see the opening of the door, and I kept pushing it on steadily, steadily. + + I had my head in, and was about to open the lantern, when my thumb slipped upon the tin fastening, and the old man sprang up in bed, crying out --"Who's there?" + + I kept quite still and said nothing. For a whole hour I did not move a muscle, and in the meantime I did not hear him lie down. He was still sitting up in the bed listening; --just as I have done, night after night, hearkening to the death watches in the wall. + + Presently I heard a slight groan, and I knew it was the groan of mortal terror. It was not a groan of pain or of grief --oh, no! --it was the low stifled sound that arises from the bottom of the soul when overcharged with awe. I knew the sound well. Many a night, just at midnight, when all the world slept, it has welled up from my own bosom, deepening, with its dreadful echo, the terrors that distracted me. I say I knew it well. I knew what the old man felt, and pitied him, although I chuckled at heart. I knew that he had been lying awake ever since the first slight noise, when he had turned in the bed. His fears had been ever since growing upon him. He had been trying to fancy them causeless, but could not. He had been saying to himself --"It is nothing but the wind in the chimney --it is only a mouse crossing the floor," or "It is merely a cricket which has made a single chirp." Yes, he had been trying to comfort himself with these suppositions: but he had found all in vain. All in vain; because Death, in approaching him had stalked with his black shadow before him, and enveloped the victim. And it was the mournful influence of the unperceived shadow that caused him to feel --although he neither saw nor heard --to feel the presence of my head within the room. + + When I had waited a long time, very patiently, without hearing him lie down, I resolved to open a little --a very, very little crevice in the lantern. So I opened it --you cannot imagine how stealthily, stealthily --until, at length a single dim ray, like the thread of the spider, shot from out the crevice and fell full upon the vulture eye. + + It was open --wide, wide open --and I grew furious as I gazed upon it. I saw it with perfect distinctness --all a dull blue, with a hideous veil over it that chilled the very marrow in my bones; but I could see nothing else of the old man's face or person: for I had directed the ray as if by instinct, precisely upon the damned spot. + + And have I not told you that what you mistake for madness is but over acuteness of the senses? --now, I say, there came to my ears a low, dull, quick sound, such as a watch makes when enveloped in cotton. I knew that sound well, too. It was the beating of the old man's heart. It increased my fury, as the beating of a drum stimulates the soldier into courage. + + But even yet I refrained and kept still. I scarcely breathed. I held the lantern motionless. I tried how steadily I could maintain the ray upon the eye. Meantime the hellish tattoo of the heart increased. It grew quicker and quicker, and louder and louder every instant. The old man's terror must have been extreme! It grew louder, I say, louder every moment! --do you mark me well? I have told you that I am nervous: so I am. And now at the dead hour of the night, amid the dreadful silence of that old house, so strange a noise as this excited me to uncontrollable terror. Yet, for some minutes longer I refrained and stood still. But the beating grew louder, louder! I thought the heart must burst. And now a new anxiety seized me --the sound would be heard by a neighbor! The old man's hour had come! With a loud yell, I threw open the lantern and leaped into the room. He shrieked once --once only. In an instant I dragged him to the floor, and pulled the heavy bed over him. I then smiled gaily, to find the deed so far done. But, for many minutes, the heart beat on with a muffled sound. This, however, did not vex me; it would not be heard through the wall. At length it ceased. The old man was dead. I removed the bed and examined the corpse. Yes, he was stone, stone dead. I placed my hand upon the heart and held it there many minutes. There was no pulsation. He was stone dead. His eye would trouble me no more. + + If still you think me mad, you will think so no longer when I describe the wise precautions I took for the concealment of the body. The night waned, and I worked hastily, but in silence. First of all I dismembered the corpse. I cut off the head and the arms and the legs. + + I then took up three planks from the flooring of the chamber, and deposited all between the scantlings. I then replaced the boards so cleverly, so cunningly, that no human eye -- not even his --could have detected any thing wrong. There was nothing to wash out --no stain of any kind --no blood-spot whatever. I had been too wary for that. A tub had caught all --ha! ha! + + When I had made an end of these labors, it was four o'clock --still dark as midnight. As the bell sounded the hour, there came a knocking at the street door. I went down to open it with a light heart, --for what had I now to fear? There entered three men, who introduced themselves, with perfect suavity, as officers of the police. A shriek had been heard by a neighbor during the night; suspicion of foul play had been aroused; information had been lodged at the police office, and they (the officers) had been deputed to search the premises. + + I smiled, --for what had I to fear? I bade the gentlemen welcome. The shriek, I said, was my own in a dream. The old man, I mentioned, was absent in the country. I took my visitors all over the house. I bade them search --search well. I led them, at length, to his chamber. I showed them his treasures, secure, undisturbed. In the enthusiasm of my confidence, I brought chairs into the room, and desired them here to rest from their fatigues, while I myself, in the wild audacity of my perfect triumph, placed my own seat upon the very spot beneath which reposed the corpse of the victim. + + The officers were satisfied. My manner had convinced them. I was singularly at ease. They sat, and while I answered cheerily, they chatted of familiar things. But, ere long, I felt myself getting pale and wished them gone. My head ached, and I fancied a ringing in my ears: but still they sat and still chatted. The ringing became more distinct: --it continued and became more distinct: I talked more freely to get rid of the feeling: but it continued and gained definiteness --until, at length, I found that the noise was not within my ears. + + No doubt I now grew very pale; --but I talked more fluently, and with a heightened voice. Yet the sound increased --and what could I do? It was a low, dull, quick sound --much such a sound as a watch makes when enveloped in cotton. I gasped for breath -- and yet the officers heard it not. I talked more quickly --more vehemently; but the noise steadily increased. I arose and argued about trifles, in a high key and with violent gesticulations; but the noise steadily increased. Why would they not be gone? I paced the floor to and fro with heavy strides, as if excited to fury by the observations of the men -- but the noise steadily increased. Oh God! what could I do? I foamed --I raved --I swore! I swung the chair upon which I had been sitting, and grated it upon the boards, but the noise arose over all and continually increased. It grew louder --louder --louder! And still the men chatted pleasantly, and smiled. Was it possible they heard not? Almighty God! --no, no! They heard! --they suspected! --they knew! --they were making a mockery of my horror! --this I thought, and this I think. But anything was better than this agony! Anything was more tolerable than this derision! I could bear those hypocritical smiles no longer! I felt that I must scream or die! --and now --again! --hark! louder! louder! louder! louder! -- + + "Villains!" I shrieked, "dissemble no more! I admit the deed! --tear up the planks! --here, here! --it is the beating of his hideous heart!" \ No newline at end of file From a90c656f1f88593e42389ef318f04e732f7855c0 Mon Sep 17 00:00:00 2001 From: xavierb <194048107+xavierb117@users.noreply.github.com> Date: Tue, 28 Jan 2025 23:01:37 -0800 Subject: [PATCH 11/11] Wave 6 - Added ramblebotOutput.txt for the output on my tellTaleHeart text --- ramblebotOutput.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 ramblebotOutput.txt diff --git a/ramblebotOutput.txt b/ramblebotOutput.txt new file mode 100644 index 0000000..6e4cebc --- /dev/null +++ b/ramblebotOutput.txt @@ -0,0 +1 @@ +true! -- how stealthily, stealthily --until, at the sound well . for his room . i not told you will think so that distracted me . ha! --would a tub had been deputed to feel --although he slept . i kept pushing it . the low stifled sound as a sound . he had caught all the chair upon the floor," or "it is the bed . they chatted pleasantly, and now you mistake for madness is the bed and smiled gaily, to open the legs . they not within my perfect suavity, as the old man's sleep . but \ No newline at end of file