-- Feb 24 In-Class Exercise
rankProximity("to","be",2)
initialize u as -infinity.
set [u,v] as the first position where a cover of "to..be" is found with nextCover("to","be",-infinity).
now [u,v] = [3,4]
use the new u value from nextCover to select the first document to search with d = docid(u).
set d = 1.
initialize score and j to 0.
enter while(3 < infinity) loop.
test if d=1 < docid(3), false.
so, append the value 1/(4-3+1) to score. (score = 1/2)
update [u,v] with nextCover("to","be",3). ([u,v] = [4,6])
reiterate while loop (4 < infinity).
test if d=1 < docid(4), false.
so, append the value 1/(6-4+1) to score. (score = 1/2 + 1/3 = 5/6)
update [u,v] with nextCover("to","be",4). ([u,v] = [1,2])
reiterate while loop (1 < infinity).
test if d=1 < docid(1), true.
append 1 to j (j = 1).
write Result[1].docid = 1.
write Result[1].score = score = 5/6.
set d = 2.
set score = 0.
then, append the value 1/(1-0+1) to score (score = 1/2).
update [u,v] with nextCover("to","be",1). ([u,v] = [2,5])
reiterate while loop (2 < infinity).
test if d=2 < docid(2), false.
so, append the value 1/(5-2+1) to score (score = 1/2 + 1/4).
update [u,v] with nextCover("to","be",2). ([u,v] = [5,6])
reiterate while loop.
test if d=2 < docid(5), false.
so, append the value 1/(6-5+1) to score (score = 1/2 + 1/4 + 1/2).
update [u,v] with nextCover("to","be",5). [u,v] = [infinity,infinity].
exit while loop since (infinity < infinity) is false.
test if d=2 < infinity, true.
append 1 to j (j = 2).
write Result[2].docid = 2.
write Result[2].score = score = 5/4.
sort Result[1..j] by score -> [(5/4,2), (5/6,1)].
return Result[1..j] = [(5/4,2), (5/6,1)].
(
Edited: 2021-02-24)
<nowiki>
rankProximity("to","be",2)
initialize u as -infinity.
set [u,v] as the first position where a cover of "to..be" is found with nextCover("to","be",-infinity).
now [u,v] = [3,4]
use the new u value from nextCover to select the first document to search with d = docid(u).
set d = 1.
initialize score and j to 0.
enter while(3 < infinity) loop.
test if d=1 < docid(3), false.
so, append the value 1/(4-3+1) to score. (score = 1/2)
update [u,v] with nextCover("to","be",3). ([u,v] = [4,6])
reiterate while loop (4 < infinity).
test if d=1 < docid(4), false.
so, append the value 1/(6-4+1) to score. (score = 1/2 + 1/3 = 5/6)
update [u,v] with nextCover("to","be",4). ([u,v] = [1,2])
reiterate while loop (1 < infinity).
test if d=1 < docid(1), true.
append 1 to j (j = 1).
write Result[1].docid = 1.
write Result[1].score = score = 5/6.
set d = 2.
set score = 0.
then, append the value 1/(1-0+1) to score (score = 1/2).
update [u,v] with nextCover("to","be",1). ([u,v] = [2,5])
reiterate while loop (2 < infinity).
test if d=2 < docid(2), false.
so, append the value 1/(5-2+1) to score (score = 1/2 + 1/4).
update [u,v] with nextCover("to","be",2). ([u,v] = [5,6])
reiterate while loop.
test if d=2 < docid(5), false.
so, append the value 1/(6-5+1) to score (score = 1/2 + 1/4 + 1/2).
update [u,v] with nextCover("to","be",5). [u,v] = [infinity,infinity].
exit while loop since (infinity < infinity) is false.
test if d=2 < infinity, true.
append 1 to j (j = 2).
write Result[2].docid = 2.
write Result[2].score = score = 5/4.
sort Result[1..j] by score -> [(5/4,2), (5/6,1)].
return Result[1..j] = [(5/4,2), (5/6,1)].
</nowiki>