40 likes | 130 Views
Parsing a Name. Homework 1. Cases to Consider. Rest Last Last, Rest Rest Last, Suffix Last, Rest, Suffix Others??? Question : how do we tell the computer to recognize and distinguish each case from the others?. Distinguishing the Four Cases. Case. Distinguishing Characteristic.
E N D
Parsing a Name Homework 1
Cases to Consider • Rest Last • Last, Rest • Rest Last, Suffix • Last, Rest, Suffix • Others??? • Question: how do we tell the computer to recognize and distinguish each case from the others?
Distinguishing the Four Cases Case Distinguishing Characteristic No Comma present First Comma before First Space First Space before First Comma First Comma ≠ Last Comma • Rest Last • Last, Rest • Rest Last, Suffix • Last, Rest, Suffix • Note that one must remove extraneous white space before the strategy above works correctly • Remove leading and trailing whitespace • Replace multiple consecutive whitespace characters with single space • Remove any whitespace immediately before a comma
Distinguishing the Four Cases Case Distinguishing Characteristic No Comma present First Comma before First Space First Space before First Comma First Comma ≠ Last Comma • Rest Last • Last, Rest • Rest Last, Suffix • Last, Rest, Suffix After handling the suffix in the last two cases and then removing it along with its preceding comma and space, we are left with the first two cases