August 2014
Beginner to intermediate
304 pages
7h 10m
English
As we saw in the previous recipe, the transformation process can result in phrases such as recipes book. This is a NNS followed by a NN, when a more proper version of the phrase would be recipe book, which is a NN followed by another NN. We can do another transform to correct these improper plural nouns.
The transforms.py script defines a function called singularize_plural_noun() which will depluralize a plural noun (tagged with NNS) that is followed by another noun:
def singularize_plural_noun(chunk): nnsidx = first_chunk_index(chunk, tag_equals('NNS')) if nnsidx is not None and nnsidx+1 < len(chunk) and chunk[nnsidx+1][1][:2] == 'NN': noun, nnstag = chunk[nnsidx] chunk[nnsidx] = (noun.rstrip('s'), nnstag.rstrip('S')) ...Read now
Unlock full access