Browse Source

Completed ParanChecker

Beggining WCTest
Need Test Cases
Nick Satinover 6 years ago
parent
commit
dc2eaf0adc

+ 9
- 0
src/main/java/io/zipcoder/Main.java View File

@@ -0,0 +1,9 @@
1
+package io.zipcoder;
2
+
3
+public class Main {
4
+    public static void main(String[] args) {
5
+        WC wc = new WC(WC.class.getResource("/someTextFile.txt").getFile());
6
+
7
+        wc.orderList("/someTextFile.txt");
8
+    }
9
+}

+ 36
- 3
src/main/java/io/zipcoder/WC.java View File

@@ -2,22 +2,55 @@ package io.zipcoder;
2 2
 
3 3
 import java.io.FileNotFoundException;
4 4
 import java.io.FileReader;
5
-import java.util.Iterator;
6
-import java.util.Scanner;
5
+import java.util.*;
6
+import java.util.stream.*;
7 7
 
8 8
 public class WC {
9 9
     private Iterator<String> si;
10
+    HashMap<String, Integer> wordCount = new HashMap<String, Integer>();
10 11
 
11 12
     public WC(String fileName) {
12 13
         try {
13
-            this.si = new Scanner(new FileReader(fileName));
14
+            si = new Scanner(new FileReader(fileName));
15
+            ((Scanner) si).useDelimiter("[\\p{Punct}\\s]")
14 16
         } catch (FileNotFoundException e) {
15 17
             System.out.println(fileName + " Does Not Exist");
16 18
             System.exit(-1);
17 19
         }
20
+        makeList();
21
+    }
22
+
23
+
24
+    public void makeList(){
25
+        while (si.hasNext()){
26
+            String word = si.next().toLowerCase();
27
+            Integer count = wordCount.get(word);
28
+            if (count != null){
29
+                wordCount.put(word, count + 1);
30
+            } else {
31
+                wordCount.put(word, 1);
32
+            }
33
+        }
18 34
     }
19 35
 
20 36
     public WC(Iterator<String> si) {
21 37
         this.si = si;
22 38
     }
39
+
40
+    public void orderList() {
41
+        Map<String, Integer> sortedWordCount = new TreeMap<String, Integer>(wordCount);
42
+        for(Map.Entry<String, Integer> entry : sortedWordCount.entrySet()){
43
+            System.out.println(entry.getKey() + "\n");
44
+        }
45
+
46
+    }
23 47
 }
48
+//get file.txt
49
+//go through each line and
50
+// if new words
51
+//add word to array, count 1
52
+//if old word
53
+//count++ to old word in array
54
+
55
+//sort array descending
56
+//collections .stream(), treemap<>;

+ 34
- 0
src/main/resources/someTextFile.txt View File

@@ -0,0 +1,34 @@
1
+Thick yellow fog, and in consequence electric light to dress by and breakfast by, was the opening day of the year. Never, to anyone who looks at this fact in the right spirit, did a year dawn more characteristically. The denseness, the utter inscrutability of the face of that which should be, was never better typified. We blindly groped on the threshold of the future, feeling here for a bell-handle, here for a knocker, while the door still stood shut. Then, about mid-day, sudden commotions shook the vapours; dim silhouettes of house-roofs, promised lands perhaps, or profiled wrecks, stood suddenly out against swirling orange whirlpools of mist; and from my window, which commanded a double view up and down Oxford Street, I looked out over the crawling traffic, with an interest, as if in the unfolding of some dramatic plot, on the battle of the skies. From sick dead{4} yellow the colour changed to gray, and for a few moments the street seemed lit by a dawn of April; then across the pearly tints came a sunbeam, lighting them with sudden opalescence. Then the smoke from the house opposite, which had been ascending slowly, like a tired man climbing stairs, was plucked away by a breeze, and in two minutes the whole street was a blaze of primrose-coloured sunshine.
2
+All that week I was work-bound in London—a place where, as everyone knows, there are forty-eight hours in every twenty-four. The reason for this is obvious. It is impossible to sit idly in a chair in London; it is impossible (almost) to read a book, and it is (happily) quite impossible to write one. Hence the hours are multiplied. The sound and spectacle of life induces a sort of intoxication of the mind. Ten yards of Piccadilly is a volume, and the Circus an improper epic. Hence the impossibility of reading; the books are in the flowing tides that jostle from house-wall to house-wall, and they are vastly more entertaining than anything that publishers have ever had the good fortune to bring out.{5}
3
+Now, people who are incapable of reading bookprint—of which the enormous mass is very sorry stuff—are held to be uneducated; but it seems to me that people who cannot read, or at any rate conjecture at, this splendid human print are much more ignorant. For it is here in these places, alive with the original words and phrases out of which all books are made, that there lies the key to all books that are worth reading at all. At any rate, here lies the material; it is here, and nowhere else, that the chef does his marketing. There are, however, several rules to be observed if you would read the original. The first is, that you must attend with all your might; the book, so to speak, shuts automatically if you cease to attend. The second is, that you must at a moment’s notice be ready to pity and to praise. The third—and perhaps the most important of all—is, that you must never be shocked. For the whole attitude of the observer is covered by pity or praise. The Great Author does not want his moral condemnation, and, in addition to this, there is nothing so blinding to one’s self as being shocked. It is like looking through a telescope at one point only, and that{6} probably wrongly focussed; for it is focussed by one’s own individual code, which is almost certainly wrong. It is Human Life you are looking at; if that is not good enough for you, go and look at something else. There are plenty of dull things in the world, but remember always that, if you find other people dull, it is only a sign that a dull person is present. But if you are to read the book Living, come humble and alert. Try to catch the point of every phrase, for of this you may be sure—that there is a point. You will find there, thank God! many pages that will make you laugh—laugh, that is, properly, with sheer childish, unreflecting amusement; you will find there things that will make you think; and you will certainly find there things that will make you want to weep. And if we knew a little, instead of knowing nothing, we should probably—no, certainly—fall on our knees, and thank God for that also.
4
+One of each of these occurred to me to-day. The first was when I was coming out of the club with a friend on our way to dinner. An obsequious porter held the club door open, an obsequious page-boy stood by our glittering{7} hansom, with a hand on the wheel. My friend had an opulent appearance and wore a fur coat. On the pavement were standing two exceedingly small and ragged boys, and one of them whose hair drooped over his eyes like a Skye terrier, seeing this resplendent exit, put his thumbs in the place where the armholes of his waistcoat would have been, had the merry little devil had one, and, with his nose in the air, said very loud to the other, ‘Whare are we doining to-night, Bill?’
5
+The second made one laugh at first, but think afterwards, and it was thus: At the corner of Dover Street there lay a heap of mud and street sweepings, and as we drew up just opposite, blocked by an opposing tide of carriages in Piccadilly, a small, very dapper little gentleman in dress-clothes stepped into the middle of this muck-heap, with the result that one of his dress-pumps was drawn off his unfortunate foot with a ‘cloop’ and stuck there. On to it there swooped a vulture of the highway, a lad of about twenty, who picked it out, and made off down Dover Street with it. Now, what good was one shoe to him? Would he not have done better to have wiped it carefully{8} on his coat, which really could not have deteriorated farther, and chanced a tip from the dapper little gentleman? Or was the instinct of stealing so strong that he never stopped to think? One would have supposed that a tip was a practical certainty.
6
+The third sight was merely a matter for tears.
7
+I walked back from dinner, and my way lay up Piccadilly again. At a populous corner stood a very stout elderly woman, dressed in violent and ridiculous colours. Her hair was golden, her eyebrows broad, thick and vilely drawn, her cheeks so burned with rouge that one blushed. She addressed every passer-by in endearing terms. None regarded her. That was quite right; but the pity of her standing there on this squally night, with her horrid mission and her total ill-success! Yes, it is difficult to thank God for that.
8
+After five days I got deliverance from this entrancing slavery, and, like a cork from a bottle, flew to Grindelwald. The journey I remember as a dreadful dream, for I had a cold so bad that all sense of taste, smell, and most of hearing and{9} feeling, had passed from me, and I seemed to myself to be a rough deal board being sent by train, and turned out into a drizzling night at what appeared to be mere cowsheds on the line, simply for the purpose of declaring that I had no spirit or lace about me. Spirit! The Queen of Sheba when she had seen Solomon in all his glory had more. As to lace, that diaphanous material seriously occupied my waking dreams as we mounted the Jura. Was there anything in my face that suggested lace, I wondered, or did lace frillings peep out from my trousers? Anyhow, why lace? I was really almost anxious to declare five hundred cigarettes, but nobody suggested such a thing. Then——
9
+The new heaven and the new earth, an earth covered with powdery snow, thatched here and there by pines, and reaching beyond all power of thought, by glacier and snowfield and rocks too steep for the settling of the snow, into the pinnacles of the Eiger and the Wetterhorn. From ridge to ridge the eye followed, lost in amazement at the wonder of the earth and the greatness of its design. Austere and silent rose the virgin{10} snows, and more silent, growing from words to exclamation, and from exclamation to silence itself, one’s wonder. There, out of the void and formless pulp which was once the world, they were set, barren, fruitless, useless, and that is the wonder of them and their glory. Centuries have been as but seconds in the life of an idle man in the forming of them; for centuries that have been to them but the winking of an eye they have raised their immemorial crests, and the centuries shall be as the sea-sand before they crumble. O ye Mountains and Hills, praise ye the Lord! Every day you praise Him.
10
+Now, this “Book of Months” is almost certainly worth nothing, anyhow, and I take this opportunity to inform critics so, in case (as is not likely) they have the slightest doubt about it. But if they and I are wrong, it will be because we have both overlooked the possible value of a true document—true, that is, as far as I personally am able to make it true. Therefore I will state at once that for the next four weeks the childish pursuit of making correct lines and edges on the ice occupied me much more, except on a few{11} occasions, than all the mountains, all the heavenly blue of the sky, or the divine radiance of the marching sun. Instead of attending to those big and beautiful things, I got up, day after day, full of anxious thoughts, and had I been assured that these anxieties would never trouble me again on condition that I never again looked at the Eiger, or the scarlet finger of the Finster-Aarhorn that caught the sunset long after the sun had set to us, I would quite certainly have closed with the bargain. Those who do not know what a clean outside-back-counter means can have no voice in this affair, since they are not acquainted with the subject-matter of it, but those who do will, I believe, extend to me their pitying sympathy. For no known reason, I desired to make these and other turns, which when made are of no conceivable use to anybody, and full of anxious thoughts, which violent collisions with the elusive material on which I performed fully justified, I proceeded to devote the hours of light to these utterly indefensible pursuits. I wished to execute a movement in which the skate left a certain mark on the ice, and no other (I am alluding, of{12} course, to involuntary change of edge), and to make these and other marks on the ice (continuous loops, bracket-eight, and a few more, for the sake of the curious) I signed a bond, so to speak, for three weeks of my short mortal life. All morning, that is to say, I struggled with these evanescent scratchings, ate a hurried lunch, and struggled again till it was dark. Really, it is very odd, and I hope to do the same next winter. I am perfectly aware that I could have spent my time much better, or, at any rate, tried to. I knew that at the time; but I did not care then, and I do not care now.
11
+There were sane intervals, however. For instance, one Saturday evening it began to snow. Now, I see nothing conceivably wrong in skating on Sunday, and am unable to comprehend the position of those who do. But it is certainly wrong to skate on Sunday when it will spoil the ice on Monday, and on this particular Sunday I went to church in the morning, and afterwards took a sandwich lunch from the hotel, and, tying it securely to a toboggan, sat myself insecurely on the toboggan, and went alone—that was an{13} essential part of the plan—down past the church and through the village, through fields of white snow that spouted as the toboggan met them, even as the spray spouts round the bows of a liner. In nothing, I suppose, does a man (unless he be M. Santos Dumont) come nearer to the ecstasy of flight, some low skimming flight that follows the contour of the ground as swallows when storm is imminent. So went I down an ever-steepening mile, finishing at the end just by the side of the bridge that crosses the stream from the glacier. The frost had been severe for the last week, and this was nearly covered over with lids of ice that grew out from backwaters and extended almost from bank to bank. Wherever a stone stood in mid-current, there below it had the ice first gathered, groping its way downstream till the cold feeler reached another stone. Then, already half established, it had broadened and broadened till a third anchorage met it. But in certain swift places the water still ran unchecked, its flow, of course, greatly diminished with the lesser melting of the glacier in winter, but still busy, busy, seeking the sea with steadfast purpose. Round the{14} banks and in the bed itself of the stream grew an immense company of alders covered completely with the inimitable confectionery of frost, a forest of spiked branches.
12
+Then mounting again, I passed up a long gentle slope by a few outlying châlets, and, having come out of the shadow of the Eiger, sat down to lunch. The air was utterly windless, the frost so keen that not a flake of snow clung to my clothes, yet through the glory of that pellucid air the sun struck so hot that a coat was altogether a superfluity. Eastwards the Wetterhorn rose in glacier and snowfield, and its superb and patient beauty, as of some noble woman waiting for the man she loves, struck me with a pang of delight. Thereafter still climbing, I entered the pine-woods below the Scheidegg, where the sun drew out a thousand woodland and resinous smells, as if odorous summer instead of midwinter held sway.
13
+Alone! I had intended to be alone, but never was a man in more delectable company. Trees, glimpses of the gorgeous dome above them, drifts of driven snow, were my companions, while, if one grew overbold, there was the Eiger to hazard{15} a respectful remark to, and the sun itself to be worshipped. On no other day, indeed, that I can remember have I felt so strong a sympathy with Parsees. High it swung, benignant, and all for the fir-trees and me. Then rising higher, I came to the edge of the wood and the beginning of the snowfields again, and, resting for a moment, did an exceedingly childish thing. Underneath a piece of spreading root of the last tree of that heavenly wood I hid a Bryant and May’s match-box containing a stick of chocolate, an English sixpence, two nickel coins of ten centimes, a short piece of pencil, and four matches. These I dedicate to the wayfarer should he need a light. Also I should ask him to write his name with the pencil and put it in the match-box, and, if he feels as foolish as I, add some small object of no value. Next year I will go there again, and make some further striking additions to the cache. The tree is a large one on the left of the path, and quite notably the last in the wood. My initials are rudely carved in the piece of root directly above the cache. An intelligent traveller knowing this can hardly miss the place.{16}
14
+Now, where shall we look for the origin of this instructive piece of foolishness? This is not a merely egotistic query, for I am perfectly certain that many sober and mature citizens like myself will feel sympathy with childishness that rejoices in such caches as I made on the slopes of the Scheidegg. Is it that we still preserve, even in this well-civilized and restauranted century, some cell in our brain which even now obeys the prudent instincts of some remote cave-dwelling ancestor, and do we now in play imitate his serious precautions? Or—and I like to think this better—have we still, in spite of our sober maturity, some remnants still of an heritage more priceless than cave-dwelling ancestors, namely, the lingering joys of our own childhood? On the whole, the evidence points this way, especially when I consider in connection with this certain other survivals, like that of ‘talking French.’ Here I feel that I may be treading on alien ground; the cache habit, I know, is not rare, but I have not at present met anyone who ‘talks French,’ of which the manner is as follows.
15
+Everyone, I suppose, has moments of sheer physical enjoyment. I need mention two only:{17} the one, getting into bed, with legs curled up, ere yet the freezing sheets can be encountered; the other, when very cold getting into a hot bath, a bath, that is to say, so hot that it is on the border between bliss and anguish, when, in fact, to move is to scream. On these occasions—for loneliness is essential,—I ‘talk French’; that is to say, streams of gibberish flow in a hushed voice from my lips, in the form of dialogue, and anyone present would hear remarkable things of this nature:
16
+(With deep anxiety) ‘Usti Icibon?’
17
+(Reassuringly) ‘Mimi molat isto pacher.’
18
+(Reassured) ‘Kaparando guilli. Amatinat skolot.’
19
+I blush to reproduce more. But I long to know if anybody else ‘talks French.’ I want to talk it with somebody, and compare vocabularies.
20
+A long colloquy was held that afternoon, sitting in the sun, after the cache was made, and then towards sunset I started to go back through the pine-wood with dim but welcome thoughts of bears and brigands lying in wait on each side the path. One corner I remember I particularly feared, for low-growing bushes bordering the path might conceal almost anything. That I had good reason{18} to fear it I soon found out, though I had feared it for wrong reasons, for my toboggan threw me with reckless gaiety into the middle of those same bushes. In fact, for the first half-mile the track was abominable; bare stones and tree-roots alternated with passages of breathless rapidity; never have I experienced a quicker succession of violences. But as the wood grew less dense the texture of the going became more uniform, and for the last mile I hissed downwards with ever-increasing speed and smoothness through the pallor of the snow-bright dusk. Large stars beamed luminous overhead, and from scattered cottages sprang the twinkling lights, showing that all were home from the frozen fields and safe within walls. Then, wonder of wonders! the full moon rose over the top of the Wetterhorn with a light as clear as running water and as soft as sleep, making complete with its perfection this perfect day.
21
+The other interlude from this rage of tracing useless marks on the ice was a funeral. The funeral was that of Slam’s kitten, though the kitten was not really Slam’s at all. But, to go back to the beginning of things, it is necessary{19} that you should know who Slam was. Her real name was Evelyn Helen Anastasia, and goodness knows what; but what matters more is that she was a child six years and one month old, freckle-faced, snub-nosed, devoted to animals and the outside edge, and by far the most popular person in the hotel. It was the outside edge originally that had brought us together, for she had told me that I didn’t do it properly, and, very kindly showing me how, she had fallen heavily on the ice. As I picked her up, she said:
22
+‘You see what I mean, don’t you? Let me show you again.’
23
+Under her tuition I improved, and, what was more important, our friendship ripened. I am proud to think that I was the only person who ever heard about the kitten, which had followed Slam—I am sure I don’t wonder—with pitiful mewings, down from the Happy Valley, an ownerless beast that would have touched hearts more hard than Slam’s. She kept it in a cupboard in her room and fed it with cake. This I learned on the second day of the kitten’s imprisonment. That evening it died. I will pass over Sla{20}m’s lamentations, and the wealth of falsehood by which I convinced her that a diet of cake in an airless cupboard was the only thing that could have saved it. Then, as it was dead, it had to be buried, still without the cognizance of Slam’s nurse, whom I feared.
24
+‘I don’t want a lot of people,’ said Slam. ‘It would be much nicer if we buried her quietly. So when nurse is at dinner I will bring her down in my hat.’
25
+Meantime I had procured a cardboard box, and from Slam’s hat the kitten passed into its coffin. The coffin was put on our toboggan—for Slam and I were going to lunch out—and the catafalque left the hotel.
26
+Slam put her hand into mine—a compliment that only children can pay—and we debated about the cemetery. I personally inclined to the riverbed at the bottom of the valley, but Slam would have none of it.
27
+‘Up above,’ she said, ‘it is cleaner;’ and, though it was all pretty clean, I assented. ‘Then we can eat our lunch and toboggan down,’ she added. This was common-sense; to walk up{21} after the funeral would be depressing; we might recover our lightness of spirit if we left the tobogganing till afterwards.
28
+On the way up, through the village, that is, and towards the glacier, the talk turned on serious subjects. Did I believe that animals would have a resurrection? Why did God make them if they were just to die and be finished? Again, if they were to have a resurrection, was it not proper to bury them properly? Thus we arrived at the cemetery. Four pine-trees stood there, with snow drifted high between them; the benediction of the sun hallowed the place; never had anyone a more virgin tomb. We scooped out the snow down to soil-level, and dropped the box into the excavation. Then with pious hands we covered it up, and on the top of the cairn planted sprigs taken from the pines.
29
+‘And now I will say my prayers,’ said Slam.
30
+She knelt down in the snow, and, even with the fear of her nurse before my eyes, I could say nothing to dissuade her, but knelt by her and uncovered my head. And then Slam said the Lord’s Prayer, and asked that she might be a good girl{22} always, and prayed that God might bless her father and mother and nurse and me.
31
+Do you know what it is to be remembered in the prayers of a child? Then she paused: ‘and the kitten,’ she added. And I said ‘Amen.’
32
+So there the kitten lies, between the sky and the beautiful snow-clad earth. Pines whisper about it, and the Wetterhorn and Eiger watch over its resting-place. And Slam said her prayers there.
33
+What follows? As far as I am concerned, this: I believe that the whole creation groaneth and travaileth in pain together, and that there will be one day a great healing and comforting. And when on that day, mysteriously, unintelligibly, that little body, which meantime has fed the grasses and the alpine flowers of the place, comes to itself and is alive again, I believe that a happy little kitten will stand between those four pine-trees, lost no longer. And Slam and I will recognise it. And the kitten—who knows?—will recognise us, and Slam will say again, in the phrase that is so often on her lips:
34
+‘Oh, it is nice!{23}’