def extract_key_phrases(self):
        # [START batch_extract_key_phrases]
        from azure.ai.textanalytics import TextAnalyticsClient, TextAnalyticsApiKeyCredential
        text_analytics_client = TextAnalyticsClient(
            endpoint=self.endpoint,
            credential=TextAnalyticsApiKeyCredential(self.key))
        documents = [
            "Redmond is a city in King County, Washington, United States, located 15 miles east of Seattle.",
            "I need to take my cat to the veterinarian.",
            "I will travel to South America in the summer.",
        ]

        result = text_analytics_client.extract_key_phrases(documents)
        for doc in result:
            if not doc.is_error:
                print(doc.key_phrases)
            if doc.is_error:
                print(doc.id, doc.error)
Пример #2
0
 def test_mixing_inputs(self, resource_group, location,
                        text_analytics_account, text_analytics_account_key):
     text_analytics = TextAnalyticsClient(
         text_analytics_account,
         TextAnalyticsApiKeyCredential(text_analytics_account_key))
     docs = [
         {
             "id": "1",
             "text": "Microsoft was founded by Bill Gates and Paul Allen."
         },
         TextDocumentInput(
             id="2",
             text=
             "I did not like the hotel we stayed at. It was too expensive."
         ), u"You cannot mix string input with the above inputs"
     ]
     with self.assertRaises(TypeError):
         response = text_analytics.extract_key_phrases(docs)
Пример #3
0
    async def test_passing_only_string(self, resource_group, location, text_analytics_account, text_analytics_account_key):
        text_analytics = TextAnalyticsClient(text_analytics_account, TextAnalyticsApiKeyCredential(text_analytics_account_key))

        docs = [
            u"My SSN is 555-55-5555.",
            u"Your ABA number - 111000025 - is the first 9 digits in the lower left hand corner of your personal check.",
            u"Is 998.214.865-68 your Brazilian CPF number?",
            u""
        ]

        response = await text_analytics.recognize_pii_entities(docs, show_stats=True)
        self.assertEqual(response[0].entities[0].text, "555-55-5555")
        self.assertEqual(response[0].entities[0].category, "U.S. Social Security Number (SSN)")
        self.assertEqual(response[1].entities[0].text, "111000025")
        # self.assertEqual(response[1].entities[0].category, "ABA Routing Number")  # Service is currently returning PhoneNumber here
        self.assertEqual(response[2].entities[0].text, "998.214.865-68")
        self.assertEqual(response[2].entities[0].category, "Brazil CPF Number")
        self.assertTrue(response[3].is_error)
Пример #4
0
    async def test_all_successful_passing_text_document_input(self, resource_group, location, text_analytics_account, text_analytics_account_key):
        text_analytics = TextAnalyticsClient(text_analytics_account, TextAnalyticsApiKeyCredential(text_analytics_account_key))

        docs = [
            TextDocumentInput(id="1", text="Microsoft was founded by Bill Gates and Paul Allen"),
            TextDocumentInput(id="2", text="Microsoft fue fundado por Bill Gates y Paul Allen")
        ]

        response = await text_analytics.recognize_linked_entities(docs)
        for doc in response:
            self.assertEqual(len(doc.entities), 3)
            for entity in doc.entities:
                self.assertIsNotNone(entity.name)
                self.assertIsNotNone(entity.matches)
                self.assertIsNotNone(entity.language)
                self.assertIsNotNone(entity.data_source_entity_id)
                self.assertIsNotNone(entity.url)
                self.assertIsNotNone(entity.data_source)
Пример #5
0
    async def test_all_successful_passing_dict(self, resource_group, location, text_analytics_account, text_analytics_account_key):
        text_analytics = TextAnalyticsClient(text_analytics_account, TextAnalyticsApiKeyCredential(text_analytics_account_key))

        docs = [{"id": "1", "language": "en", "text": "Microsoft was founded by Bill Gates and Paul Allen"},
                {"id": "2", "language": "es", "text": "Microsoft fue fundado por Bill Gates y Paul Allen"}]

        response = await text_analytics.recognize_linked_entities(docs, show_stats=True)
        for doc in response:
            self.assertEqual(len(doc.entities), 3)
            self.assertIsNotNone(doc.id)
            self.assertIsNotNone(doc.statistics)
            for entity in doc.entities:
                self.assertIsNotNone(entity.name)
                self.assertIsNotNone(entity.matches)
                self.assertIsNotNone(entity.language)
                self.assertIsNotNone(entity.data_source_entity_id)
                self.assertIsNotNone(entity.url)
                self.assertIsNotNone(entity.data_source)
Пример #6
0
    def test_document_attribute_error_nonexistent_attribute(
            self, resource_group, location, text_analytics_account,
            text_analytics_account_key):
        text_analytics = TextAnalyticsClient(
            text_analytics_account,
            TextAnalyticsApiKeyCredential(text_analytics_account_key))

        docs = [{"id": "1", "text": ""}]
        response = text_analytics.extract_key_phrases(docs)

        # Attribute not found on DocumentError or result obj, default behavior/message
        try:
            key_phrases = response[0].attribute_not_on_result_or_error
        except AttributeError as default_behavior:
            self.assertEqual(
                default_behavior.args[0],
                '\'DocumentError\' object has no attribute \'attribute_not_on_result_or_error\''
            )
Пример #7
0
    async def test_whole_batch_country_hint_and_obj_per_item_hints(self, resource_group, location, text_analytics_account, text_analytics_account_key):
        text_analytics = TextAnalyticsClient(text_analytics_account, TextAnalyticsApiKeyCredential(text_analytics_account_key))

        def callback(resp):
            country_str = "\"countryHint\": \"CA\""
            country = resp.http_request.body.count(country_str)
            self.assertEqual(country, 2)
            country_str = "\"countryHint\": \"US\""
            country = resp.http_request.body.count(country_str)
            self.assertEqual(country, 1)

        docs = [
            DetectLanguageInput(id="1", text="I should take my cat to the veterinarian.", country_hint="CA"),
            DetectLanguageInput(id="4", text="Este es un document escrito en Español.", country_hint="CA"),
            DetectLanguageInput(id="3", text="猫は幸せ"),
        ]

        response = await text_analytics.detect_language(docs, country_hint="US", raw_response_hook=callback)
Пример #8
0
    async def authentication_with_api_key_credential_async(self):
        print("\n.. authentication_with_api_key_credential_async")
        # [START create_ta_client_with_key_async]
        from azure.ai.textanalytics.aio import TextAnalyticsClient
        from azure.ai.textanalytics import TextAnalyticsApiKeyCredential
        endpoint = os.getenv("AZURE_TEXT_ANALYTICS_ENDPOINT")
        key = os.getenv("AZURE_TEXT_ANALYTICS_KEY")

        text_analytics_client = TextAnalyticsClient(
            endpoint, TextAnalyticsApiKeyCredential(key))
        # [END create_ta_client_with_key_async]

        doc = ["I need to take my cat to the veterinarian."]
        async with text_analytics_client:
            result = await text_analytics_client.detect_language(doc)

        print("Language detected: {}".format(result[0].primary_language.name))
        print("Confidence score: {}".format(result[0].primary_language.score))
    async def recognize_entities_async(self):
        # [START single_recognize_entities_async]
        from azure.ai.textanalytics.aio import single_recognize_entities
        from azure.ai.textanalytics import TextAnalyticsApiKeyCredential

        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 = await single_recognize_entities(
            endpoint=self.endpoint,
            credential=TextAnalyticsApiKeyCredential(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))
Пример #10
0
    async def test_bad_model_version_error(self, resource_group, location,
                                           text_analytics_account,
                                           text_analytics_account_key):
        text_analytics = TextAnalyticsClient(
            text_analytics_account,
            TextAnalyticsApiKeyCredential(text_analytics_account_key))
        docs = [{
            "id": "1",
            "language": "english",
            "text": "I did not like the hotel we stayed at."
        }]

        try:
            result = await text_analytics.recognize_linked_entities(
                docs, model_version="bad")
        except HttpResponseError as err:
            self.assertEqual(err.error.code, "InvalidRequest")
            self.assertIsNotNone(err.error.message)
Пример #11
0
    async def test_whole_batch_language_hint_and_obj_per_item_hints(self, resource_group, location, text_analytics_account, text_analytics_account_key):
        text_analytics = TextAnalyticsClient(text_analytics_account, TextAnalyticsApiKeyCredential(text_analytics_account_key))

        def callback(resp):
            language_str = "\"language\": \"es\""
            language = resp.http_request.body.count(language_str)
            self.assertEqual(language, 2)
            language_str = "\"language\": \"en\""
            language = resp.http_request.body.count(language_str)
            self.assertEqual(language, 1)

        docs = [
            TextDocumentInput(id="1", text="I should take my cat to the veterinarian.", language="es"),
            TextDocumentInput(id="2", text="Este es un document escrito en Español.", language="es"),
            TextDocumentInput(id="3", text="猫は幸せ"),
        ]

        response = await text_analytics.recognize_linked_entities(docs, language="en", raw_response_hook=callback)
Пример #12
0
    def test_successful_single_recognize_linked_entities(
            self, resource_group, location, text_analytics_account,
            text_analytics_account_key):
        response = single_recognize_linked_entities(
            endpoint=text_analytics_account,
            credential=TextAnalyticsApiKeyCredential(
                text_analytics_account_key),
            input_text="Microsoft was founded by Bill Gates.",
            language="en")

        self.assertEqual(response.entities[0].name, "Bill Gates")
        self.assertEqual(response.entities[1].name, "Microsoft")
        for entity in response.entities:
            self.assertIsNotNone(entity.matches)
            self.assertIsNotNone(entity.language)
            self.assertIsNotNone(entity.id)
            self.assertIsNotNone(entity.url)
            self.assertIsNotNone(entity.data_source)
Пример #13
0
    def test_successful_single_recognize_entities(self, resource_group,
                                                  location,
                                                  text_analytics_account,
                                                  text_analytics_account_key):
        response = single_recognize_entities(
            endpoint=text_analytics_account,
            credential=TextAnalyticsApiKeyCredential(
                text_analytics_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)
    async def alternative_scenario_recognize_pii_entities_async(self):
        """This sample demonstrates how to retrieve batch statistics, the
        model version used, and the raw response returned from the service.

        It additionally shows an alternative way to pass in the input documents
        using a list[TextDocumentInput] and supplying your own IDs and language hints along
        with the text.
        """
        from azure.ai.textanalytics.aio import TextAnalyticsClient
        from azure.ai.textanalytics import TextAnalyticsApiKeyCredential
        text_analytics_client = TextAnalyticsClient(
            endpoint=self.endpoint,
            credential=TextAnalyticsApiKeyCredential(self.key))

        documents = [{
            "id": "0",
            "language": "en",
            "text": "The employee's SSN is 555-55-5555."
        }, {
            "id":
            "1",
            "language":
            "en",
            "text":
            "Your ABA number - 111000025 - is the first 9 digits in the lower left hand corner of your personal check."
        }, {
            "id": "2",
            "language": "en",
            "text": "Is 998.214.865-68 your Brazilian CPF number?"
        }]

        extras = []

        def callback(resp):
            extras.append(resp.statistics)
            extras.append(resp.model_version)
            extras.append(resp.raw_response)

        async with text_analytics_client:
            result = await text_analytics_client.recognize_pii_entities(
                documents,
                show_stats=True,
                model_version="latest",
                response_hook=callback)
Пример #15
0
    async def alternative_document_input(self):
        from azure.ai.textanalytics.aio import TextAnalyticsClient
        from azure.ai.textanalytics import TextAnalyticsApiKeyCredential
        text_analytics_client = TextAnalyticsClient(
            endpoint=self.endpoint,
            credential=TextAnalyticsApiKeyCredential(self.key))

        documents = [{
            "id": "0",
            "language": "en",
            "text": "I had the best day of my life."
        }, {
            "id":
            "1",
            "language":
            "en",
            "text":
            "This was a waste of my time. The speaker put me to sleep."
        }, {
            "id": "2",
            "language": "es",
            "text": "No tengo dinero ni nada que dar..."
        }, {
            "id":
            "3",
            "language":
            "fr",
            "text":
            "L'hôtel n'était pas très confortable. L'éclairage était trop sombre."
        }]
        async with text_analytics_client:
            result = await text_analytics_client.detect_language(documents)

        for idx, doc in enumerate(result):
            if not doc.is_error:
                print("Document text: {}".format(documents[idx]))
                print("Language detected: {}".format(
                    doc.primary_language.name))
                print("ISO6391 name: {}".format(
                    doc.primary_language.iso6391_name))
                print("Confidence score: {}\n".format(
                    doc.primary_language.score))
            if doc.is_error:
                print(doc.id, doc.error)
Пример #16
0
    async def analyze_sentiment_async(self):
        # [START batch_analyze_sentiment_async]
        from azure.ai.textanalytics.aio import TextAnalyticsClient
        from azure.ai.textanalytics import TextAnalyticsApiKeyCredential
        text_analytics_client = TextAnalyticsClient(
            endpoint=self.endpoint,
            credential=TextAnalyticsApiKeyCredential(self.key))
        documents = [
            "I had the best day of my life.",
            "This was a waste of my time. The speaker put me to sleep.",
            "No tengo dinero ni nada que dar...",
            "L'hôtel n'était pas très confortable. L'éclairage était trop sombre."
        ]

        async with text_analytics_client:
            result = await text_analytics_client.analyze_sentiment(documents)

        docs = [doc for doc in result if not doc.is_error]

        for idx, doc in enumerate(docs):
            print("Document text: {}".format(documents[idx]))
            print("Overall sentiment: {}".format(doc.sentiment))
            # [END batch_analyze_sentiment_async]
            print(
                "Overall scores: positive={0:.3f}; neutral={1:.3f}; negative={2:.3f} \n"
                .format(
                    doc.document_scores.positive,
                    doc.document_scores.neutral,
                    doc.document_scores.negative,
                ))
            for idx, sentence in enumerate(doc.sentences):
                print("Sentence {} sentiment: {}".format(
                    idx + 1, sentence.sentiment))
                print(
                    "Sentence score: positive={0:.3f}; neutral={1:.3f}; negative={2:.3f}"
                    .format(
                        sentence.sentence_scores.positive,
                        sentence.sentence_scores.neutral,
                        sentence.sentence_scores.negative,
                    ))
                print("Offset: {}".format(sentence.offset))
                print("Length: {}\n".format(sentence.length))
            print("------------------------------------")
    def test_passing_only_string(self, resource_group, location,
                                 text_analytics_account,
                                 text_analytics_account_key):
        text_analytics = TextAnalyticsClient(
            text_analytics_account,
            TextAnalyticsApiKeyCredential(text_analytics_account_key))

        docs = [
            u"I should take my cat to the veterinarian.",
            u"Este es un document escrito en Español.", u"猫は幸せ",
            u"Fahrt nach Stuttgart und dann zum Hotel zu Fu.", u""
        ]

        response = text_analytics.detect_language(docs)
        self.assertEqual(response[0].primary_language.name, "English")
        self.assertEqual(response[1].primary_language.name, "Spanish")
        self.assertEqual(response[2].primary_language.name, "Japanese")
        self.assertEqual(response[3].primary_language.name, "German")
        self.assertTrue(response[4].is_error)
    def test_country_hint_kwarg(self, resource_group, location,
                                text_analytics_account,
                                text_analytics_account_key):
        text_analytics = TextAnalyticsClient(
            text_analytics_account,
            TextAnalyticsApiKeyCredential(text_analytics_account_key))

        def callback(response):
            country_str = "\"countryHint\": \"ES\""
            self.assertEqual(response.http_request.body.count(country_str), 1)
            self.assertIsNotNone(response.model_version)
            self.assertIsNotNone(response.statistics)

        res = text_analytics.detect_language(
            documents=["this is written in english"],
            model_version="latest",
            show_stats=True,
            country_hint="ES",
            raw_response_hook=callback)
Пример #19
0
    def test_passing_only_string(self, resource_group, location,
                                 text_analytics_account,
                                 text_analytics_account_key):
        text_analytics = TextAnalyticsClient(
            text_analytics_account,
            TextAnalyticsApiKeyCredential(text_analytics_account_key))

        docs = [
            u"Microsoft was founded by Bill Gates and Paul Allen.",
            u"I did not like the hotel we stayed at. It was too expensive.",
            u"The restaurant had really good food. I recommend you try it.",
            u""
        ]

        response = text_analytics.analyze_sentiment(docs)
        self.assertEqual(response[0].sentiment, "neutral")
        self.assertEqual(response[1].sentiment, "negative")
        self.assertEqual(response[2].sentiment, "positive")
        self.assertTrue(response[3].is_error)
Пример #20
0
    async def alternative_scenario_extract_key_phrases_async(self):
        """This sample demonstrates how to retrieve batch statistics, the
        model version used, and the raw response returned from the service.

        It additionally shows an alternative way to pass in the input documents
        using a list[TextDocumentInput] and supplying your own IDs and language hints along
        with the text.
        """
        from azure.ai.textanalytics.aio import TextAnalyticsClient
        from azure.ai.textanalytics import TextAnalyticsApiKeyCredential
        text_analytics_client = TextAnalyticsClient(
            endpoint=self.endpoint,
            credential=TextAnalyticsApiKeyCredential(self.key))

        documents = [{
            "id":
            "0",
            "language":
            "en",
            "text":
            "Redmond is a city in King County, Washington, United States, located 15 miles east of Seattle."
        }, {
            "id": "1",
            "language": "en",
            "text": "I need to take my cat to the veterinarian."
        }, {
            "id": "2",
            "language": "en",
            "text": "I will travel to South America in the summer."
        }]
        extras = []

        def callback(resp):
            extras.append(resp.statistics)
            extras.append(resp.model_version)
            extras.append(resp.raw_response)

        async with text_analytics_client:
            result = await text_analytics_client.extract_key_phrases(
                documents,
                show_stats=True,
                model_version="latest",
                response_hook=callback)
    def test_input_with_all_errors(self, resource_group, location,
                                   text_analytics_account,
                                   text_analytics_account_key):
        text_analytics = TextAnalyticsClient(
            text_analytics_account,
            TextAnalyticsApiKeyCredential(text_analytics_account_key))

        docs = [{
            "id": "1",
            "text": ""
        }, {
            "id": "2",
            "language": "Spanish",
            "text": "Microsoft fue fundado por Bill Gates y Paul Allen"
        }]

        response = text_analytics.recognize_linked_entities(docs)
        self.assertTrue(response[0].is_error)
        self.assertTrue(response[1].is_error)
Пример #22
0
    async def test_language_kwarg_spanish(self, resource_group, location,
                                          text_analytics_account,
                                          text_analytics_account_key):
        text_analytics = TextAnalyticsClient(
            text_analytics_account,
            TextAnalyticsApiKeyCredential(text_analytics_account_key))

        def callback(response):
            language_str = "\"language\": \"es\""
            self.assertEqual(response.http_request.body.count(language_str), 1)
            self.assertIsNotNone(response.model_version)
            self.assertIsNotNone(response.statistics)

        res = await text_analytics.extract_key_phrases(
            documents=["Bill Gates is the CEO of Microsoft."],
            model_version="latest",
            show_stats=True,
            language="es",
            raw_response_hook=callback)
    def alternative_scenario_recognize_entities(self):
        """This sample demonstrates how to retrieve batch statistics, the
        model version used, and the raw response returned from the service.

        It additionally shows an alternative way to pass in the input documents
        using a list[TextDocumentInput] and supplying your own IDs and language hints along
        with the text.
        """
        from azure.ai.textanalytics import TextAnalyticsClient, TextAnalyticsApiKeyCredential
        text_analytics_client = TextAnalyticsClient(
            endpoint=self.endpoint,
            credential=TextAnalyticsApiKeyCredential(self.key))

        documents = [
            {
                "id": "0",
                "language": "en",
                "text": "Microsoft was founded by Bill Gates and Paul Allen."
            },
            {
                "id": "1",
                "language": "de",
                "text": "I had a wonderful trip to Seattle last week."
            },
            {
                "id": "2",
                "language": "es",
                "text": "I visited the Space Needle 2 times."
            },
        ]

        extras = []

        def callback(resp):
            extras.append(resp.statistics)
            extras.append(resp.model_version)
            extras.append(resp.raw_response)

        result = text_analytics_client.recognize_entities(
            documents,
            show_stats=True,
            model_version="latest",
            response_hook=callback)
Пример #24
0
    def test_language_kwarg_english(self, resource_group, location,
                                    text_analytics_account,
                                    text_analytics_account_key):
        text_analytics = TextAnalyticsClient(
            text_analytics_account,
            TextAnalyticsApiKeyCredential(text_analytics_account_key))

        def callback(response):
            language_str = "\"language\": \"en\""
            self.assertEqual(response.http_request.body.count(language_str), 1)
            self.assertIsNotNone(response.model_version)
            self.assertIsNotNone(response.statistics)

        res = text_analytics.recognize_pii_entities(
            inputs=["Bill Gates is the CEO of Microsoft."],
            model_version="latest",
            show_stats=True,
            language="en",
            raw_response_hook=callback)
    def detect_language(self):
        # [START single_detect_language]
        from azure.ai.textanalytics import single_detect_language, TextAnalyticsApiKeyCredential

        text = "I need to take my cat to the veterinarian."

        result = single_detect_language(
            endpoint=self.endpoint,
            credential=TextAnalyticsApiKeyCredential(self.key),
            input_text=text,
            country_hint="US",
            show_stats=True
        )

        print("Language detected: {}".format(result.primary_language.name))
        print("Confidence score: {}\n".format(result.primary_language.score))
        print("Document Statistics:")
        print("Text character count: {}".format(result.statistics.character_count))
        print("Transactions count: {}".format(result.statistics.transaction_count))
Пример #26
0
 def test_duplicate_ids_error(self, resource_group, location,
                              text_analytics_account,
                              text_analytics_account_key):
     text_analytics = TextAnalyticsClient(
         text_analytics_account,
         TextAnalyticsApiKeyCredential(text_analytics_account_key))
     # Duplicate Ids
     docs = [{
         "id": "1",
         "text": "hello world"
     }, {
         "id": "1",
         "text": "I did not like the hotel we stayed at."
     }]
     try:
         result = text_analytics.recognize_pii_entities(docs)
     except HttpResponseError as err:
         self.assertEqual(err.error.code, "InvalidDocument")
         self.assertIsNotNone(err.error.message)
Пример #27
0
    def test_input_with_all_errors(self, resource_group, location,
                                   text_analytics_account,
                                   text_analytics_account_key):
        text_analytics = TextAnalyticsClient(
            text_analytics_account,
            TextAnalyticsApiKeyCredential(text_analytics_account_key))

        docs = [{
            "id": "1",
            "language": "es",
            "text": "hola"
        }, {
            "id": "2",
            "text": ""
        }]

        response = text_analytics.recognize_pii_entities(docs)
        self.assertTrue(response[0].is_error)
        self.assertTrue(response[1].is_error)
Пример #28
0
    async def test_all_successful_passing_dict(self, resource_group, location,
                                               text_analytics_account,
                                               text_analytics_account_key):
        text_analytics = TextAnalyticsClient(
            text_analytics_account,
            TextAnalyticsApiKeyCredential(text_analytics_account_key))

        docs = [{
            "id":
            "1",
            "language":
            "en",
            "text":
            "Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975."
        }, {
            "id":
            "2",
            "language":
            "es",
            "text":
            "Microsoft fue fundado por Bill Gates y Paul Allen el 4 de abril de 1975."
        }, {
            "id":
            "3",
            "language":
            "de",
            "text":
            "Microsoft wurde am 4. April 1975 von Bill Gates und Paul Allen gegründet."
        }]

        response = await text_analytics.recognize_entities(docs,
                                                           show_stats=True)
        for doc in response:
            self.assertEqual(len(doc.entities), 4)
            self.assertIsNotNone(doc.id)
            self.assertIsNotNone(doc.statistics)
            for entity in doc.entities:
                self.assertIsNotNone(entity.text)
                self.assertIsNotNone(entity.category)
                self.assertIsNotNone(entity.grapheme_offset)
                self.assertIsNotNone(entity.grapheme_length)
                self.assertIsNotNone(entity.confidence_score)
Пример #29
0
    def test_whole_batch_dont_use_language_hint(self, resource_group, location,
                                                text_analytics_account,
                                                text_analytics_account_key):
        text_analytics = TextAnalyticsClient(
            text_analytics_account,
            TextAnalyticsApiKeyCredential(text_analytics_account_key))

        def callback(resp):
            language_str = "\"language\": \"\""
            language = resp.http_request.body.count(language_str)
            self.assertEqual(language, 3)

        docs = [
            u"This was the best day of my life.",
            u"I did not like the hotel we stayed at. It was too expensive.",
            u"The restaurant was not as good as I hoped."
        ]

        response = text_analytics.recognize_pii_entities(
            docs, language="", raw_response_hook=callback)
Пример #30
0
    async def test_input_with_all_errors(self, resource_group, location,
                                         text_analytics_account,
                                         text_analytics_account_key):
        text_analytics = TextAnalyticsClient(
            text_analytics_account,
            TextAnalyticsApiKeyCredential(text_analytics_account_key))

        docs = [{
            "id": "1",
            "language": "English",
            "text": "Microsoft was founded by Bill Gates and Paul Allen"
        }, {
            "id": "2",
            "language": "es",
            "text": ""
        }]

        response = await text_analytics.extract_key_phrases(docs)
        self.assertTrue(response[0].is_error)
        self.assertTrue(response[1].is_error)