Text.Word (Text v0.2.0) View Source

Implements word counting for lists, streams and flows.

Link to this section Summary

Types

A list of words and their frequencies in a text

A function to split text

Enumerable types for word counting

Functions

Counts the average word length in a frequency list.

Sorts the words in words in a frequency list.

Counts the total number of words in a frequency list.

Counts the number of words in a string, File.Stream, or Flow.

Link to this section Types

Specs

frequency_list() :: [{String.t(), pos_integer()}, ...]

A list of words and their frequencies in a text

Specs

splitter() :: function()

A function to split text

Specs

text() :: Flow.t() | File.Stream.t() | String.t() | [String.t(), ...]

Enumerable types for word counting

Link to this section Functions

Link to this function

average_word_length(frequency_list)

View Source

Specs

average_word_length(frequency_list()) :: float()

Counts the average word length in a frequency list.

Arguments

## Returns

  • An float representing the average word length

Examples

Link to this function

sort(frequency_list, direction \\ :desc)

View Source

Specs

sort(frequency_list(), :asc | :desc) :: frequency_list()

Sorts the words in words in a frequency list.

Arguments

  • frequency_list is a list of frequencies returned from Text.Word.word_count/2

  • directions is either :asc or :desc. The default is :desc.

## Returns

  • The frequency_list sorted in the direction specified

Examples

Link to this function

total_word_count(frequency_list)

View Source

Specs

total_word_count(frequency_list()) :: pos_integer()

Counts the total number of words in a frequency list.

Arguments

## Returns

  • An integer number of words

Examples

Link to this function

word_count(text, splitter \\ &String.split/1)

View Source

Specs

word_count(Flow.t() | File.Stream.t() | String.t() | [String.t()], splitter()) ::
  frequency_list()

Counts the number of words in a string, File.Stream, or Flow.

Arguments

  • text is either a String.t, Flow.t, File.Stream.t or a list of strings.

  • splitter is an arity-1 function that splits the text stream. The default is &String.split/1.

## Returns

  • A list of 2-tuples of the form {word, count} referred to as a frequency list.

Examples