Converts between plain text and inverted index format.
An inverted index maps each unique word to the list of positions where it appears in the original text:
%{"Despite" => [0], "growing" => [1], "interest" => [2], "in" => [3, 57]}This format is used by OpenAlex to represent scholarly abstracts. This module converts between that representation and plain text strings.
Examples
iex> index = %{"Hello" => [0], "world" => [1]}
iex> Amplified.InvertedIndex.to_text(index)
"Hello world"
iex> Amplified.InvertedIndex.from_text("Hello world")
%{"Hello" => [0], "world" => [1]}
Summary
Functions
Converts plain text to an inverted index map.
Converts an inverted index map to plain text.
Functions
Converts plain text to an inverted index map.
Returns nil if the input is nil.
Examples
iex> Amplified.InvertedIndex.from_text("Hello world")
%{"Hello" => [0], "world" => [1]}
iex> Amplified.InvertedIndex.from_text("the cat chased the dog")
%{"cat" => [1], "chased" => [2], "dog" => [4], "the" => [0, 3]}
iex> Amplified.InvertedIndex.from_text(nil)
nil
Converts an inverted index map to plain text.
Returns nil if the input is nil.
Examples
iex> Amplified.InvertedIndex.to_text(%{"Hello" => [0], "world" => [1]})
"Hello world"
iex> Amplified.InvertedIndex.to_text(%{"the" => [0, 3], "cat" => [1], "chased" => [2], "dog" => [4]})
"the cat chased the dog"
iex> Amplified.InvertedIndex.to_text(nil)
nil