@@ -0,0 +1,615 @@
+#!/usr/bin/python%0A# -*- coding: latin-1 -*-%0A%0Aimport math%0Afrom operator import itemgetter%0A%0Adef tfidf(word, doc, docList):%0A    tf = doc.split(None).count(word) / float(len(doc.split(None)))%0A%0A    docs_in_word = 0%0A%0A    for doc in docList:%0A        if doc.split(None).count(word) %3E 0:%0A            docs_in_word +=1%0A%0A    idf = math.log(len(docList)/ docs_in_word)%0A%0A    return tf * idf%0A%0Adef top_keywords(doc, docList, n=5):%0A    d = %7B%7D%0A    for word in set(doc.split(None)):%0A        d%5Bword%5D = tfidf(word, doc, docList)%0A%0A    sorted_d = sorted(d.items(), key=itemgetter(1), reverse=True)%0A    return %5Bw%5B0%5D for w in sorted_d%5B:n%5D%5D%0A

Create tf-idf.py