2.1.3 A Simple Example
Suppose we wanted to write a RE to find cases of the English article the. A simple (but incorrect) pattern might be:
/the/
One problem is that this pattern will miss the word when it begins a sentence and hence is capitalized (i.e., The). This might lead us to the following pattern:
/[tT]he/
But we will still incorrectly return texts with the embedded in other words (e.g., other or theology). So we need to specify that we want instances with a word boundary on both sides:
$$ \mathrm{\mathord{\langle b}\mathrm{\it{t T}}\mathrm{\it]}}h e\mathrm{\it{\theequation b/}} $$
Suppose we wanted to do this without the use of /\\b/? We might want this since /\\b/ won't treat underscores and numbers as word boundaries; but we might want to find the in some context where it might also have underlines or numbers nearby (the_ or the25). We need to specify that we want instances in which there are no alphabetic letters on either side of the the:
$$ /[\hat{a}-z\mathrm{A-Z}][t T]h e[\hat{a}-z\mathrm{A-Z}]\Big/ $$
But there is still one more problem with this pattern: it won't find the word the when it begins a line. This is because the regular expression [^a-zA-Z], which we used to avoid embedded thes, implies that there must be some single (although non-alphabetic) character before the the. We can avoid this by specifying that before the the we require either the beginning-of-line or a non-alphabetic character, and the same at the end of the line:
$$ \left/(\hat{}\right\vert\left[\hat{a}\mathrm{a-z}\mathrm{A-Z}\right])\left[\mathrm{t T}\right]\mathrm{h e}(\left[\hat{a}\mathrm{a-z}\mathrm{A-Z}\right]\left\vert\mathrm{}\right.)/ $$
FALSE POSITIVES FALSE NEGATIVES
The process we just went through was based on fixing two kinds of errors: false positives, strings that we incorrectly matched like other or there, and false negatives, strings that we incorrectly missed, like The. Addressing these two kinds of errors comes up again and again in building and improving speech and language processing systems. Reducing the error rate for an application thus involves two antagonistic efforts:
• Increasing accuracy (minimizing false positives)
• Increasing coverage (minimizing false negatives).