View Source Needlepoint.Util (Needlepoint v0.1.0)
Link to this section Summary
Functions
Check if a string is downcased.
Check if a string is uppercased.
Return the ngrams generated from a sequence of items, as a stream.
Returns a padded sequence of items before ngram extraction.
Take the product of 2 enumerables, a simple version of Python's itertools.product
Link to this section Functions
Check if a string is downcased.
examples
Examples
iex> Needlepoint.Util.is_downcase?("foo")
true
iex> Needlepoint.Util.is_downcase?("FOo")
false
iex> Needlepoint.Util.is_downcase?("FOO")
false
iex> Needlepoint.Util.is_downcase?(":)")
true
Check if a string is uppercased.
examples
Examples
iex> Needlepoint.Util.is_upcase?("foo")
false
iex> Needlepoint.Util.is_upcase?("FOo")
false
iex> Needlepoint.Util.is_upcase?("FOO")
true
iex> Needlepoint.Util.is_upcase?(":D")
true
Return the ngrams generated from a sequence of items, as a stream.
examples
Examples
iex> Needlepoint.Util.ngrams([1,2,3,4,5], 3) |> Enum.to_list()
[[1, 2, 3], [2, 3, 4], [3, 4, 5]]
iex> Needlepoint.Util.ngrams([1,2,3,4,5], 2, pad_right: true) |> Enum.to_list()
[[1, 2], [2, 3], [3, 4], [4, 5], [5, nil]]
iex> Needlepoint.Util.ngrams([1,2,3,4,5], 2, pad_right: true, right_pad_symbol: "</s>") |> Enum.to_list()
[[1, 2], [2, 3], [3, 4], [4, 5], [5, "</s>"]]
iex> Needlepoint.Util.ngrams([1,2,3,4,5], 2, pad_left: true, left_pad_symbol: "<s>") |> Enum.to_list()
[["<s>", 1], [1, 2], [2, 3], [3, 4], [4, 5]]
iex> Needlepoint.Util.ngrams([1,2,3,4,5], 2, pad_left: true, pad_right: true, left_pad_symbol: "<s>", right_pad_symbol: "</s>") |> Enum.to_list()
[["<s>", 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, "</s>"]]
Returns a padded sequence of items before ngram extraction.
examples
Examples
iex> alias Needlepoint.Util
Needlepoint.Util
iex> Util.pad_sequence([1,2,3,4,5], 2)
[1, 2, 3, 4, 5]
iex> Util.pad_sequence([2,3,4,5,6], 3, pad_left: true, pad_right: true)
[nil, nil, 2, 3, 4, 5, 6, nil, nil]
iex> Util.pad_sequence([3,4,5,6,7], 2, pad_left: true, pad_right: true, left_pad_symbol: "<s>", right_pad_symbol: "</s>")
["<s>", 3, 4, 5, 6, 7, "</s>"]
iex> Util.pad_sequence([4,5,6,7,8], 2, pad_left: true, left_pad_symbol: "<s>")
["<s>", 4, 5, 6, 7, 8]
iex> Util.pad_sequence([5,6,7,8,9], 2, pad_right: true, right_pad_symbol: "</s>")
[5, 6, 7, 8, 9, "</s>"]
Take the product of 2 enumerables, a simple version of Python's itertools.product
examples
Examples
iex> Needlepoint.Util.product([],[])
[]
iex> Needlepoint.Util.product(["a","b"], ["x","y","z"])
[["a", "x"], ["a", "y"], ["a", "z"], ["b", "x"], ["b", "y"], ["b", "z"]]