Keywords (keywords v1.2.0) View Source

Documentation for KeywordParser.

Link to this section Summary

Functions

Removes pattern by name.

Generates new keyword-pattern for parsing strings from a list of keywords.

Parses tickers from string

Checks if pattern exists.

Updates a keyword-pattern.

Link to this section Functions

Removes pattern by name.

Examples

iex> Keywords.kill_pattern(:stocks)
{:ok, :stocks}
iex> Keywords.kill_pattern(:stocks)
{:error, :not_found}
Link to this function

new_pattern(name, keyword_list, opts \\ [])

View Source

Generates new keyword-pattern for parsing strings from a list of keywords.

opts -> case_sensitive: true/false -> substrings: true/false defaults -> case_sensitive: false, substrings: false

Examples

iex> Keywords.new_pattern(:stocks, ["TSLA", "XOM", "AMZN"])
{:ok, :stocks}
iex> Keywords.new_pattern(:stocks, ["TSLA", "XOM", "AMZN"])
{:error, :already_started}
Link to this function

parse(string, pattern_names, opts \\ [])

View Source

Parses tickers from string

opts -> counts: true/false (include total occurrences of each keyword) -> aggregate: true/false (group results by pattern name) defaults -> counts: false, aggregate: true

Examples

iex> Keywords.parse(" XOM AAPL $TSLA buy now, ++ PLTR and $AMZN", :stocks)
[XOM, AAPL, TSLA, PLTR, AMZN]

iex> Keywords.parse(" XOM AAPL $TSLA buy now, ++ PLTR and $AMZN", :stocks_2)
["AAPL", "PLTR"]

iex> Keywords.parse(" XOM AAPL $TSLA buy now, ++ PLTR and $AMZN", [:stocks, :stocks_2])
["AAPL", "PLTR", XOM, TSLA, PLTR, AMZN]

iex> Keywords.parse(" XOM AAPL AMZN $TSLA buy now, ++ PLTR and $AMZN", :all)
["XOM", "AMZN", "TSLA", "AAPL", "PLTR"]

iex> Keywords.parse(" XOM AAPL AMZN $TSLA buy now, ++ PLTR and $AMZN", :stocks, [counts: true])
[{"AMZN", 2}, {"TSLA", 1}, {"XOM", 1}]

iex> Keywords.parse(" XOM AAPL AMZN $TSLA buy now, ++ PLTR and $AMZN", [:stocks, :stocks_2], [counts: true])
[{"AAPL", 1}, {"AMZN", 2}, {"PLTR", 1}, {"TSLA", 1}, {"XOM", 1}]

iex> Keywords.parse(" XOM AAPL AMZN $TSLA buy now, ++ PLTR and $AMZN", [:stocks, :stocks_2], [counts: true, aggregate: false])
[stocks: [{"AMZN", 2}, {"TSLA", 1}, {"XOM", 1}], stocks_2: [{"AAPL", 1}, {"PLTR", 1}]]

iex> Keywords.parse(" XOM AAPL AMZN $TSLA buy now, ++ PLTR and $AMZN", [:stocks, :stocks_2], [aggregate: false])
[stocks: ["XOM", "AMZN", "TSLA"], stocks_2: ["AAPL", "PLTR"]]

iex> Keywords.parse("a|n[xwn;qw%dl$qm*w", :stocks)
[]

iex> Keywords.parse(nil, :stocks)
[]

Checks if pattern exists.

Examples

iex> Keywords.pattern_exists?(:stocks)
true
iex> Keywords.pattern_exists?(:stonks)
false
Link to this function

update_pattern(name, keyword_list)

View Source

Updates a keyword-pattern.

Examples

iex> Keywords.update_pattern(:stocks, ["TSLA", "XOM", "AMZN"])
{:ok, :stocks}
iex> Keywords.update_pattern(:stonks, ["TSLA", "XOM", "AMZN"])
{:error, :pattern_not_found}