August 2014
Beginner to intermediate
304 pages
7h 10m
English
The transform functions defined in the previous recipes can be chained together to normalize chunks. The resulting chunks are often shorter with no loss of meaning.
In transforms.py is the function transform_chunk(). It takes a single chunk and an optional list of transform functions. It calls each transform function on the chunk, one at a time, and returns the final chunk:
def transform_chunk(chunk, chain=[filter_insignificant, swap_verb_phrase, swap_infinitive_phrase, singularize_plural_noun], trace=0):
for f in chain:
chunk = f(chunk)
if trace:
print f.__name__, ':', chunk
return chunkUsing it on the phrase the book of recipes is delicious, we get delicious recipe book:
>>> from transforms import transform_chunk ...
Read now
Unlock full access