def generate_keywords(text): """generates a list of keywords based on some text""" rake = Rake() keywords = rake.run(text) ret = [] for (tag, strength) in keywords: if len(tag.split(' ')) < 3 and strength >= 3: ret.append(tag) return ret
def generate_keywords(text): """generates a list of 10 keywords based on some text""" rake = Rake() keywords = rake.run(text) ret = [] for (tag, strength) in keywords: if len(tag.split(' ')) < 3 <= strength: ret.append(tag) if len(ret) > 10: ret = ret[:10] return ret