2017年5月24日水曜日

開発環境

Think Perl 6: How to Think Like a Computer Scientist (Laurent Rosenfeld(著)、Allen B. Downey(著)、Oreilly & Associates Inc)のPart 1(Starting with the basics)、Chapter 11(Case Study: Data Structure Selection)の Word Frequency Analysis、Exercise: 1、2、3、4.を取り組んでみる。

Exercise: 1、2、3、4.

コード(Emacs)

#!/usr/bin/env perl6
# -*- coding: utf-8 -*-

say '1, 2.';

my $filename = '54767-0.txt';
my %words;
my $total = 0;

my $reg = rx/<[-!"#$%&'()*+,./:;<=>?@\[\\\]^_`{|}~”“’]>/;

for $filename.IO.lines -> $line is copy {
    $line ~~ s:g/<$reg>//;
    for $line.words -> $word is copy {
        $word = lc $word;
        if %words{$word} {
            %words{$word}++;
        } else {
            %words{$word} = 1;
        }
        $total++;
    }
}

say %words.keys.elems;
say $total;
say [+] %words.values;

say '3.';
my @words = sort { %words{$^b} cmp %words{$^a} }, %words.keys;
for @words[0..19] -> $word {
    say "$word: %words{$word}";
}

say '4.';
my %words_list = map { $_ => 1}, 'words.txt'.IO.lines;
for %words.keys -> $word {
    say $word unless %words_list{$word};
}

入出力結果(Terminal, REPL)

$ ./sample1.pl
1, 2.
6597
68907
68907
3.
the: 4322
and: 2712
to: 1960
of: 1726
a: 1714
in: 1260
it: 878
he: 798
was: 776
i: 653
they: 653
that: 639
you: 627
for: 591
with: 581
his: 535
as: 525
on: 523
had: 488
but: 370
4.
tunnelshaped
silvergray
enraptured
goodhearted
livesto
bearhunts
isaac
waterhouse
rusties
america
kindsfrench
m
manythen
straightgrained
smullen
daythree
turk
shiptimber
boomirons
mannering
yawlboat
creetur
containgazette
elijah
sparmakers
potatoballs
spindleshanked
æschylus
canada
millbrook
revolutioneven
deckload
284
ak
william
sufficientgive
housemake
60
forestaysail
april
shovewindows
84116
cornhouse
principled
islandszions
carolina
rhiness
1f3
sich
twentyeight
1d
crusoe
beartraps
aleak
himselfa
ireland
livescouldnt
larning
lampblack
influenced
keigler
‘long
16mo
httpwwwpgdpnet
monstrous
ebook
theyre
boathis
africa
mannerings
547670txt
outfor
steambox
sam
consarn
xvi
ninetysix
o
capitally
therell
bennie
recalk
xviii
clarke
doyou
rainproof
restingplace
december
timeterrible
hed
135
nauseousstandard
knittingwork
fairbanks
snowcovered
shipcarpenters
moreone
masterstrain
minnie
sundayschool
centinel
loveas
appliances
metaphoric
doacorns
beartrap
bradley
november
fred
havent
joeyes
fishingholes
kellogg
thawy
woodsmixed
newburyport
2017
leanto
online
thistaking
c
owna
scotlandwhere
illust
boxtraps
salem
indomitable
hotscorching
tewel
twentyfive
anutting
bountyanywhere
bradish
delightful
springgun
thomaston
longwinded
october
‘wheres
kelloggs
stumppulling
drawbill
xv
ann
imperfect
logsbut
1f2
cousinpretty
pearsons
sandand
ralph
beardrunk
deada
dr
creeturs
gafftopsail
501c3
300
wholl
inhabitants
steeltrap
50
firebrand
benjaminall
upa
1e4
martingale
99775
unusualfor
burmah
theyll
54767
unlookedfor
gutenbergtm
crossroot
liverpool
perkins
betterhearted
babys
portland
australian
169
bowholes
eva
stalehome
europe
ceilingplank
transcribers
andrewson
neely
newman
1c
sailingmaster
150
youve
drawshave
kingston
richards
gregory
saddlebags
3
scotland
matteroffact
reubens
didholding
dugoutand
bullmoose
merchantability
spaniards
suppertable
charitable
grassside
robinson
frontyard
loadedand
2001
karl
clapboarded
rudderirons
cadizfor
hopvine
shipbuilding
apthorp
upanddown
forebraces
276
hotnot
llc
afternoonand
cumberland
timesdont
january
agreeably
pricethere
viii
middleaged
1831
wouldnt
b
russia
unenforceability
christmas
doorstone
1871
supplemented
sheephouse
1f6
somers
hardfrozen
wantto
switzerland
howlings
dollarsthree
storybooks
broadaxeman
250
katy
yelf
40
stroudwater
wagessix
charley
onethe
thencanvas
framehouse
lostthen
anchorstock
sailmaking
mississippi
onethough
diversified
13
apthorps
danish
thurstons
shiplarge
foreplaned
martinique
2
notstoves
breastwork
sunday
sartain
riverdriving
whos
waistcoat
ofyou
1e8
reënforce
waterwheel
woodthat
whaleboats
crabtree
axehandle
wwwgutenbergorglicense
1b
storyandahalf
blackpassing
rhine
englandand
indian
‘o
logsthe
diamondshaped
312
closelycaught
finelooking
1812
gutenberg
messrs
itive
yarmouth
springpole
1f4
email
eatons
beaverskins
cobwork
charlies
crusoes
mustnt
aint
foller
carlos
selfsacrificing
effortsthe
grimess
aniseseed
bellmuzzled
e
cheapgood
breathingholes
5961887
eaton
1805
fewthe
indies
g
awaya
evas
chainplates
disclaimer
internet
electronically
buildingsand
1f1
belgium
likeway
logfour
breakfasttable
xvii
workhours
starrett
couldnt
246
646221541
xii
64
1e1
po
20
‘may
flatturnips
grovebehind
edgar
wwwgutenbergorgcontact
yankee
‘raising
sawpit
x
housefloor
foughta
oxens
shant
cornhouses
cornfield
swedenwhich
cowcumber
cuba
200
backwoodsmans
45c
columbian
neednt
anchorcharlie
halftorpid
fourandsix
vols
weve
dosomethings
iv
162
spanish
breastplate
oldsettled
williams
louise
writingsr
charlie
merrithew
sternposts
gbnewbypglaforg
downloading
seventyfive
sentimentality
88
processthe
rideout
1f5
29th
richard
forjust
266
foretopmast
125
walter
cæsar
orlando
readerwebster
draughtsman
suppertime
wellbuilt
foresticks
30
wwwgutenbergorg
teagrounds
woodville
pglaf
miletrap
rattletrap
commissionsweeten
ein
pitchwhich
chimneythe
upmake
jutland
31
blaisdell
1f
warrantnot
xxi
upand
isaacs
wwwgutenbergorgdonate
danforth
hannah
gonechain
jr
indiaman
codline
irish
sailcloth
pilotboat
brushful
pote
sailshavent
womens
tigego
oxnards
boatmodel
archiveamerican
vi
rockmaple
murch
beto
mainewith
st
knighterrantry
cradleknolls
cherrytree
547670zip
steeltraps
forgetrough
fishskin
seedcorn
104
rhines
nast
spaniard
‘a
germany
eightday
backsticks
148
generalmuster
anythingat
h
earthmade
ricker
michael
dashaway
boatswithout
6
childrenphiladelphia
1e9
‘stuboy
cervantes
stickworth
tonsa
vesselload
breechpin
christian
9
saccarappa
foxpen
pigeonnet
british
thereand
tontimber
transient
ropeyarn
risingline
hasnt
oldgrowth
tige
boatbuilder
experienced
storypage
cretur
seaboat
guesswork
unperceived
thorndike
extravagancy
gutenbergtms
xxiii
spenti
gutenbergs
admonition
234
toboggin
july
tenhour
treenailed
straightforwardness
1794
somebodys
firstrate
rightangled
seawinds
a
delaware
v
canoesof
j
wristjoints
ucayga
1e2
1e5
oclock
librariesladies
pitifulest
oxwagons
joooo
ladys
profitmaking
firebrands
smullens
squashvines
‘he
nationsben
hoosiers
longwith
☞
summerhouse
vii
burnsquashes
101
menofwar
cruikshank
trestletrees
waterline
faroff
elses
agoing
washbench
firelight
billethead
90
electrotyped
dayshe
xxii
chebacco
goodhue
australia
incalculabletoledo
americans
enobling
ourselvessay
legendsall
shepard
cts
77
drogers
wovena
knox
15th
somebodyeither
theodolite
twoandtwenty
indians
venturewent
islanda
reconnoitre
lilyroots
herechopping
tuesday
219
eastrd
tiges
boxtrap
118
teamsix
elwell
ix
boynature
treesanything
oncefrom
childrens
fannie
hypertext
80
russians
purgativesthe
wayat
hardscrabble
wayne
edwards
ive
buttbolt
bestnews
shipto
ratemaking
manofwar
radford
cadiz
wiscasset
privately
themwhich
suppera
oldfashioned
bradishs
r
xx
withand
augerhole
godsoe
etc
ascii
mackerelhooks
1e6
antonio
homeand
sydney
thatll
fishoil
sams
204
arkto
thats
riverdale
birchbark
madewhose
eightyfive
manys
marblehead
mudpuddle
w
laterof
mrs
twentyone
plumbline
thirtyfour
correspondingly
shotand
pg
whiteoak
wasnt
smokehole
breasthooks
france
78
discouragedit
joel
‘the
non
s
ploughings
juicyand
campkettle
dipseylead
britain
i
mr
bradford
xiv
rippleton
expulsive
harumscarum
xix
airholes
1500
253
shouldnt
portsmouth
andersen
topgallant
irs
amidships
seyton
timen
fishinglines
saturday
bearhow
moccasons
offoccupied
champlain
isnt
laborthe
pettigrews
crossband
channelo
england
reformation
mainyard
jurymasts
unremittingly
monday
anxiouslyexpected
watermillions
fiftyone
warwhoop
declivity
huntingknives
springguns
studdingsail
draughtingboard
dont
newby
havana
highlyornamented
elizabeth
5
roberts
twostory
freds
sallys
boatbuilding
breachy
fortyfive
quarterdeck
hammond
4
flyingjib
york
1783
httpwwwgutenbergorg547654767
newfangled
hadnt
cowyard
northrd
sternpost
xxv
23
1
undeceived
yeeees
dorcas
asis
1e
handspike
american
frenchman
motionsand
pigeonbed
thirtysix
preventerbraces
1a
19
wolftrap
manufactory
y
im
harborput
grapplingwhich
oneno
calkingiron
utf8
squaresail
‘that
joinerwork
eend
virginia
cowden
mary
55
marm
christianity
ile
chesley
didnt
millcranks
criticise
awayyou
solicitations
whitenosed
smellslike
peterson
801
topgallantsail
oliver
broadmouthed
mastercalker
casco
youll
oxgoad
griffinshes
substance
coveif
‘you
bearpage
disclaimers
groundsparrow
thesee
captaingeneral
youre
honeyjust
gubtail
mahogany
undoingfor
nonproprietary
homefeeling
twould
stevens
coalkiln
‘quicksilver
redistribution
twentysix
scribeschristian
iii
oxenthe
youd
buttbolted
despondingly
windlassbitts
vol
instituted
pasturage
1e7
xxvi
theyve
june
188
enterprising
ebooks
james
administered
750175
tarpit
trademarkcopyright
809
‘rickers
otterslides
african
grassground
xxiv
seth
breathinghole
‘hardscrabble
blewjust
ii
maine
xiii
mudholes
harvesttime
nobodyor
vesselany
bellowssome
cartwheels
merrill
robert
lowvoiced
chokecherry
spritsail
t
1e3
twentytwo
nabby
nowno
45
1870
kate
goadpage
5000
hans
jacob
redburn
shouldntbefore
$

0 コメント:

コメントを投稿