Пример #1
0
 def test_single_recognize_entities_non_text_input(self, resource_group, location, cognitiveservices_account, cognitiveservices_account_key):
     with self.assertRaises(TypeError):
         response = single_recognize_entities(
             endpoint=cognitiveservices_account,
             credential=cognitiveservices_account_key,
             input_text={"id": "1", "text": "hello world"}
         )
Пример #2
0
 def test_single_recognize_entities_non_text_input(self, resource_group, location, text_analytics_account, text_analytics_account_key):
     with self.assertRaises(TypeError):
         response = single_recognize_entities(
             endpoint=text_analytics_account,
             credential=TextAnalyticsAPIKeyCredential(text_analytics_account_key),
             input_text={"id": "1", "text": "hello world"}
         )
Пример #3
0
 def test_single_recognize_entities_empty_text_input(self, resource_group, location, cognitiveservices_account, cognitiveservices_account_key):
     with self.assertRaises(HttpResponseError):
         response = single_recognize_entities(
             endpoint=cognitiveservices_account,
             credential=cognitiveservices_account_key,
             input_text="",
         )
Пример #4
0
 def test_single_recognize_entities_none_credentials(self, resource_group, location, cognitiveservices_account, cognitiveservices_account_key):
     with self.assertRaises(ValueError):
         response = single_recognize_entities(
             endpoint=cognitiveservices_account,
             credential=None,
             input_text="Microsoft was founded by Bill Gates.",
         )
Пример #5
0
 def test_single_recognize_entities_empty_text_input(self, resource_group, location, text_analytics_account, text_analytics_account_key):
     with self.assertRaises(HttpResponseError):
         response = single_recognize_entities(
             endpoint=text_analytics_account,
             credential=TextAnalyticsAPIKeyCredential(text_analytics_account_key),
             input_text="",
         )
Пример #6
0
 def test_single_recognize_entities_bad_type_credentials(self, resource_group, location, text_analytics_account, text_analytics_account_key):
     with self.assertRaises(TypeError):
         response = single_recognize_entities(
             endpoint=text_analytics_account,
             credential=[],
             input_text="Microsoft was founded by Bill Gates.",
         )
Пример #7
0
 def test_single_recognize_entities_bad_credentials(self, resource_group, location, text_analytics_account, text_analytics_account_key):
     with self.assertRaises(ClientAuthenticationError):
         response = single_recognize_entities(
             endpoint=text_analytics_account,
             credential=TextAnalyticsAPIKeyCredential("xxxxxxxxxxxx"),
             input_text="Microsoft was founded by Bill Gates.",
         )
Пример #8
0
 def test_single_recognize_entities_bad_language_hint(self, resource_group, location, cognitiveservices_account, cognitiveservices_account_key):
     with self.assertRaises(HttpResponseError):
         response = single_recognize_entities(
             endpoint=cognitiveservices_account,
             credential=cognitiveservices_account_key,
             input_text="Microsoft was founded by Bill Gates.",
             language="English"
         )
Пример #9
0
 def test_single_recognize_entities_bad_language_hint(self, resource_group, location, text_analytics_account, text_analytics_account_key):
     with self.assertRaises(HttpResponseError):
         response = single_recognize_entities(
             endpoint=text_analytics_account,
             credential=TextAnalyticsAPIKeyCredential(text_analytics_account_key),
             input_text="Microsoft was founded by Bill Gates.",
             language="English"
         )
 def test_single_recognize_entities_bad_model_version(
         self, resource_group, location, text_analytics_account,
         text_analytics_account_key):
     with self.assertRaises(HttpResponseError):
         response = single_recognize_entities(
             endpoint=text_analytics_account,
             credential=text_analytics_account_key,
             input_text="Microsoft was founded by Bill Gates.",
             language="en",
             model_version="old")
Пример #11
0
 def test_single_recognize_entities_too_many_chars(self, resource_group, location, cognitiveservices_account, cognitiveservices_account_key):
     text = ""
     for _ in range(5121):
         text += "x"
     with self.assertRaises(HttpResponseError):
         response = single_recognize_entities(
             endpoint=cognitiveservices_account,
             credential=cognitiveservices_account_key,
             input_text=text,
         )
Пример #12
0
 def test_single_recognize_entities_too_many_chars(self, resource_group, location, text_analytics_account, text_analytics_account_key):
     text = ""
     for _ in range(5121):
         text += "x"
     with self.assertRaises(HttpResponseError):
         response = single_recognize_entities(
             endpoint=text_analytics_account,
             credential=TextAnalyticsAPIKeyCredential(text_analytics_account_key),
             input_text=text,
         )
Пример #13
0
    def test_single_recognize_entities_response_hook(self, resource_group, location, cognitiveservices_account, cognitiveservices_account_key):
        def callback(resp):
            self.assertIsNotNone(resp.statistics)
            self.assertIsNotNone(resp.model_version)

        response = single_recognize_entities(
            endpoint=cognitiveservices_account,
            credential=cognitiveservices_account_key,
            input_text="Microsoft was founded by Bill Gates.",
            show_stats=True,
            model_version="latest",
            response_hook=callback
        )
Пример #14
0
    def test_successful_single_recognize_entities(self, resource_group, location, cognitiveservices_account, cognitiveservices_account_key):
        response = single_recognize_entities(
            endpoint=cognitiveservices_account,
            credential=cognitiveservices_account_key,
            input_text="Microsoft was founded by Bill Gates.",
            language="en"
        )

        self.assertEqual(response.entities[0].text, "Microsoft")
        self.assertEqual(response.entities[1].text, "Bill Gates")
        for entity in response.entities:
            self.assertIsNotNone(entity.type)
            self.assertIsNotNone(entity.offset)
            self.assertIsNotNone(entity.length)
            self.assertIsNotNone(entity.score)
    def recognize_entities(self):
        # [START single_recognize_entities]
        from azure.ai.textanalytics import single_recognize_entities

        text = "Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975," \
               " to develop and sell BASIC interpreters for the Altair 8800."

        result = single_recognize_entities(endpoint=self.endpoint,
                                           credential=self.key,
                                           input_text=text,
                                           language="en")

        for entity in result.entities:
            print("Entity: {}".format(entity.text))
            print("Type: {}".format(entity.type))
            print("Confidence Score: {0:.3f}\n".format(entity.score))