KeywordLengthBands (keyword_length_bands v1.0.0)

Copy Markdown View Source

Split a keyword list into head, body and long-tail bands by word count.

Input is a CSV with a keyword column and an optional volume column (a non-negative whole number). Words are the whitespace-separated tokens of the trimmed keyword.

  • head: fewer than body_from words (default: 1 word)
  • body: body_from or more words but fewer than long_from (default: 2 to 3 words)
  • long tail: long_from or more words (default: 4 or more)

body_from and long_from are parameters set by you, not rules. They must satisfy 2 <= body_from < long_from.

Keywords that repeat (ignoring case and extra spaces) are counted once; the first row wins, including its volume. Shares and averages are rounded half up to one decimal.

Summary

Functions

Band name for a word count.

Check the band limits: 2 <= body_from < long_from.

Parse the CSV text. Duplicate keywords are dropped (first row kept) and listed.

Divide num / den * mult exactly (integers only) and format with decimals places, rounding half up. Returns "n/a" when den is zero.

Printable report: totals, duplicates, band table and top keywords.

Per-band summary for parsed keywords. Returns a list of three maps (head, body, long tail) with the keys band, keywords, words_total, volume and top (up to 3 keywords by volume, ties by keyword).

Types

keyword_row()

@type keyword_row() :: %{
  keyword: String.t(),
  words: pos_integer(),
  volume: non_neg_integer() | nil
}

parsed()

@type parsed() :: %{
  keywords: [keyword_row()],
  duplicates: [String.t()],
  has_volume: boolean()
}

Functions

band(words, body_from \\ 2, long_from \\ 4)

@spec band(pos_integer(), pos_integer(), pos_integer()) :: :head | :body | :long_tail

Band name for a word count.

check_limits(body_from, long_from)

@spec check_limits(integer(), integer()) :: :ok | {:error, String.t()}

Check the band limits: 2 <= body_from < long_from.

parse(text)

@spec parse(String.t()) :: {:ok, parsed()} | {:error, String.t()}

Parse the CSV text. Duplicate keywords are dropped (first row kept) and listed.

ratio(num, den, mult, decimals)

@spec ratio(integer(), integer(), integer(), non_neg_integer()) :: String.t()

Divide num / den * mult exactly (integers only) and format with decimals places, rounding half up. Returns "n/a" when den is zero.

render(parsed, body_from \\ 2, long_from \\ 4)

@spec render(parsed(), pos_integer(), pos_integer()) :: String.t()

Printable report: totals, duplicates, band table and top keywords.

summarize(map, body_from \\ 2, long_from \\ 4)

@spec summarize(parsed(), pos_integer(), pos_integer()) :: [map()]

Per-band summary for parsed keywords. Returns a list of three maps (head, body, long tail) with the keys band, keywords, words_total, volume and top (up to 3 keywords by volume, ties by keyword).