コード例 #1
0
    def test_organizations_v1(self):
        test_data = "A year ago, the New York Times published confidential comments about ISIS' ideology by Major General Michael K. Nagata, then U.S. Special Operations commander in the Middle East."
        response = organizations(test_data, version=1)
        self.assertTrue(isinstance(response, list))
        sorted_response = sorted(response, key=lambda x: x['confidence'], reverse=True)
        self.assertTrue('ISIS' in sorted_response[0]['text'])

        test_data = [test_data] * 2
        response = organizations(test_data, version=1)
        self.assertTrue(isinstance(response, list))
        sorted_response = [sorted(arr, key=lambda x: x['confidence'], reverse=True) for arr in response]
        self.assertTrue('ISIS' in sorted_response[0][0]['text'])
コード例 #2
0
    def test_organizations(self):
        test_data = "A year ago, the New York Times published confidential comments about ISIS' ideology by Major General Michael K. Nagata, then U.S. Special Operations commander in the Middle East."
        response = organizations(test_data)
        self.assertTrue(isinstance(response, list))
        sorted_response = sorted(response, key=lambda x: x['confidence'], reverse=True)
        self.assertTrue('ISIS' in sorted_response[0]['text'])

        test_data = [test_data] * 2
        response = organizations(test_data)
        self.assertTrue(isinstance(response, list))
        sorted_response = [sorted(arr, key=lambda x: x['confidence'], reverse=True) for arr in response]
        self.assertTrue('ISIS' in sorted_response[0][0]['text'])
コード例 #3
0
    def test_organizations_v2(self):
        test_data = "A year ago, the New York Times published confidential comments about ISIS ideology by Major General Michael K. Nagata, then U.S. Special Operations commander in the Middle East."
        response = organizations(test_data)
        self.assertTrue(isinstance(response, list))
        sorted_response = sorted(response, key=lambda x: x["confidence"], reverse=True)
        self.assertTrue(
            "New York Times" in [result["text"] for result in sorted_response]
        )

        test_data = [test_data] * 2
        response = organizations(test_data)
        self.assertTrue(isinstance(response, list))
        sorted_response = [
            sorted(arr, key=lambda x: x["confidence"], reverse=True) for arr in response
        ]
        self.assertTrue(
            "New York Times" in [result["text"] for result in sorted_response[0]]
        )
コード例 #4
0
#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))