def get_bigram_scores(text_words, min_bgfreq=2.0):
    """
    compute scores for identifying bigrams in a collection of texts
    compute unigram and bigram frequencies (of words) and give a score for every bigram.
    depending on this score (e.g. if higher than a threshold), bigram phrases can be identified
    in the raw texts before splitting them into words
    --> once the lists of words in the text_words are replaced by appropriate bigrams, the whole thing could be repeated
        to find trigrams, etc.
    Input:
        - text_words: a list (or generator) of lists of (preprocessed) words
        - min_bgfreq: how often a bigram has to have to occur in the corpus to be recognized (if both words occur just once
                      and that in combination, it still doesn't mean it's a true phrase because we have too little observations of the words
    Returns:
        - bigram_scores: a dict with bigrams ("word1 word2") and their score
    """
    unigram_freq = {}
    bigram_freq = {}
    for wordlist in text_words:
        for i, word in enumerate(wordlist):
            try:
                unigram_freq[word] += 1.0
            except KeyError:
                unigram_freq[word] = 1.0
            if i:
                try:
                    bigram_freq['%s %s' % (wordlist[i - 1], word)] += 1.0
                except KeyError:
                    bigram_freq['%s %s' % (wordlist[i - 1], word)] = 1.0
    bigram_scores = {}
    for bigram in bigram_freq:
        if max(0.0, bigram_freq[bigram] - min_bgfreq):
            bigram_scores[bigram] = bigram_freq[bigram] / max(unigram_freq[
                bigram.split()[0]], unigram_freq[bigram.split()[1]])
    return bigram_scores
