taxon_search v0.0.1 TaxonSearch.StringUtils

Provides functions to help with tokenizing strings, generating regexes from string tokens, and matching phrases against sets of string tokens.

A token is defined as a series of alphanumeric characters separated from other tokens by whitespace or punctuation.

Summary

Functions

Returns true if str matches against all of the regexes

Returns a collection of the tokens in str

Returns a case-insenstive regular expression generated from str

Returns a collection of case-insensitive regexes, one for each token in str

Functions

all_regexes_match?(regexes, str)

Returns true if str matches against all of the regexes.

Parameters

  • regexes: Collection of regular expressions
  • str: String to match against the regexes

Examples

iex> TaxonSearch.StringUtils.all_regexes_match?(["Hello", "world"], "Hello, world")
true

iex> TaxonSearch.StringUtils.all_regexes_match?(["Goodbye", "world"], "Hello, world")
false
get_string_tokens(str)

Returns a collection of the tokens in str.

Parameters

  • str: String to split into tokens

Examples

iex> TaxonSearch.StringUtils.get_string_tokens("Red-headed monkey  ")
["Red", "headed", "monkey"]
get_token_regex(str)

Returns a case-insenstive regular expression generated from str.

Parameters

  • str: String to convert into a case-insensitive regular expression

Examples

iex> TaxonSearch.StringUtils.get_token_regex("Red")
~r/Red/i
get_token_regexes(str)

Returns a collection of case-insensitive regexes, one for each token in str.

Parameters

  • str: String to split into token regexes

Examples

iex> TaxonSearch.StringUtils.get_token_regexes("Red-headed monkey  ")
[~r/Red/i, ~r/headed/i, ~r/monkey/i]