Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[text analytics] add test for opinion in diff sentence #13524

Merged
merged 1 commit into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions sdk/textanalytics/azure-ai-textanalytics/tests/test_json_pointer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this scenario not currently supported by the service?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it's not supported yet, but @maririos wanted to add a test so when it is supported, I'm able to deal with it service side. That's why I have to create the generated models myself

# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
import pytest
from azure.ai.textanalytics._models import (
AnalyzeSentimentResult,
AspectSentiment,
OpinionSentiment,
SentenceSentiment,
_get_indices,
)

from azure.ai.textanalytics._response_handlers import sentiment_result

from azure.ai.textanalytics._generated.v3_1_preview_1 import models as _generated_models


@pytest.fixture
def generated_aspect_opinion_confidence_scores():
return _generated_models.AspectConfidenceScoreLabel(
positive=1.0,
neutral=0.0,
negative=0.0,
)

@pytest.fixture
def generated_sentiment_confidence_score():
return _generated_models.SentimentConfidenceScorePerLabel(
positive=1.0,
neutral=0.0,
negative=0.0,
)

@pytest.fixture
def generated_aspect_relation():
return _generated_models.AspectRelation(
relation_type="opinion",
ref="#/documents/0/sentences/1/opinions/0"
)

@pytest.fixture
def generated_aspect(generated_aspect_opinion_confidence_scores, generated_aspect_relation):
return _generated_models.SentenceAspect(
text="aspect",
sentiment="positive",
confidence_scores=generated_aspect_opinion_confidence_scores,
offset=0,
length=6,
relations=[generated_aspect_relation],
)

@pytest.fixture
def generated_opinion(generated_aspect_opinion_confidence_scores):
return _generated_models.SentenceOpinion(
text="good",
sentiment="positive",
confidence_scores=generated_aspect_opinion_confidence_scores,
offset=0,
length=4,
is_negated=False,
)

def generated_sentence_sentiment(generated_sentiment_confidence_score, index, aspects=[], opinions=[]):
return _generated_models.SentenceSentiment(
text="not relevant",
sentiment="positive",
confidence_scores=generated_sentiment_confidence_score,
offset=0,
length=12,
aspects=aspects,
opinions=opinions,
)

@pytest.fixture
def generated_document_sentiment(generated_aspect, generated_opinion, generated_sentiment_confidence_score):
aspect_sentence = generated_sentence_sentiment(generated_sentiment_confidence_score, index=0, aspects=[generated_aspect])
opinion_sentence = generated_sentence_sentiment(generated_sentiment_confidence_score, index=1, opinions=[generated_opinion])

return _generated_models.DocumentSentiment(
id=1,
sentiment="positive",
confidence_scores=generated_sentiment_confidence_score,
sentences=[aspect_sentence, opinion_sentence],
warnings=[],
)

@pytest.fixture
def generated_sentiment_response(generated_document_sentiment):
return _generated_models.SentimentResponse(
documents=[generated_document_sentiment],
errors=[],
model_version="0000-00-00",
)


class TestJsonPointer():

def test_json_pointer_parsing(self):
assert [1, 0, 15] == _get_indices("#/documents/1/sentences/0/opinions/15")

def test_opinion_different_sentence_aspect(self, generated_sentiment_response):
# the first sentence has the aspect, and the second sentence has the opinion
# the desired behavior is the first wrapped sentence object has an aspect, and it's opinion
# is in the second sentence.
# the second sentence will have no mined opinions, since we define that as an aspect and opinion duo
wrapped_sentiment = sentiment_result(response="not relevant", obj=generated_sentiment_response, response_headers={})[0]
assert wrapped_sentiment.sentences[0].mined_opinions[0].opinions[0].text == "good"
assert not wrapped_sentiment.sentences[1].mined_opinions
14 changes: 0 additions & 14 deletions sdk/textanalytics/azure-ai-textanalytics/tests/test_unittests.py

This file was deleted.