aboutsummaryrefslogtreecommitdiff
path: root/challenge-024
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-09-08 08:33:55 +0100
committerGitHub <noreply@github.com>2019-09-08 08:33:55 +0100
commit2e297a6d377a83372e8be5c6f1524caa6720649f (patch)
tree0dfe0ad649fbd45dc23e07f8a628c9f9cf155248 /challenge-024
parent75a3cc3367548220bbb2bcad6f2d7e52cc973a2d (diff)
parent6441af73bab6df2132fb131575602aa9ba863b52 (diff)
downloadperlweeklychallenge-club-2e297a6d377a83372e8be5c6f1524caa6720649f.tar.gz
perlweeklychallenge-club-2e297a6d377a83372e8be5c6f1524caa6720649f.tar.bz2
perlweeklychallenge-club-2e297a6d377a83372e8be5c6f1524caa6720649f.zip
Merge pull request #604 from adamcrussell/challenge-024
Challenge 024
Diffstat (limited to 'challenge-024')
-rw-r--r--challenge-024/adam-russell/blog.txt1
-rw-r--r--challenge-024/adam-russell/blog1.txt1
-rw-r--r--challenge-024/adam-russell/data/arrow.txt15
-rw-r--r--challenge-024/adam-russell/data/balloon.txt29
-rw-r--r--challenge-024/adam-russell/data/call.txt9
-rw-r--r--challenge-024/adam-russell/data/catriona.txt24
-rw-r--r--challenge-024/adam-russell/data/eighty.txt26
-rw-r--r--challenge-024/adam-russell/data/fang.txt12
-rw-r--r--challenge-024/adam-russell/data/kidnapped.txt13
-rw-r--r--challenge-024/adam-russell/perl5/ch-1.sh1
-rw-r--r--challenge-024/adam-russell/perl5/ch-2.pl77
11 files changed, 208 insertions, 0 deletions
diff --git a/challenge-024/adam-russell/blog.txt b/challenge-024/adam-russell/blog.txt
new file mode 100644
index 0000000000..b838b1da20
--- /dev/null
+++ b/challenge-024/adam-russell/blog.txt
@@ -0,0 +1 @@
+https://adamcrussell.livejournal.com/8122.html
diff --git a/challenge-024/adam-russell/blog1.txt b/challenge-024/adam-russell/blog1.txt
new file mode 100644
index 0000000000..10db5957a4
--- /dev/null
+++ b/challenge-024/adam-russell/blog1.txt
@@ -0,0 +1 @@
+https://adamcrussell.livejournal.com/8285.html
diff --git a/challenge-024/adam-russell/data/arrow.txt b/challenge-024/adam-russell/data/arrow.txt
new file mode 100644
index 0000000000..1754d2fa6a
--- /dev/null
+++ b/challenge-024/adam-russell/data/arrow.txt
@@ -0,0 +1,15 @@
+On a certain afternoon, in the late springtime, the bell upon Tunstall
+Moat House was heard ringing at an unaccustomed hour. Far and near, in
+the forest and in the fields along the river, people began to desert
+their labours and hurry towards the sound; and in Tunstall hamlet a group
+of poor country-folk stood wondering at the summons.
+
+Tunstall hamlet at that period, in the reign of old King Henry VI., wore
+much the same appearance as it wears to-day. A score or so of houses,
+heavily framed with oak, stood scattered in a long green valley ascending
+from the river. At the foot, the road crossed a bridge, and mounting on
+the other side, disappeared into the fringes of the forest on its way to
+the Moat House, and further forth to Holywood Abbey. Half-way up the
+village, the church stood among yews. On every side the slopes were
+crowned and the view bounded by the green elms and greening oak-trees of
+the forest.
diff --git a/challenge-024/adam-russell/data/balloon.txt b/challenge-024/adam-russell/data/balloon.txt
new file mode 100644
index 0000000000..6dda8b0bd3
--- /dev/null
+++ b/challenge-024/adam-russell/data/balloon.txt
@@ -0,0 +1,29 @@
+The End of a much-applauded Speech.--The Presentation of Dr. Samuel
+Ferguson.--Excelsior.--Full-length Portrait of the Doctor.--A Fatalist
+convinced.--A Dinner at the Travellers’ Club.--Several Toasts for the
+Occasion.
+
+There was a large audience assembled on the 14th of January, 1862, at
+the session of the Royal Geographical Society, No. 3 Waterloo
+Place, London. The president, Sir Francis M----, made an important
+communication to his colleagues, in an address that was frequently
+interrupted by applause.
+
+This rare specimen of eloquence terminated with the following sonorous
+phrases bubbling over with patriotism:
+
+“England has always marched at the head of nations” (for, the reader
+will observe, the nations always march at the head of each other), “by
+the intrepidity of her explorers in the line of geographical discovery.”
+ (General assent). “Dr. Samuel Ferguson, one of her most glorious sons,
+will not reflect discredit on his origin.” (“No, indeed!” from all parts
+of the hall.)
+
+“This attempt, should it succeed” (“It will succeed!”), “will complete
+and link together the notions, as yet disjointed, which the world
+entertains of African cartology” (vehement applause); “and, should it
+fail, it will, at least, remain on record as one of the most daring
+conceptions of human genius!” (Tremendous cheering.)
+
+“Huzza! huzza!” shouted the immense audience, completely electrified by
+these inspiring words.
diff --git a/challenge-024/adam-russell/data/call.txt b/challenge-024/adam-russell/data/call.txt
new file mode 100644
index 0000000000..e9059de1d3
--- /dev/null
+++ b/challenge-024/adam-russell/data/call.txt
@@ -0,0 +1,9 @@
+Buck did not read the newspapers, or he would have known that trouble
+was brewing, not alone for himself, but for every tide-water dog,
+strong of muscle and with warm, long hair, from Puget Sound to San
+Diego. Because men, groping in the Arctic darkness, had found a yellow
+metal, and because steamship and transportation companies were booming
+the find, thousands of men were rushing into the Northland. These men
+wanted dogs, and the dogs they wanted were heavy dogs, with strong
+muscles by which to toil, and furry coats to protect them from the
+frost.
diff --git a/challenge-024/adam-russell/data/catriona.txt b/challenge-024/adam-russell/data/catriona.txt
new file mode 100644
index 0000000000..3b38fbc6ba
--- /dev/null
+++ b/challenge-024/adam-russell/data/catriona.txt
@@ -0,0 +1,24 @@
+The 25th day of August, 1751, about two in the afternoon, I, David
+Balfour, came forth of the British Linen Company, a porter attending me
+with a bag of money, and some of the chief of these merchants bowing me
+from their doors. Two days before, and even so late as yestermorning, I
+was like a beggar-man by the wayside, clad in rags, brought down to my
+last shillings, my companion a condemned traitor, a price set on my own
+head for a crime with the news of which the country rang. To-day I was
+served heir to my position in life, a landed laird, a bank porter by me
+carrying my gold, recommendations in my pocket, and (in the words of the
+saying) the ball directly at my foot.
+
+There were two circumstances that served me as ballast to so much sail.
+The first was the very difficult and deadly business I had still to
+handle; the second, the place that I was in. The tall, black city, and
+the numbers and movement and noise of so many folk, made a new world for
+me, after the moorland braes, the sea-sands and the still country-sides
+that I had frequented up to then. The throng of the citizens in
+particular abashed me. Rankeillor’s son was short and small in the
+girth; his clothes scarce held on me; and it was plain I was ill
+qualified to strut in the front of a bank-porter. It was plain, if I did
+so, I should but set folk laughing, and (what was worse in my case) set
+them asking questions. So that I behooved to come by some clothes of my
+own, and in the meanwhile to walk by the porter’s side, and put my hand
+on his arm as though we were a pair of friends.
diff --git a/challenge-024/adam-russell/data/eighty.txt b/challenge-024/adam-russell/data/eighty.txt
new file mode 100644
index 0000000000..971f0f08e3
--- /dev/null
+++ b/challenge-024/adam-russell/data/eighty.txt
@@ -0,0 +1,26 @@
+Mr. Phileas Fogg lived, in 1872, at No. 7, Saville Row, Burlington
+Gardens, the house in which Sheridan died in 1814. He was one of the
+most noticeable members of the Reform Club, though he seemed always to
+avoid attracting attention; an enigmatical personage, about whom little
+was known, except that he was a polished man of the world. People said
+that he resembled Byron--at least that his head was Byronic; but he was
+a bearded, tranquil Byron, who might live on a thousand years without
+growing old.
+
+Certainly an Englishman, it was more doubtful whether Phileas Fogg was
+a Londoner. He was never seen on 'Change, nor at the Bank, nor in the
+counting-rooms of the "City"; no ships ever came into London docks of
+which he was the owner; he had no public employment; he had never been
+entered at any of the Inns of Court, either at the Temple, or Lincoln's
+Inn, or Gray's Inn; nor had his voice ever resounded in the Court of
+Chancery, or in the Exchequer, or the Queen's Bench, or the
+Ecclesiastical Courts. He certainly was not a manufacturer; nor was he
+a merchant or a gentleman farmer. His name was strange to the
+scientific and learned societies, and he never was known to take part
+in the sage deliberations of the Royal Institution or the London
+Institution, the Artisan's Association, or the Institution of Arts and
+Sciences. He belonged, in fact, to none of the numerous societies
+which swarm in the English capital, from the Harmonic to that of the
+Entomologists, founded mainly for the purpose of abolishing pernicious
+insects.
+
diff --git a/challenge-024/adam-russell/data/fang.txt b/challenge-024/adam-russell/data/fang.txt
new file mode 100644
index 0000000000..30bd899bb7
--- /dev/null
+++ b/challenge-024/adam-russell/data/fang.txt
@@ -0,0 +1,12 @@
+Dark spruce forest frowned on either side the frozen waterway. The trees
+had been stripped by a recent wind of their white covering of frost, and
+they seemed to lean towards each other, black and ominous, in the fading
+light. A vast silence reigned over the land. The land itself was a
+desolation, lifeless, without movement, so lone and cold that the spirit
+of it was not even that of sadness. There was a hint in it of laughter,
+but of a laughter more terrible than any sadness--a laughter that was
+mirthless as the smile of the sphinx, a laughter cold as the frost and
+partaking of the grimness of infallibility. It was the masterful and
+incommunicable wisdom of eternity laughing at the futility of life and
+the effort of life. It was the Wild, the savage, frozen-hearted
+Northland Wild.
diff --git a/challenge-024/adam-russell/data/kidnapped.txt b/challenge-024/adam-russell/data/kidnapped.txt
new file mode 100644
index 0000000000..0fe6c7616a
--- /dev/null
+++ b/challenge-024/adam-russell/data/kidnapped.txt
@@ -0,0 +1,13 @@
+I will begin the story of my adventures with a certain morning early in
+the month of June, the year of grace 1751, when I took the key for the
+last time out of the door of my father’s house. The sun began to shine
+upon the summit of the hills as I went down the road; and by the time
+I had come as far as the manse, the blackbirds were whistling in the
+garden lilacs, and the mist that hung around the valley in the time of
+the dawn was beginning to arise and die away.
+
+Mr. Campbell, the minister of Essendean, was waiting for me by the
+garden gate, good man! He asked me if I had breakfasted; and hearing
+that I lacked for nothing, he took my hand in both of his and clapped it
+kindly under his arm.
+
diff --git a/challenge-024/adam-russell/perl5/ch-1.sh b/challenge-024/adam-russell/perl5/ch-1.sh
new file mode 100644
index 0000000000..286af7e33a
--- /dev/null
+++ b/challenge-024/adam-russell/perl5/ch-1.sh
@@ -0,0 +1 @@
+perl -d -e 0
diff --git a/challenge-024/adam-russell/perl5/ch-2.pl b/challenge-024/adam-russell/perl5/ch-2.pl
new file mode 100644
index 0000000000..f1e5f7e76b
--- /dev/null
+++ b/challenge-024/adam-russell/perl5/ch-2.pl
@@ -0,0 +1,77 @@
+use strict;
+use warnings;
+##
+# Create a script to implement full text search functionality using Inverted Index.
+##
+use boolean;
+use constant DATA_DIR => "./data/";
+
+sub index_contents{
+ my($index, $file) = @_;
+ my %seen;
+ my $contents;
+ do{
+ local $/;
+ open(F, $file);
+ $contents = <F>;
+ $contents =~ tr/-/ /;
+ $contents =~ s/[^[:ascii:]]//g;
+ $contents =~ s/[[:punct:]]//g;
+ close(F);
+ };
+ my $d = DATA_DIR;
+ $file =~ s/$d//g;
+ my @words = split(/\s+/, $contents);
+ @words = map { lc($_) } @words;
+ for my $word (@words){
+ if(!$index->{$word}){
+ $index->{$word} = [$file];
+ $seen{$word} = true;
+ }
+ if($index->{$word} && !$seen{$word}){
+ push @{$index->{$word}}, $file;
+ $seen{$word} = true;
+ }
+ }
+}
+
+sub print_index{
+ my($index) = @_;
+ my($word, $documents);
+ format INDEX_HEADER =
+ ------------------------------------------------------------------------------------------------------
+ |Word | Documents |
+ ------------------------------------------------------------------------------------------------------
+.
+ format INDEX =
+ |@<<<<<<<<<<<<<<|@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<|
+ $word, $documents
+.
+ format INDEX_FOOTER =
+ ------------------------------------------------------------------------------------------------------
+.
+ $~ = "INDEX_HEADER";
+ write;
+
+ $~ = "INDEX";
+ for my $w (sort keys %{$index}){
+ $word = $w;
+ $documents = join(", ", @{$index->{$w}});
+ write;
+ }
+
+ $~ = "INDEX_FOOTER";
+ write;
+}
+
+MAIN:{
+ my %index;
+ opendir(DATA, DATA_DIR);
+ while(my $file = readdir(DATA)){
+ if(-f DATA_DIR.$file){
+ index_contents(\%index, DATA_DIR.$file);
+ }
+ }
+ close(DATA);
+ print_index(\%index);
+}