SECTION 29 / 31

Map each pronoun to the nearest earlier noun

1 min read
For illustrative noun positions [1,3,8,14,19] and pronoun17, the nearest earlier noun is position14.
For illustrative noun positions [1,3,8,14,19] and pronoun17, the nearest earlier noun is position14.
REAL COURSE DATA · KEYS, COUNTS AND CONNECTIONS

Map each pronoun to its preceding noun

Follow the dictionary as its keys and values change. Predict each lookup or update before revealing the next step.

Ready

CURRENT RECORD / VALUE

Ready to begin

No records have been processed. Start with Next step.

What we remember

Processed
0

Predict the next key, whether it already exists, and the value that will be stored.

matchD = {}
foreach p in partOfSpeech["Pronoun"] {
    matched = -1
    foreach n in partOfSpeech["Noun"] {
        if (n < p) {
            matched = n
        }
        else {
            exitloop
        }
    }
    matchD[p] = matched
}

For each pronoun p, reset matched to −1. Walk the sorted noun positions. Every n<p is a candidate; updating matched as n increases leaves the largest position below p. At the first n≥p, exit only the INNER loop and store matchD[p]. Then continue with the next pronoun.

Pronoun position and wordChosen noun position and word
0 It−1: no preceding noun
9 his4 Swaminathan
11 He10 eyes.
27 it26 Sunday,
40 He39 discipline.
55 his54 Vedanayagam,
61 his59 headmaster

This is the lecture’s deliberately simple positional heuristic. It can choose a grammatically wrong antecedent: “He” at 11 is mapped to “eyes.” at 10. It demonstrates dictionary/list processing, not a complete English pronoun resolver. The −1 result is a sentinel, never a valid word lookup.

Try it yourself

Why must matched reset for every pronoun?

Show explained answer

Otherwise a pronoun with no preceding noun could inherit an unrelated earlier result.

Try it yourself

Why can the loop stop at n≥p?

Show explained answer

All later noun positions are at least as large because the list is sorted.

Try it yourself

What does the source rule return for the paragraph’s first word “It” at 0?

Show explained answer

−1, because no noun position is earlier than 0.

YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑