def test_people(self): test_data = 'Barack Obama is scheduled to give a talk next Saturday at the White House.' response = people(test_data) self.assertTrue(isinstance(response, list)) sorted_response = sorted(response, key=lambda x: x['confidence'], reverse=True) self.assertTrue(sorted_response[0]['text'] == 'Barack Obama') test_data = [test_data] * 2 response = people(test_data) self.assertTrue(isinstance(response, list)) sorted_response = [sorted(arr, key=lambda x: x['confidence'], reverse=True) for arr in response] self.assertEqual(len(sorted_response), 2) self.assertTrue(sorted_response[0][0]['text'] == 'Barack Obama')
def test_people(self): test_data = 'Barack Obama is scheduled to give a talk next Saturday at the White House.' response = people(test_data) self.assertTrue(isinstance(response, list)) sorted_response = sorted(response, key=lambda x: x['confidence'], reverse=True) self.assertTrue(sorted_response[0]['text'] == 'Barack Obama') test_data = [test_data] * 2 response = people(test_data) self.assertTrue(isinstance(response, list)) sorted_response = [ sorted(arr, key=lambda x: x['confidence'], reverse=True) for arr in response ] self.assertEqual(len(sorted_response), 2) self.assertTrue(sorted_response[0][0]['text'] == 'Barack Obama')
def keywords(blob): things = [] indicoio.config.api_key = 'ab83001ca5c484aa92fc18a5b2d6585c' people = indicoio.people(blob) for person in people: if person['confidence'] > 0.5: things.append(person['text']) places = indicoio.places(blob) for place in places: if place['confidence'] > 0.5: things.append(place['text']) print(things) blob = parse_stop_words(blob) tfdic = tf(blob) things.append(list(tfidf(tfdic, idf(tfdic, blob)).keys())) things = list(set(source_list)) return things
#with open('textfile.txt', 'r') as myfile: # data = myfile.read().replace('\n', '') #print(data) import os import indicoio # reads from the file which contains the audio to speech content __location__ = os.path.realpath( os.path.join(os.getcwd(), os.path.dirname(__file__))) file_contents = open(os.path.join(__location__, "textfile.txt")) text = file_contents.read() # next, feed it into the ML API indicoio.config.api_key = 'd08fbca96c4341957f0a8a0b21d08b5d' print("Political Allegiance: ") print(indicoio.political(text)) print("\n") print("Key Words: ") print(indicoio.keywords(text, version=2)) print("\n") print("Important Persons: ") print(indicoio.people(text)) print("\n") print("Significant Locations: ") print(indicoio.places(text)) print("\n") print("Relevant Organizations: ") print(indicoio.organizations(text))