Example #1
0
def extract_key_words():
    extractor = request.args.get('extractor', 'tfidf')
    text = request.args.get('text', '')
    num = int(request.args.get('num', 5))
    pos = request.args.get('pos', None)

    results = KeywordExtractor.get_instance(extractor).extract(text, num, pos)
    return NLPResponse(results, 200)
Example #2
0
def init_kw():
    KeywordExtractor.init(['tfidf', 'textrank'])
Example #3
0
 def test_tfidf(self):
     test_text = 'RAKE算法用来做关键词(keyword)的提取,实际上提取的是关键的短语(phrase)'
     res = KeywordExtractor.get_instance('tfidf').extract(test_text)
     print(res)
Example #4
0
 def setUp(self):
     KeywordExtractor.init(['tfidf', 'textrank'])
Example #5
0
 def test_not_implemented(self):
     with self.assertRaises(NotImplementedError) as cm:
         KeywordExtractor.init(['tfidf', 'textrank', 'lda'])
     self.assertEqual(str(cm.exception), 'Extractor not supported!')
Example #6
0
 def test_use_pos(self):
     test_text = 'RAKE算法用来做关键词(keyword)的提取,实际上提取的是关键的短语(phrase)'
     pos = ['n', 'v']
     res = KeywordExtractor.get_instance('textrank').extract(test_text,
                                                             pos=pos)
     print(res)