Skip to content

Commit b4a2c58

Browse files
committed
final class 4 versions
1 parent 06fa671 commit b4a2c58

File tree

4 files changed

+74
-16
lines changed

4 files changed

+74
-16
lines changed

week-04/code/sherlock.txt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Project Gutenberg's The Adventures of Sherlock Holmes, by Arthur Conan Doyle
1+
Project Gutenberg's The Adventures of Sherlock Holmes, by Arthur Conan Doyle
22

33
This eBook is for the use of anyone anywhere at no cost and with
44
almost no restrictions whatsoever. You may copy it, give it away or
@@ -1137,7 +1137,7 @@ take in the future. I leave a photograph which he might care to
11371137
possess; and I remain, dear Mr. Sherlock Holmes,
11381138

11391139
"Very truly yours,
1140-
"IRENE NORTON, née ADLER."
1140+
"IRENE NORTON, ne ADLER."
11411141

11421142
"What a woman--oh, what a woman!" cried the King of Bohemia, when
11431143
we had all three read this epistle. "Did I not tell you how quick
@@ -1371,7 +1371,7 @@ assistant, Mr. Holmes; and I know very well that he could better
13711371
himself and earn twice what I am able to give him. But, after
13721372
all, if he is satisfied, why should I put ideas in his head?"
13731373

1374-
"Why, indeed? You seem most fortunate in having an employé who
1374+
"Why, indeed? You seem most fortunate in having an employ who
13751375
comes under the full market price. It is not a common experience
13761376
among employers in this age. I don't know that your assistant is
13771377
not as remarkable as your advertisement."
@@ -2097,7 +2097,7 @@ Merryweather, we must put the screen over that dark lantern."
20972097
"And sit in the dark?"
20982098

20992099
"I am afraid so. I had brought a pack of cards in my pocket, and
2100-
I thought that, as we were a partie carrée, you might have your
2100+
I thought that, as we were a partie carre, you might have your
21012101
rubber after all. But I see that the enemy's preparations have
21022102
gone so far that we cannot risk the presence of a light. And,
21032103
first of all, we must choose our positions. These are daring men,
@@ -2305,7 +2305,7 @@ hand in hand, hover over this great city, gently remove the
23052305
roofs, and peep in at the queer things which are going on, the
23062306
strange coincidences, the plannings, the cross-purposes, the
23072307
wonderful chains of events, working through generations, and
2308-
leading to the most outré results, it would make all fiction with
2308+
leading to the most outr results, it would make all fiction with
23092309
its conventionalities and foreseen conclusions most stale and
23102310
unprofitable."
23112311

@@ -2857,7 +2857,7 @@ attention at the time, and the whole of next day I was busy at
28572857
the bedside of the sufferer. It was not until close upon six
28582858
o'clock that I found myself free and was able to spring into a
28592859
hansom and drive to Baker Street, half afraid that I might be too
2860-
late to assist at the dénouement of the little mystery. I found
2860+
late to assist at the dnouement of the little mystery. I found
28612861
Sherlock Holmes alone, however, half asleep, with his long, thin
28622862
form curled up in the recesses of his armchair. A formidable
28632863
array of bottles and test-tubes, with the pungent cleanly smell
@@ -3084,8 +3084,8 @@ address asking him if he would come here. As I expected, his
30843084
reply was typewritten and revealed the same trivial but
30853085
characteristic defects. The same post brought me a letter from
30863086
Westhouse & Marbank, of Fenchurch Street, to say that the
3087-
description tallied in every respect with that of their employé,
3088-
James Windibank. Voilà tout!"
3087+
description tallied in every respect with that of their employ,
3088+
James Windibank. Voil tout!"
30893089

30903090
"And Miss Sutherland?"
30913091

@@ -3284,7 +3284,7 @@ jaw, it is surely very clear that that side is less illuminated
32843284
than the other. I could not imagine a man of your habits looking
32853285
at himself in an equal light and being satisfied with such a
32863286
result. I only quote this as a trivial example of observation and
3287-
inference. Therein lies my métier, and it is just possible that
3287+
inference. Therein lies my mtier, and it is just possible that
32883288
it may be of some service in the investigation which lies before
32893289
us. There are one or two minor points which were brought out in
32903290
the inquest, and which are worth considering."
@@ -3470,7 +3470,7 @@ young man's favour. Don't you see that you alternately give him
34703470
credit for having too much imagination and too little? Too
34713471
little, if he could not invent a cause of quarrel which would
34723472
give him the sympathy of the jury; too much, if he evolved from
3473-
his own inner consciousness anything so outré as a dying
3473+
his own inner consciousness anything so outr as a dying
34743474
reference to a rat, and the incident of the vanishing cloth. No,
34753475
sir, I shall approach this case from the point of view that what
34763476
this young man says is true, and we shall see whither that
@@ -10110,7 +10110,7 @@ with the help of a youth whom he had brought with him, and
1011010110
presently, to my very great astonishment, a quite epicurean
1011110111
little cold supper began to be laid out upon our humble
1011210112
lodging-house mahogany. There were a couple of brace of cold
10113-
woodcock, a pheasant, a pâté de foie gras pie with a group of
10113+
woodcock, a pheasant, a pt de foie gras pie with a group of
1011410114
ancient and cobwebby bottles. Having laid out all these luxuries,
1011510115
my two visitors vanished away, like the genii of the Arabian
1011610116
Nights, with no explanation save that the things had been paid
@@ -11546,7 +11546,7 @@ pleasant to me to observe, Watson, that you have so far grasped
1154611546
this truth that in these little records of our cases which you
1154711547
have been good enough to draw up, and, I am bound to say,
1154811548
occasionally to embellish, you have given prominence not so much
11549-
to the many causes célèbres and sensational trials in which I
11549+
to the many causes clbres and sensational trials in which I
1155011550
have figured but rather to those incidents which may have been
1155111551
trivial in themselves, but which have given room for those
1155211552
faculties of deduction and of logical synthesis which I have made
@@ -12159,7 +12159,7 @@ the nursery.
1215912159
"Two days later this same performance was gone through under
1216012160
exactly similar circumstances. Again I changed my dress, again I
1216112161
sat in the window, and again I laughed very heartily at the funny
12162-
stories of which my employer had an immense répertoire, and which
12162+
stories of which my employer had an immense rpertoire, and which
1216312163
he told inimitably. Then he handed me a yellow-backed novel, and
1216412164
moving my chair a little sideways, that my own shadow might not
1216512165
fall upon the page, he begged me to read aloud to him. I read for
@@ -12467,7 +12467,7 @@ figure, and the colour of your hair. Hers had been cut off, very
1246712467
possibly in some illness through which she has passed, and so, of
1246812468
course, yours had to be sacrificed also. By a curious chance you
1246912469
came upon her tresses. The man in the road was undoubtedly some
12470-
friend of hers--possibly her fiancé--and no doubt, as you wore
12470+
friend of hers--possibly her fianc--and no doubt, as you wore
1247112471
the girl's dress and were so like her, he was convinced from your
1247212472
laughter, whenever he saw you, and afterwards from your gesture,
1247312473
that Miss Rucastle was perfectly happy, and that she no longer

week-04/code/sherlock_small.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
One night--it was on the twentieth of March, 1888--I was
1+
One night--it was on the twentieth of March, 1888--I was
22
returning from a journey to a patient (for I had now returned to
33
civil practice), when my way led me through Baker Street. As I
44
passed the well-remembered door, which must always be associated

week-04/code/trigram.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#/usr/bin/ev python
2+
3+
"""
4+
Trigram.py
5+
6+
A solution to the trigram coding Kata:
7+
8+
http://codekata.pragprog.com/2007/01/kata_fourteen_t.html
9+
"""
10+
infilename = "sherlock_small.txt"
11+
#infilename = "sherlock.txt"
12+
13+
import string
14+
15+
# translation table for string.translate:
16+
# stuff I want to keep:
17+
valid = string.letters + "'"
18+
all = ''.join([chr(i) for i in range(256)])
19+
table = []
20+
for c in all:
21+
if c in valid:
22+
table.append(c)
23+
else:
24+
table.append(' ')
25+
table = ''.join(table)
26+
27+
# read it all into memory
28+
29+
#in_data = open(infilename, 'r').read()
30+
in_data = open(infilename, 'r').read()
31+
# Dictionary for results:
32+
word_pairs = {}
33+
34+
# lower-case everything to remove that complication:
35+
in_data = in_data.lower()
36+
# strip out the punctuation:
37+
in_data = in_data.translate(table)
38+
39+
#split into words (what about punctuation?)
40+
words = in_data.split()# loop through the words
41+
for i in range(len(words) - 2):
42+
pair = " ".join(words[i:i+2])
43+
follower = words[i+2]
44+
if pair in word_pairs:
45+
print "pair is repeated:", pair
46+
word_pairs[pair].append(follower)
47+
else:
48+
word_pairs[pair] = [follower]
49+
50+
# create some new text
51+
52+
import random
53+
new_text = []
54+
for i in range (10): #just do a few
55+
pair = random.sample(word_pairs, 1)
56+
57+
58+
print word_pairs

week-04/presentation-week04.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1533,7 +1533,7 @@ \section{Dictionaries and Sets}
15331533
\begin{itemize}
15341534
\item Coding Kata 14 - Dave Thomas \\
15351535
\url{http://codekata.pragprog.com/2007/01/ kata_fourteen_t.html}
1536-
\item See how far you can get on this task using “The Adventures of Sherlock Holmes” as input: sherlock.txt in the week04 directory (UTF-8)
1536+
\item See how far you can get on this task using “The Adventures of Sherlock Holmes” as input: sherlock.txt in the week04 directory (ascii)
15371537
\item This is intentionally open-ended and underspecified. There are many interesting decisions to make.
15381538
\end{itemize}
15391539

0 commit comments

Comments
 (0)