from keyword_list import keyword_list
import re

keyword_re = {}

for k in keyword_list:
    keyword_re[k] = re.compile(r'(?:\A|[\s\.\-,;])' + k + r'(?:[\s\.\-,;]|\Z)', re.UNICODE|re.IGNORECASE)

def keywords_from_content(content):
    result = []
    last_match = 0
    max_index = len(keyword_list)

    for i in range(0, 10):
        for j in xrange(last_match, max_index):
            k = keyword_list[j]
            try:
                if keyword_re[k].search(content) and not k in result:
                    result.append(k)
                    last_match = j + 1
                    break
            except Exception, error:
                print '%s : %s' %(k, error)
    return result
