-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
sdk/textanalytics/azure-ai-textanalytics/tests/test_json_pointer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# 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
14
sdk/textanalytics/azure-ai-textanalytics/tests/test_unittests.py
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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