def _test_create_skillset_validation(self):
        name = "test-ss-validation"
        with pytest.raises(ValueError) as err:
            client = SearchIndexerClient("fake_endpoint", AzureKeyCredential("fake_key"))

            s1 = EntityRecognitionSkill(inputs=[InputFieldMappingEntry(name="text", source="/document/content")],
                                        outputs=[OutputFieldMappingEntry(name="organizations", target_name="organizationsS1")],
                                        description="Skill Version 1",
                                        model_version="1",
                                        include_typeless_entities=True)

            s2 = EntityRecognitionSkill(inputs=[InputFieldMappingEntry(name="text", source="/document/content")],
                                        outputs=[OutputFieldMappingEntry(name="organizations", target_name="organizationsS2")],
                                        skill_version=EntityRecognitionSkillVersion.LATEST,
                                        description="Skill Version 3",
                                        model_version="3",
                                        include_typeless_entities=True)
            s3 = SentimentSkill(inputs=[InputFieldMappingEntry(name="text", source="/document/content")],
                                outputs=[OutputFieldMappingEntry(name="score", target_name="scoreS3")],
                                skill_version=SentimentSkillVersion.V1,
                                description="Sentiment V1",
                                include_opinion_mining=True)
            skillset = SearchIndexerSkillset(name=name, skills=list([s1, s2, s3]), description="desc")
            client.create_skillset(skillset)
        assert 'include_typeless_entities' in str(err.value)
        assert 'model_version' in str(err.value)
        assert 'include_opinion_mining' in str(err.value)
Beispiel #2
0
    def test_delete_skillset_if_unchanged(self, api_key, endpoint, index_name,
                                          **kwargs):
        client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key))
        s = EntityRecognitionSkill(inputs=[
            InputFieldMappingEntry(name="text", source="/document/content")
        ],
                                   outputs=[
                                       OutputFieldMappingEntry(
                                           name="organizations",
                                           target_name="organizations")
                                   ])

        result = client.create_skillset(name='test-ss',
                                        skills=[s],
                                        description="desc")
        etag = result.e_tag

        updated = client.create_or_update_skillset(name='test-ss',
                                                   skills=[s],
                                                   description="updated")
        updated.e_tag = etag

        with pytest.raises(HttpResponseError):
            client.delete_skillset(
                updated, match_condition=MatchConditions.IfNotModified)
    def test_create_skillset(self, api_key, endpoint, index_name, **kwargs):
        client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key))

        s = EntityRecognitionSkill(inputs=[
            InputFieldMappingEntry(name="text", source="/document/content")
        ],
                                   outputs=[
                                       OutputFieldMappingEntry(
                                           name="organizations",
                                           target_name="organizations")
                                   ])

        skillset = SearchIndexerSkillset(name='test-ss',
                                         skills=list([s]),
                                         description="desc")

        result = client.create_skillset(skillset)
        assert isinstance(result, SearchIndexerSkillset)
        assert result.name == "test-ss"
        assert result.description == "desc"
        assert result.e_tag
        assert len(result.skills) == 1
        assert isinstance(result.skills[0], EntityRecognitionSkill)

        assert len(client.get_skillsets()) == 1
Beispiel #4
0
def _create_skillset():
    client = SearchIndexerClient(service_endpoint, AzureKeyCredential(key))
    inp = InputFieldMappingEntry(name="text", source="/document/lastRenovationDate")
    output = OutputFieldMappingEntry(name="dateTimes", target_name="RenovatedDate")
    s = EntityRecognitionSkill(name="merge-skill", inputs=[inp], outputs=[output])

    skillset = SearchIndexerSkillset(name='hotel-data-skill', skills=[s], description="example skillset")
    result = client.create_skillset(skillset)
    return result
Beispiel #5
0
    def test_get_skillsets(self, api_key, endpoint, index_name, **kwargs):
        client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key))
        s = EntityRecognitionSkill(inputs=[
            InputFieldMappingEntry(name="text", source="/document/content")
        ],
                                   outputs=[
                                       OutputFieldMappingEntry(
                                           name="organizations",
                                           target_name="organizations")
                                   ])

        client.create_skillset(name='test-ss-1',
                               skills=[s],
                               description="desc1")
        client.create_skillset(name='test-ss-2',
                               skills=[s],
                               description="desc2")
        result = client.get_skillsets()
        assert isinstance(result, list)
        assert all(isinstance(x, SearchIndexerSkillset) for x in result)
        assert set(x.name for x in result) == {"test-ss-1", "test-ss-2"}
Beispiel #6
0
    def test_delete_skillset(self, api_key, endpoint, index_name, **kwargs):
        client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key))
        s = EntityRecognitionSkill(inputs=[
            InputFieldMappingEntry(name="text", source="/document/content")
        ],
                                   outputs=[
                                       OutputFieldMappingEntry(
                                           name="organizations",
                                           target_name="organizations")
                                   ])

        result = client.create_skillset(name='test-ss',
                                        skills=[s],
                                        description="desc")
        assert len(client.get_skillsets()) == 1

        client.delete_skillset("test-ss")
        assert len(client.get_skillsets()) == 0
Beispiel #7
0
    def test_create_skillset(self, api_key, endpoint, index_name, **kwargs):
        client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key))
        name = "test-ss"

        s1 = EntityRecognitionSkill(
            name="skill1",
            inputs=[
                InputFieldMappingEntry(name="text", source="/document/content")
            ],
            outputs=[
                OutputFieldMappingEntry(name="organizations",
                                        target_name="organizationsS1")
            ],
            description="Skill Version 1",
            include_typeless_entities=True)

        s2 = EntityRecognitionSkill(
            name="skill2",
            inputs=[
                InputFieldMappingEntry(name="text", source="/document/content")
            ],
            outputs=[
                OutputFieldMappingEntry(name="organizations",
                                        target_name="organizationsS2")
            ],
            skill_version=EntityRecognitionSkillVersion.LATEST,
            description="Skill Version 3",
            model_version="3")
        s3 = SentimentSkill(name="skill3",
                            inputs=[
                                InputFieldMappingEntry(
                                    name="text", source="/document/content")
                            ],
                            outputs=[
                                OutputFieldMappingEntry(name="score",
                                                        target_name="scoreS3")
                            ],
                            skill_version=SentimentSkillVersion.V1,
                            description="Sentiment V1")

        s4 = SentimentSkill(
            name="skill4",
            inputs=[
                InputFieldMappingEntry(name="text", source="/document/content")
            ],
            outputs=[
                OutputFieldMappingEntry(name="confidenceScores",
                                        target_name="scoreS4")
            ],
            skill_version=SentimentSkillVersion.V3,
            description="Sentiment V3",
            include_opinion_mining=True)

        s5 = EntityLinkingSkill(
            name="skill5",
            inputs=[
                InputFieldMappingEntry(name="text", source="/document/content")
            ],
            outputs=[
                OutputFieldMappingEntry(name="entities",
                                        target_name="entitiesS5")
            ],
            minimum_precision=0.5)

        skillset = SearchIndexerSkillset(name=name,
                                         skills=list([s1, s2, s3, s4, s5]),
                                         description="desc")

        dict_skills = [skill.as_dict() for skill in skillset.skills]
        skillset.skills = dict_skills

        result = client.create_skillset(skillset)

        assert isinstance(result, SearchIndexerSkillset)
        assert result.name == "test-ss"
        assert result.description == "desc"
        assert result.e_tag
        assert len(result.skills) == 5
        assert isinstance(result.skills[0], EntityRecognitionSkill)
        assert result.skills[
            0].skill_version == EntityRecognitionSkillVersion.V1
        assert isinstance(result.skills[1], EntityRecognitionSkill)
        assert result.skills[
            1].skill_version == EntityRecognitionSkillVersion.V3
        assert isinstance(result.skills[2], SentimentSkill)
        assert result.skills[2].skill_version == SentimentSkillVersion.V1
        assert isinstance(result.skills[3], SentimentSkill)
        assert result.skills[3].skill_version == SentimentSkillVersion.V3
        assert isinstance(result.skills[4], EntityLinkingSkill)
        assert result.skills[4].minimum_precision == 0.5

        assert len(client.get_skillsets()) == 1

        client.reset_skills(result, [x.name for x in result.skills])