(examples)
return index
Create an inverted index based on words in title and shortdesc.  Keys are
    lower cased words.  Values are dictionaries with example index keys and
    count values.
Create an inverted index based on words in title and shortdesc.  Keys are
    lower cased words.  Values are dictionaries with example index keys and
    count values.
Create an inverted index based on words in title and shortdesc . Keys are lower cased words . Values are dictionaries with example index keys and count values .
def wordIndex(examples):
    """
    Create an inverted index based on words in title and shortdesc.  Keys are
    lower cased words.  Values are dictionaries with example index keys and
    count values.
    """
    index = {}
    unword = re.compile("\\W+")
    keys = ["shortdesc", "title", "tags"]
    for i in range(len(examples)):
        for key in keys:
            text = examples[i][key]
            if text:
                words = unword.split(text)
                for word in words:
                    if word:
                        word = word.lower()
                        if index.has_key(word):
                            if index[word].has_key(i):
                                index[word][i] += 1
                            else:
                                index[word][i] = 1
                        else:
                            index[word] = {i: 1}
    return index
def wordIndex ( examples ) : index = { } unword = re . compile ( "\\W+" ) keys = [ "shortdesc" , "title" , "tags" ] for i in range ( len ( examples ) ) : for key in keys : text = examples [ i ] [ key ] if text : words = unword . split ( text ) for word in words : if word : word = word . lower ( ) if index . has_key ( word ) : if index [ word ] . has_key ( i ) : index [ word ] [ i ] += 1 else : index [ word ] [ i ] = 1 else : index [ word ] = { i : 1 } return index