Skip to content

Commit 8f0d9a9

Browse files
authored
[text analytics] don't take doc # in json pointer to account for now bc of service bug (#13820)
1 parent 0b6c4b2 commit 8f0d9a9

6 files changed

+184
-8
lines changed

sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_models.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ def __init__(self, **kwargs):
820820
self.mined_opinions = kwargs.get("mined_opinions", None)
821821

822822
@classmethod
823-
def _from_generated(cls, sentence, results):
823+
def _from_generated(cls, sentence, results, sentiment):
824824
offset = sentence.offset
825825
length = sentence.length
826826
if isinstance(sentence, _v3_0_models.SentenceSentiment):
@@ -830,7 +830,7 @@ def _from_generated(cls, sentence, results):
830830
length = None
831831
if hasattr(sentence, "aspects"):
832832
mined_opinions = (
833-
[MinedOpinion._from_generated(aspect, results) for aspect in sentence.aspects] # pylint: disable=protected-access
833+
[MinedOpinion._from_generated(aspect, results, sentiment) for aspect in sentence.aspects] # pylint: disable=protected-access
834834
if sentence.aspects else []
835835
)
836836
else:
@@ -871,27 +871,27 @@ def __init__(self, **kwargs):
871871
self.opinions = kwargs.get("opinions", None)
872872

873873
@staticmethod
874-
def _get_opinions(relations, results):
874+
def _get_opinions(relations, results, sentiment): # pylint: disable=unused-argument
875875
if not relations:
876876
return []
877877
opinion_relations = [r.ref for r in relations if r.relation_type == "opinion"]
878878
opinions = []
879879
for opinion_relation in opinion_relations:
880880
nums = _get_indices(opinion_relation)
881-
document_index = nums[0]
882881
sentence_index = nums[1]
883882
opinion_index = nums[2]
884883
opinions.append(
885-
results[document_index].sentences[sentence_index].opinions[opinion_index]
884+
sentiment.sentences[sentence_index].opinions[opinion_index]
886885
)
887886
return opinions
888887

889888
@classmethod
890-
def _from_generated(cls, aspect, results):
889+
def _from_generated(cls, aspect, results, sentiment):
891890
return cls(
892891
aspect=AspectSentiment._from_generated(aspect), # pylint: disable=protected-access
893892
opinions=[
894-
OpinionSentiment._from_generated(opinion) for opinion in cls._get_opinions(aspect.relations, results) # pylint: disable=protected-access
893+
OpinionSentiment._from_generated(opinion) # pylint: disable=protected-access
894+
for opinion in cls._get_opinions(aspect.relations, results, sentiment)
895895
],
896896
)
897897

sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_response_handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def sentiment_result(sentiment, results):
126126
warnings=[TextAnalyticsWarning._from_generated(w) for w in sentiment.warnings], # pylint: disable=protected-access
127127
statistics=TextDocumentStatistics._from_generated(sentiment.statistics), # pylint: disable=protected-access
128128
confidence_scores=SentimentConfidenceScores._from_generated(sentiment.confidence_scores), # pylint: disable=protected-access
129-
sentences=[SentenceSentiment._from_generated(s, results) for s in sentiment.sentences], # pylint: disable=protected-access
129+
sentences=[SentenceSentiment._from_generated(s, results, sentiment) for s in sentiment.sentences], # pylint: disable=protected-access
130130
)
131131

132132
@prepare_result
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
interactions:
2+
- request:
3+
body: '{"documents": [{"id": "0", "text": "The food was unacceptable", "language":
4+
"en"}, {"id": "1", "text": "The rooms were beautiful. The AC was good and quiet.",
5+
"language": "en"}, {"id": "2", "text": "The breakfast was good, but the toilet
6+
was smelly.", "language": "en"}, {"id": "3", "text": "Loved this hotel - good
7+
breakfast - nice shuttle service - clean rooms.", "language": "en"}, {"id":
8+
"4", "text": "I had a great unobstructed view of the Microsoft campus.", "language":
9+
"en"}, {"id": "5", "text": "Nice rooms but bathrooms were old and the toilet
10+
was dirty when we arrived.", "language": "en"}, {"id": "6", "text": "The toilet
11+
smelled.", "language": "en"}]}'
12+
headers:
13+
Accept:
14+
- application/json, text/json
15+
Accept-Encoding:
16+
- gzip, deflate
17+
Connection:
18+
- keep-alive
19+
Content-Length:
20+
- '664'
21+
Content-Type:
22+
- application/json
23+
User-Agent:
24+
- azsdk-python-ai-textanalytics/5.1.0b1 Python/3.8.5 (macOS-10.13.6-x86_64-i386-64bit)
25+
method: POST
26+
uri: https://westcentralus.api.cognitive.microsoft.com/text/analytics/v3.1-preview.2/sentiment?showStats=false&opinionMining=true&stringIndexType=UnicodeCodePoint
27+
response:
28+
body:
29+
string: '{"documents":[{"id":"0","sentiment":"negative","confidenceScores":{"positive":0.0,"neutral":0.0,"negative":1.0},"sentences":[{"sentiment":"negative","confidenceScores":{"positive":0.0,"neutral":0.0,"negative":1.0},"offset":0,"length":25,"text":"The
30+
food was unacceptable","aspects":[{"sentiment":"negative","confidenceScores":{"positive":0.0,"negative":1.0},"offset":4,"length":4,"text":"food","relations":[{"relationType":"opinion","ref":"#/documents/0/sentences/0/opinions/0"}]}],"opinions":[{"sentiment":"negative","confidenceScores":{"positive":0.0,"negative":1.0},"offset":13,"length":12,"text":"unacceptable","isNegated":false}]}],"warnings":[]},{"id":"1","sentiment":"positive","confidenceScores":{"positive":1.0,"neutral":0.0,"negative":0.0},"sentences":[{"sentiment":"positive","confidenceScores":{"positive":1.0,"neutral":0.0,"negative":0.0},"offset":0,"length":25,"text":"The
31+
rooms were beautiful.","aspects":[{"sentiment":"positive","confidenceScores":{"positive":1.0,"negative":0.0},"offset":4,"length":5,"text":"rooms","relations":[{"relationType":"opinion","ref":"#/documents/1/sentences/0/opinions/0"}]}],"opinions":[{"sentiment":"positive","confidenceScores":{"positive":1.0,"negative":0.0},"offset":15,"length":9,"text":"beautiful","isNegated":false}]},{"sentiment":"positive","confidenceScores":{"positive":1.0,"neutral":0.0,"negative":0.0},"offset":26,"length":26,"text":"The
32+
AC was good and quiet.","aspects":[{"sentiment":"positive","confidenceScores":{"positive":1.0,"negative":0.0},"offset":30,"length":2,"text":"AC","relations":[{"relationType":"opinion","ref":"#/documents/1/sentences/1/opinions/0"},{"relationType":"opinion","ref":"#/documents/1/sentences/1/opinions/1"}]}],"opinions":[{"sentiment":"positive","confidenceScores":{"positive":1.0,"negative":0.0},"offset":37,"length":4,"text":"good","isNegated":false},{"sentiment":"positive","confidenceScores":{"positive":1.0,"negative":0.0},"offset":46,"length":5,"text":"quiet","isNegated":false}]}],"warnings":[]},{"id":"2","sentiment":"negative","confidenceScores":{"positive":0.01,"neutral":0.0,"negative":0.99},"sentences":[{"sentiment":"negative","confidenceScores":{"positive":0.01,"neutral":0.0,"negative":0.99},"offset":0,"length":50,"text":"The
33+
breakfast was good, but the toilet was smelly.","aspects":[{"sentiment":"positive","confidenceScores":{"positive":1.0,"negative":0.0},"offset":4,"length":9,"text":"breakfast","relations":[{"relationType":"opinion","ref":"#/documents/2/sentences/0/opinions/0"}]},{"sentiment":"negative","confidenceScores":{"positive":0.0,"negative":1.0},"offset":32,"length":6,"text":"toilet","relations":[{"relationType":"opinion","ref":"#/documents/2/sentences/0/opinions/1"}]}],"opinions":[{"sentiment":"positive","confidenceScores":{"positive":1.0,"negative":0.0},"offset":18,"length":4,"text":"good","isNegated":false},{"sentiment":"negative","confidenceScores":{"positive":0.0,"negative":1.0},"offset":43,"length":6,"text":"smelly","isNegated":false}]}],"warnings":[]},{"id":"3","sentiment":"positive","confidenceScores":{"positive":1.0,"neutral":0.0,"negative":0.0},"sentences":[{"sentiment":"positive","confidenceScores":{"positive":1.0,"neutral":0.0,"negative":0.0},"offset":0,"length":71,"text":"Loved
34+
this hotel - good breakfast - nice shuttle service - clean rooms.","aspects":[{"sentiment":"positive","confidenceScores":{"positive":1.0,"negative":0.0},"offset":11,"length":5,"text":"hotel","relations":[{"relationType":"opinion","ref":"#/documents/3/sentences/0/opinions/0"}]},{"sentiment":"positive","confidenceScores":{"positive":1.0,"negative":0.0},"offset":24,"length":9,"text":"breakfast","relations":[{"relationType":"opinion","ref":"#/documents/3/sentences/0/opinions/1"}]},{"sentiment":"positive","confidenceScores":{"positive":1.0,"negative":0.0},"offset":41,"length":15,"text":"shuttle
35+
service","relations":[{"relationType":"opinion","ref":"#/documents/3/sentences/0/opinions/2"}]},{"sentiment":"positive","confidenceScores":{"positive":1.0,"negative":0.0},"offset":65,"length":5,"text":"rooms","relations":[{"relationType":"opinion","ref":"#/documents/3/sentences/0/opinions/0"},{"relationType":"opinion","ref":"#/documents/3/sentences/0/opinions/1"},{"relationType":"opinion","ref":"#/documents/3/sentences/0/opinions/3"},{"relationType":"opinion","ref":"#/documents/3/sentences/0/opinions/2"}]}],"opinions":[{"sentiment":"positive","confidenceScores":{"positive":1.0,"negative":0.0},"offset":19,"length":4,"text":"good","isNegated":false},{"sentiment":"positive","confidenceScores":{"positive":1.0,"negative":0.0},"offset":36,"length":4,"text":"nice","isNegated":false},{"sentiment":"positive","confidenceScores":{"positive":1.0,"negative":0.0},"offset":0,"length":5,"text":"loved","isNegated":false},{"sentiment":"positive","confidenceScores":{"positive":1.0,"negative":0.0},"offset":59,"length":5,"text":"clean","isNegated":false}]}],"warnings":[]},{"id":"4","sentiment":"positive","confidenceScores":{"positive":1.0,"neutral":0.0,"negative":0.0},"sentences":[{"sentiment":"positive","confidenceScores":{"positive":1.0,"neutral":0.0,"negative":0.0},"offset":0,"length":56,"text":"I
36+
had a great unobstructed view of the Microsoft campus.","aspects":[{"sentiment":"positive","confidenceScores":{"positive":0.97,"negative":0.03},"offset":27,"length":4,"text":"view","relations":[{"relationType":"opinion","ref":"#/documents/4/sentences/0/opinions/0"},{"relationType":"opinion","ref":"#/documents/4/sentences/0/opinions/1"}]}],"opinions":[{"sentiment":"positive","confidenceScores":{"positive":1.0,"negative":0.0},"offset":8,"length":5,"text":"great","isNegated":false},{"sentiment":"positive","confidenceScores":{"positive":0.93,"negative":0.07},"offset":14,"length":12,"text":"unobstructed","isNegated":false}]}],"warnings":[]},{"id":"5","sentiment":"negative","confidenceScores":{"positive":0.0,"neutral":0.0,"negative":1.0},"sentences":[{"sentiment":"negative","confidenceScores":{"positive":0.0,"neutral":0.0,"negative":1.0},"offset":0,"length":75,"text":"Nice
37+
rooms but bathrooms were old and the toilet was dirty when we arrived.","aspects":[{"sentiment":"positive","confidenceScores":{"positive":1.0,"negative":0.0},"offset":5,"length":5,"text":"rooms","relations":[{"relationType":"opinion","ref":"#/documents/0/sentences/0/opinions/0"}]},{"sentiment":"negative","confidenceScores":{"positive":0.0,"negative":1.0},"offset":15,"length":9,"text":"bathrooms","relations":[{"relationType":"opinion","ref":"#/documents/0/sentences/0/opinions/1"}]},{"sentiment":"negative","confidenceScores":{"positive":0.0,"negative":1.0},"offset":42,"length":6,"text":"toilet","relations":[{"relationType":"opinion","ref":"#/documents/0/sentences/0/opinions/2"}]}],"opinions":[{"sentiment":"positive","confidenceScores":{"positive":1.0,"negative":0.0},"offset":0,"length":4,"text":"nice","isNegated":false},{"sentiment":"negative","confidenceScores":{"positive":0.0,"negative":1.0},"offset":30,"length":3,"text":"old","isNegated":false},{"sentiment":"negative","confidenceScores":{"positive":0.0,"negative":1.0},"offset":53,"length":5,"text":"dirty","isNegated":false}]}],"warnings":[]},{"id":"6","sentiment":"neutral","confidenceScores":{"positive":0.03,"neutral":0.63,"negative":0.34},"sentences":[{"sentiment":"neutral","confidenceScores":{"positive":0.03,"neutral":0.63,"negative":0.34},"offset":0,"length":19,"text":"The
38+
toilet smelled.","aspects":[{"sentiment":"negative","confidenceScores":{"positive":0.01,"negative":0.99},"offset":4,"length":6,"text":"toilet","relations":[{"relationType":"opinion","ref":"#/documents/1/sentences/0/opinions/0"}]}],"opinions":[{"sentiment":"negative","confidenceScores":{"positive":0.01,"negative":0.99},"offset":11,"length":7,"text":"smelled","isNegated":false}]}],"warnings":[]}],"errors":[],"modelVersion":"2020-04-01"}'
39+
headers:
40+
apim-request-id:
41+
- 3114573b-7cce-415e-8fb0-4a40fbb1fdf4
42+
content-type:
43+
- application/json; charset=utf-8
44+
csp-billing-usage:
45+
- CognitiveServices.TextAnalytics.BatchScoring=7
46+
date:
47+
- Wed, 16 Sep 2020 19:41:48 GMT
48+
strict-transport-security:
49+
- max-age=31536000; includeSubDomains; preload
50+
transfer-encoding:
51+
- chunked
52+
x-content-type-options:
53+
- nosniff
54+
x-envoy-upstream-service-time:
55+
- '113'
56+
status:
57+
code: 200
58+
message: OK
59+
version: 1

0 commit comments

Comments
 (0)