Ejemplo n.º 1
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)
Ejemplo n.º 2
0
def _clean_up_indexers(endpoint, api_key):
    from azure.search.documents.indexes import SearchIndexerClient
    client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key))
    for indexer in client.get_indexers():
        client.delete_indexer(indexer)
    for datasource in client.get_data_source_connection_names():
        client.delete_data_source_connection(datasource)
    for skillset in client.get_skillset_names():
        client.delete_skillset(skillset)
Ejemplo n.º 3
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
Ejemplo n.º 4
0
    def test_create_skillset(self, api_key, endpoint, index_name, **kwargs):
        client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key))
        name = "test-ss"

        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)

        s4 = SentimentSkill(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(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")

        client.delete_skillset(name)

        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