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
Specs
average_word_length(frequency_list()) :: float()
Counts the average word length in a frequency list.
Arguments
frequency_list
is a list of frequencies returned fromText.Word.word_count/2
## Returns
- An float representing the average word length
Examples
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 fromText.Word.word_count/2
directions
is either:asc
or:desc
. The default is:desc
.
## Returns
- The
frequency_list
sorted in the direction specified
Examples
Specs
total_word_count(frequency_list()) :: pos_integer()
Counts the total number of words in a frequency list.
Arguments
frequency_list
is a list of frequencies returned fromText.Word.word_count/2
## Returns
- An integer number of words
Examples
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 aString.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.