import re
from typing import Counter


def get_term_frequencies(series, min_str_len=1, ngram=1):
    """
    Get number of occurence of each term in the given pandas series

    Parameters
    ----------
    series: pandas series
        Series to extract the term frequencies from
    min_str_len: int, optional (default value=1)
        Minimum string length for a word
    ngram: int, optional (default value=1)
        Number of words to get frequency from.

    Return
    -------
    Python dict ({word:frequency})
    """
    text = " ".join(series.values.astype(str))
    regex = re.compile(r"\w+{}".format(r" \w+"*(ngram-1)))
    words = re.findall(regex, text.lower())
    words = [w for w in words if len(w) >= min_str_len]
    word_dict = Counter(words)

    return dict(word_dict)