Пример #1
0
def gather(webpage):
    kales = Kales(API_KEY)
    data = kales.analyze(webpage['content'].encode('utf-8'))
    terms = list()    
    entity_tuples= [(entity['relevance'], entity['name'])for entity in data["entities"]]        
    for entity in sorted(entity_tuples, key=lambda entity: entity[0], reverse=True)[:num_of_entities]: #sort by relevance
        terms.extend(get_terms(entity[1]))            
    return {'terms': {'$in': terms}}
Пример #2
0
class KalesTest(TestCase):
    def setUp(self):
        self.calais = Kales("123456789")

    @patch.object(Kales, '_request')
    def test_analyze(self, mock):
        mock.return_value = MockResponse()
        data = self.calais.analyze("Barack Obama")
        self.assertTrue("entities" in data)
        self.assertEqual(len(data["entities"]), 1)

    def test_analyze_empty(self):
        data = self.calais.analyze(" ")
        self.assertEqual(data, None)
Пример #3
0
class KalesTest(TestCase):
    def setUp(self):
        self.calais = Kales("123456789")

    @patch.object(Kales, '_request')
    def test_analyze(self, mock):
        mock.return_value = MockResponse()
        data = self.calais.analyze("Barack Obama")
        self.assertTrue("entities" in data)
        self.assertEqual(len(data["entities"]), 1)

    def test_analyze_empty(self):
        data = self.calais.analyze(" ")
        self.assertEqual(data, None)
Пример #4
0
 def setUp(self):
     self.calais = Kales("123456789")
Пример #5
0
 def setUp(self):
     self.calais = Kales("123456789")