Storing an ordered dictionary in Redis
An ordered dictionary is like a normal dict
, but the keys are ordered by an ordering function. In the case of Redis, it supports ordered dictionaries whose keys are strings and whose values are floating point scores. This structure can come in handy in cases where we need to calculate the information gain (covered in the Calculating high information words recipe in Chapter 7, Text Classification), and when you want to store all the words and scores for later use.
Getting ready
Again, you'll need Redis
and redis-py
installed with an instance of redis-server
running, as explained in the earlier recipe, Storing a frequency distribution in Redis.
How to do it...
The RedisOrderedDict
class in rediscollections.py
Get Natural Language Processing: Python and NLTK now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.