Exemplo n.º 1
0
def prioritize(words):
    counters = {}
    for word in words:
        dict_match = DictionaryWord.query(
            DictionaryWord.word == word).fetch()
        if dict_match:
            mentions = Mention.query(Mention.word == dict_match[0].key).fetch()
            for mention in mentions:
                if mention.quote in counters:
                    counters[mention.quote] += 1
                else:
                    counters.update(dict([(mention.quote, 1)]))
    ordered = sorted(counters.items(), key=lambda x: x[1]).copy()
    logging.debug(" ====================================== ")
    logging.debug(ordered)
    logging.debug(" ====================================== ")
    return ordered
Exemplo n.º 2
0
def parser(word):
    """ individual word into array of dicts
    of quotes """
    dict_match = DictionaryWord.query(
            DictionaryWord.word == word).fetch()
    if dict_match:
        mentions = Mention.query(Mention.word == dict_match[0].key).fetch()
        yeild_text = []
        for mention in mentions:
            quote = mention.quote.get()
            quote_dict = {'line':quote.line,
                        'context': quote.context,
                        'movie':quote.movie
                        }
            yeild_text.append(quote_dict)
        return yeild_text
    else:
        return []