Skip to content

Instantly share code, notes, and snippets.

@caioertai
Last active January 26, 2019 20:40
Show Gist options
  • Save caioertai/14f1d29ed66a87c554b8346be3d26eb7 to your computer and use it in GitHub Desktop.
Save caioertai/14f1d29ed66a87c554b8346be3d26eb7 to your computer and use it in GitHub Desktop.
require_relative './word_counter.rb'
# Opens the content from the txt file and reads it into a string
text_string = File.open('text.txt').read
# Iterates over the hash to print each word on a new line
word_counter(text_string).each do |word, count|
puts "#{count} -> #{word}"
end
A MODEST PROPOSAL
For preventing the children of poor people in Ireland, from being a
burden on their parents or country, and for making them beneficial to
the publick.
by Dr. Jonathan Swift
1729
It is a melancholy object to those, who walk through this great town,
or travel in the country, when they see the streets, the roads and
cabbin-doors crowded with beggars of the female sex, followed by three,
four, or six children, all in rags, and importuning every passenger for
an alms. These mothers instead of being able to work for their honest
livelihood, are forced to employ all their time in stroling to beg
sustenance for their helpless infants who, as they grow up, either turn
thieves for want of work, or leave their dear native country, to fight
for the Pretender in Spain, or sell themselves to the Barbadoes.
I think it is agreed by all parties, that this prodigious number of
children in the arms, or on the backs, or at the heels of their mothers,
and frequently of their fathers, is in the present deplorable state of
the kingdom, a very great additional grievance; and therefore whoever
could find out a fair, cheap and easy method of making these children
sound and useful members of the common-wealth, would deserve so well of
the publick, as to have his statue set up for a preserver of the nation.
But my intention is very far from being confined to provide only for the
children of professed beggars: it is of a much greater extent, and shall
take in the whole number of infants at a certain age, who are born of
parents in effect as little able to support them, as those who demand
our charity in the streets.
As to my own part, having turned my thoughts for many years, upon this
important subject, and maturely weighed the several schemes of
our projectors, I have always found them grossly mistaken in their
computation. It is true, a child just dropt from its dam, may be
supported by her milk, for a solar year, with little other nourishment:
at most not above the value of two shillings, which the mother may
certainly get, or the value in scraps, by her lawful occupation of
begging; and it is exactly at one year old that I propose to provide for
them in such a manner, as, instead of being a charge upon their parents,
or the parish, or wanting food and raiment for the rest of their lives,
they shall, on the contrary, contribute to the feeding, and partly to
the cloathing of many thousands.
There is likewise another great advantage in my scheme, that it will
prevent those voluntary abortions, and that horrid practice of
women murdering their bastard children, alas! too frequent among us,
sacrificing the poor innocent babes, I doubt, more to avoid the expence
than the shame, which would move tears and pity in the most savage and
inhuman breast.
The number of souls in this kingdom being usually reckoned one million
and a half, of these I calculate there may be about two hundred thousand
couple whose wives are breeders; from which number I subtract thirty
thousand couple, who are able to maintain their own children, (although
I apprehend there cannot be so many, under the present distresses of
the kingdom) but this being granted, there will remain an hundred and
seventy thousand breeders. I again subtract fifty thousand, for those
women who miscarry, or whose children die by accident or disease within
the year. There only remain an hundred and twenty thousand children of
poor parents annually born. The question therefore is, How this number
shall be reared, and provided for? which, as I have already said, under
the present situation of affairs, is utterly impossible by all the
methods hitherto proposed. For we can neither employ them in handicraft
or agriculture; they neither build houses, (I mean in the country) nor
cultivate land: they can very seldom pick up a livelihood by stealing
till they arrive at six years old; except where they are of towardly
parts, although I confess they learn the rudiments much earlier;
during which time they can however be properly looked upon only as
probationers: As I have been informed by a principal gentleman in the
county of Cavan, who protested to me, that he never knew above one or
two instances under the age of six, even in a part of the kingdom so
renowned for the quickest proficiency in that art.
I am assured by our merchants, that a boy or a girl before twelve years
old, is no saleable commodity, and even when they come to this age, they
will not yield above three pounds, or three pounds and half a crown
at most, on the exchange; which cannot turn to account either to the
parents or kingdom, the charge of nutriments and rags having been at
least four times that value.
I shall now therefore humbly propose my own thoughts, which I hope will
not be liable to the least objection.
I have been assured by a very knowing American of my acquaintance in
London, that a young healthy child well nursed, is, at a year old, a
most delicious nourishing and wholesome food, whether stewed, roasted,
baked, or boiled; and I make no doubt that it will equally serve in a
fricasie, or a ragoust.
I do therefore humbly offer it to publick consideration, that of the
hundred and twenty thousand children, already computed, twenty thousand
may be reserved for breed, whereof only one fourth part to be males;
which is more than we allow to sheep, black cattle, or swine, and my
reason is, that these children are seldom the fruits of marriage, a
circumstance not much regarded by our savages, therefore, one male will
be sufficient to serve four females. That the remaining hundred thousand
may, at a year old, be offered in sale to the persons of quality and
fortune, through the kingdom, always advising the mother to let them
suck plentifully in the last month, so as to render them plump, and fat
for a good table. A child will make two dishes at an entertainment for
friends, and when the family dines alone, the fore or hind quarter will
make a reasonable dish, and seasoned with a little pepper or salt, will
be very good boiled on the fourth day, especially in winter.
I have reckoned upon a medium, that a child just born will weigh 12
pounds, and in a solar year, if tolerably nursed, encreaseth to 28
pounds.
I grant this food will be somewhat dear, and therefore very proper for
landlords, who, as they have already devoured most of the parents, seem
to have the best title to the children.
Infant's flesh will be in season throughout the year, but more plentiful
in March, and a little before and after; for we are told by a grave
author, an eminent French physician, that fish being a prolifick dyet,
there are more children born in Roman Catholick countries about nine
months after Lent, the markets will be more glutted than usual, because
the number of Popish infants, is at least three to one in this kingdom,
and therefore it will have one other collateral advantage, by lessening
the number of Papists among us.
I have already computed the charge of nursing a beggar's child (in which
list I reckon all cottagers, labourers, and four-fifths of the farmers)
to be about two shillings per annum, rags included; and I believe no
gentleman would repine to give ten shillings for the carcass of a good
fat child, which, as I have said, will make four dishes of excellent
nutritive meat, when he hath only some particular friend, or his
own family to dine with him. Thus the squire will learn to be a good
landlord, and grow popular among his tenants, the mother will have eight
shillings neat profit, and be fit for work till she produces another
child.
Those who are more thrifty (as I must confess the times require) may
flea the carcass; the skin of which, artificially dressed, will make
admirable gloves for ladies, and summer boots for fine gentlemen.
As to our City of Dublin, shambles may be appointed for this purpose, in
the most convenient parts of it, and butchers we may be assured will not
be wanting; although I rather recommend buying the children alive, and
dressing them hot from the knife, as we do roasting pigs.
A very worthy person, a true lover of his country, and whose virtues
I highly esteem, was lately pleased, in discoursing on this matter, to
offer a refinement upon my scheme. He said, that many gentlemen of this
kingdom, having of late destroyed their deer, he conceived that the
want of venison might be well supply'd by the bodies of young lads and
maidens, not exceeding fourteen years of age, nor under twelve; so great
a number of both sexes in every country being now ready to starve for
want of work and service: And these to be disposed of by their parents
if alive, or otherwise by their nearest relations. But with due
deference to so excellent a friend, and so deserving a patriot, I
cannot be altogether in his sentiments; for as to the males, my American
acquaintance assured me from frequent experience, that their flesh was
generally tough and lean, like that of our school-boys, by continual
exercise, and their taste disagreeable, and to fatten them would not
answer the charge. Then as to the females, it would, I think, with
humble submission, be a loss to the publick, because they soon would
become breeders themselves: And besides, it is not improbable that some
scrupulous people might be apt to censure such a practice, (although
indeed very unjustly) as a little bordering upon cruelty, which, I
confess, hath always been with me the strongest objection against any
project, how well soever intended.
But in order to justify my friend, he confessed, that this expedient
was put into his head by the famous Salmanaazor, a native of the island
Formosa, who came from thence to London, above twenty years ago, and in
conversation told my friend, that in his country, when any young person
happened to be put to death, the executioner sold the carcass to persons
of quality, as a prime dainty; and that, in his time, the body of a
plump girl of fifteen, who was crucified for an attempt to poison the
Emperor, was sold to his imperial majesty's prime minister of state, and
other great mandarins of the court in joints from the gibbet, at four
hundred crowns. Neither indeed can I deny, that if the same use were
made of several plump young girls in this town, who without one single
groat to their fortunes, cannot stir abroad without a chair, and appear
at a play-house and assemblies in foreign fineries which they never will
pay for; the kingdom would not be the worse.
Some persons of a desponding spirit are in great concern about that vast
number of poor people, who are aged, diseased, or maimed; and I have
been desired to employ my thoughts what course may be taken, to ease
the nation of so grievous an incumbrance. But I am not in the least pain
upon that matter, because it is very well known, that they are every day
dying, and rotting, by cold and famine, and filth, and vermin, as fast
as can be reasonably expected. And as to the young labourers, they
are now in almost as hopeful a condition. They cannot get work, and
consequently pine away from want of nourishment, to a degree, that if
at any time they are accidentally hired to common labour, they have not
strength to perform it, and thus the country and themselves are happily
delivered from the evils to come.
I have too long digressed, and therefore shall return to my subject. I
think the advantages by the proposal which I have made are obvious and
many, as well as of the highest importance.
For first, as I have already observed, it would greatly lessen the
number of Papists, with whom we are yearly over-run, being the principal
breeders of the nation, as well as our most dangerous enemies, and who
stay at home on purpose with a design to deliver the kingdom to the
Pretender, hoping to take their advantage by the absence of so many good
Protestants, who have chosen rather to leave their country, than stay at
home and pay tithes against their conscience to an episcopal curate.
Secondly, The poorer tenants will have something valuable of their own,
which by law may be made liable to a distress, and help to pay their
landlord's rent, their corn and cattle being already seized, and money a
thing unknown.
Thirdly, Whereas the maintainance of an hundred thousand children,
from two years old, and upwards, cannot be computed at less than
ten shillings a piece per annum, the nation's stock will be thereby
encreased fifty thousand pounds per annum, besides the profit of a
new dish, introduced to the tables of all gentlemen of fortune in the
kingdom, who have any refinement in taste. And the money will circulate
among our selves, the goods being entirely of our own growth and
manufacture.
Fourthly, The constant breeders, besides the gain of eight shillings
sterling per annum by the sale of their children, will be rid of the
charge of maintaining them after the first year.
Fifthly, This food would likewise bring great custom to taverns,
where the vintners will certainly be so prudent as to procure the best
receipts for dressing it to perfection; and consequently have their
houses frequented by all the fine gentlemen, who justly value themselves
upon their knowledge in good eating; and a skilful cook, who understands
how to oblige his guests, will contrive to make it as expensive as they
please.
Sixthly, This would be a great inducement to marriage, which all wise
nations have either encouraged by rewards, or enforced by laws and
penalties. It would encrease the care and tenderness of mothers towards
their children, when they were sure of a settlement for life to the
poor babes, provided in some sort by the publick, to their annual profit
instead of expence. We should soon see an honest emulation among the
married women, which of them could bring the fattest child to the
market. Men would become as fond of their wives, during the time of
their pregnancy, as they are now of their mares in foal, their cows in
calf, or sow when they are ready to farrow; nor offer to beat or kick
them (as is too frequent a practice) for fear of a miscarriage.
Many other advantages might be enumerated. For instance, the addition
of some thousand carcasses in our exportation of barrel'd beef: the
propagation of swine's flesh, and improvement in the art of making good
bacon, so much wanted among us by the great destruction of pigs,
too frequent at our tables; which are no way comparable in taste or
magnificence to a well grown, fat yearly child, which roasted whole will
make a considerable figure at a Lord Mayor's feast, or any other publick
entertainment. But this, and many others, I omit, being studious of
brevity.
Supposing that one thousand families in this city, would be constant
customers for infants flesh, besides others who might have it at merry
meetings, particularly at weddings and christenings, I compute that
Dublin would take off annually about twenty thousand carcasses; and the
rest of the kingdom (where probably they will be sold somewhat cheaper)
the remaining eighty thousand.
I can think of no one objection, that will possibly be raised against
this proposal, unless it should be urged, that the number of people will
be thereby much lessened in the kingdom. This I freely own, and 'twas
indeed one principal design in offering it to the world. I desire the
reader will observe, that I calculate my remedy for this one individual
Kingdom of Ireland, and for no other that ever was, is, or, I think,
ever can be upon Earth. Therefore let no man talk to me of other
expedients: Of taxing our absentees at five shillings a pound: Of using
neither cloaths, nor houshold furniture, except what is of our
own growth and manufacture: Of utterly rejecting the materials and
instruments that promote foreign luxury: Of curing the expensiveness of
pride, vanity, idleness, and gaming in our women: Of introducing a vein
of parsimony, prudence and temperance: Of learning to love our
country, wherein we differ even from Laplanders, and the inhabitants
of Topinamboo: Of quitting our animosities and factions, nor acting any
longer like the Jews, who were murdering one another at the very moment
their city was taken: Of being a little cautious not to sell our country
and consciences for nothing: Of teaching landlords to have at least one
degree of mercy towards their tenants. Lastly, of putting a spirit of
honesty, industry, and skill into our shop-keepers, who, if a resolution
could now be taken to buy only our native goods, would immediately unite
to cheat and exact upon us in the price, the measure, and the goodness,
nor could ever yet be brought to make one fair proposal of just dealing,
though often and earnestly invited to it.
Therefore I repeat, let no man talk to me of these and the like
expedients, 'till he hath at least some glympse of hope, that there will
ever be some hearty and sincere attempt to put them into practice.
But, as to my self, having been wearied out for many years with offering
vain, idle, visionary thoughts, and at length utterly despairing of
success, I fortunately fell upon this proposal, which, as it is wholly
new, so it hath something solid and real, of no expence and little
trouble, full in our own power, and whereby we can incur no danger
in disobliging England. For this kind of commodity will not bear
exportation, and flesh being of too tender a consistence, to admit a
long continuance in salt, although perhaps I could name a country, which
would be glad to eat up our whole nation without it.
After all, I am not so violently bent upon my own opinion, as to reject
any offer, proposed by wise men, which shall be found equally innocent,
cheap, easy, and effectual. But before something of that kind shall be
advanced in contradiction to my scheme, and offering a better, I desire
the author or authors will be pleased maturely to consider two points.
First, As things now stand, how they will be able to find food and
raiment for a hundred thousand useless mouths and backs. And secondly,
There being a round million of creatures in humane figure throughout
this kingdom, whose whole subsistence put into a common stock, would
leave them in debt two million of pounds sterling, adding those who are
beggars by profession, to the bulk of farmers, cottagers and labourers,
with their wives and children, who are beggars in effect; I desire
those politicians who dislike my overture, and may perhaps be so bold
to attempt an answer, that they will first ask the parents of these
mortals, whether they would not at this day think it a great happiness
to have been sold for food at a year old, in the manner I prescribe, and
thereby have avoided such a perpetual scene of misfortunes, as they have
since gone through, by the oppression of landlords, the impossibility of
paying rent without money or trade, the want of common sustenance, with
neither house nor cloaths to cover them from the inclemencies of the
weather, and the most inevitable prospect of intailing the like, or
greater miseries, upon their breed for ever.
I profess, in the sincerity of my heart, that I have not the least
personal interest in endeavouring to promote this necessary work, having
no other motive than the publick good of my country, by advancing
our trade, providing for infants, relieving the poor, and giving some
pleasure to the rich. I have no children, by which I can propose to
get a single penny; the youngest being nine years old, and my wife past
child-bearing.
STOP_WORDS = %w[the of and to a in for as or at it by that their this they is]
def word_counter(text)
alphabet = ('A'..'Z').to_a + ('a'..'z').to_a
# Create a hash for counting the words
# creating it by doing Hash.new(0) (instead of simply {})
# makes it so the default values of the hash are 0 instead of nil
hash = Hash.new(0)
# Split the text into a n array of words
pieces = text.split(/\b/)
# Select only words starting with a char from the alphabet
words = pieces.select do |piece|
alphabet.include?(piece[0])
end
# Iterate over the words
words.each do |word|
# Increment the value associated with the word
downcased_word = word.downcase
hash[downcased_word] += 1 unless STOP_WORDS.include?(downcased_word)
end
# Sorts the hash
# Which returns us an array (eg.: []) of arrays (eg.: ['word', 1])
sorted_array_of_arrays = hash.sort_by do |word, count|
count
end.reverse
# Create a hash to receive the now sorted words back
sorted_words_hash = {}
# Iterates over the array of words array to insert the (now sorted)
# info into a new hash
sorted_array_of_arrays.each do |element|
sorted_words_hash[element[0]] = element[1]
end
# Returns the sort words hash
return sorted_words_hash
end
require_relative './word_counter.rb'
describe "#word_counter" do
it "should count the words correctly" do
text = "I love ruby, and love coding"
expected = {
'I' => 1,
'love' => 2,
'ruby' => 1,
'and' => 1,
'coding' => 1
}
actual = word_counter(text)
expect(actual).to eq(expected)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment