N-grams and N-logs with Ruby

N-grams are useful, in spell-checking, for example. I’ve been working on a project where I need to extract the word-level equivalent of n-grams from phrases. Lacking a better name, I call them n-logs. As one might expect, Ruby makes this easy. Here is a pipe-friendly script:

Modifying this script to create n-grams instead is trivial.

Advertisement

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.