


























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



























Department of Computer Science — University of San Francisco – p.1/
Department of Computer Science — University of San Francisco – p.3/
Department of Computer Science — University of San Francisco – p.4/
Department of Computer Science — University of San Francisco – p.7/
Department of Computer Science — University of San Francisco – p.9/
Department of Computer Science — University of San Francisco – p.10/
S,^ a^
1-gram^
distribution
n =^ length(S)words^ =
array[n+1] best^ = array[n+1]
(n+1)*^
best[0]
for^ i^ =
1 to^
n for^ j^ =
0 to^
i^ -^1 word^ =
S[j:i]
##get
the^ substring
from^
j^ to^ i
w =^ length(word)if^ (P[word]
x best[i
-^ w]^ >=
best[i])
best[i]
=^ P[word]
x^ best[i
-^ w]
words[i]
= word ###^ now
get^ best
words result^
i =^ n while^ i
^0 push words[i]
onto^
result
i^ =^ i^
-^ len(words[i]) return^
result,
best[i]
Department of Computer Science — University of San Francisco – p.12/
P(cat)
P(cattle)
P(fish)
all^ other
1-grams
are^ 0.001. best[0]
i:^ 1,^ j:
0 word:
’c’.^
w =^1
0.001^ *
best[1]
words[1]
= ’c’ i =^ 2,^
j^ =^0
word^ =^
’ca’,^
w^ =^2
best[2]
words[2]
= ’ca’ i =^ 2,^
j^ =^1
word^ =^
’a’,^ w
Department of Computer Science — University of San Francisco – p.13/
w=
0.001^ *
1.0^ > 0.0 (^) best[4]^ =^
words[4]
= ’catt’ i=4,j=
word^
=^ ’att’,
w=
0.001^ *
i=4,^ j=2,
word=’tt’,
w=
0.001^ *
i=4,^ j=3,
word=’t’,
w=
0.001^ *
Department of Computer Science — University of San Francisco – p.15/
w=
0.001^ *
1.0^ > 0.0 (^) best[5]^ =^ 0.001word[5]^ =^ ’cattl’ i=5,^ j=1,
word=’attl’,
w=
0.001^ *
i=5,^ j=2,
word=’ttl’,
w=
0.001^ *
i=5,^ j=3,
word=’tl’,
w=
0.001^ *
i=5,^ j=4,
word=’l’,
w=
0.001^ *
Department of Computer Science — University of San Francisco – p.16/
words:^
[’c’^ ’ca’
’cat’^
’catt’
’cattl’
’cattle’
’cattlef’
’cattlefi’
’cattlefis’
’fish’] i =^10 push^ ’fish’
onto^
result i =^ i-4push^ ’cattle’
onto^
result
i =^0
Department of Computer Science — University of San Francisco – p.18/
Department of Computer Science — University of San Francisco – p.19/