Skip to content

Commit fb5df37

Browse files
iscai-msftroot
authored and
root
committed
score -> confidence_score in CategorizedEntity, LinkedEntityMatch, and PiiEntity (#10279)
1 parent a8c3a5f commit fb5df37

14 files changed

+53
-47
lines changed

sdk/textanalytics/azure-ai-textanalytics/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Change Log azure-ai-textanalytics
22

33
## 1.0.0b4 (Unreleased)
4+
**Breaking changes**
5+
- `score` attribute has been renamed to `confidence_score` for the `CategorizedEntity`, `LinkedEntityMatch`, and
6+
`PiiEntity` models
47

58

69
## 1.0.0b3 (2020-03-10)

sdk/textanalytics/azure-ai-textanalytics/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ result = [doc for doc in response if not doc.is_error]
238238
for doc in result:
239239
for entity in doc.entities:
240240
print("Entity: \t", entity.text, "\tCategory: \t", entity.category,
241-
"\tConfidence Score: \t", entity.score)
241+
"\tConfidence Score: \t", entity.confidence_score)
242242
```
243243

244244
The returned response is a heterogeneous list of result and error objects: list[[RecognizeEntitiesResult][recognize_entities_result], [DocumentError][document_error]]
@@ -266,7 +266,7 @@ result = [doc for doc in response if not doc.is_error]
266266
for doc in result:
267267
for entity in doc.entities:
268268
print("Entity: \t", entity.text, "\tCategory: \t", entity.category,
269-
"\tConfidence Score: \t", entity.score)
269+
"\tConfidence Score: \t", entity.confidence_score)
270270
```
271271

272272
The returned response is a heterogeneous list of result and error objects: list[[RecognizePiiEntitiesResult][recognize_pii_entities_result], [DocumentError][document_error]]
@@ -297,7 +297,7 @@ for doc in result:
297297
print("URL: {}".format(entity.url))
298298
print("Data Source: {}".format(entity.data_source))
299299
for match in entity.matches:
300-
print("Score: {}".format(match.score))
300+
print("Confidence Score: {}".format(match.confidence_score))
301301
print("Entity as appears in request: {}".format(match.text))
302302
```
303303

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

+21-18
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ class CategorizedEntity(DictMixin):
196196
:param grapheme_length: Length (in Unicode characters) for the entity
197197
text.
198198
:type grapheme_length: int
199-
:param score: Confidence score between 0 and 1 of the extracted
199+
:param confidence_score: Confidence score between 0 and 1 of the extracted
200200
entity.
201-
:type score: float
201+
:type confidence_score: float
202202
"""
203203

204204
def __init__(self, **kwargs):
@@ -207,7 +207,7 @@ def __init__(self, **kwargs):
207207
self.subcategory = kwargs.get('subcategory', None)
208208
self.grapheme_offset = kwargs.get('grapheme_offset', None)
209209
self.grapheme_length = kwargs.get('grapheme_length', None)
210-
self.score = kwargs.get('score', None)
210+
self.confidence_score = kwargs.get('confidence_score', None)
211211

212212
@classmethod
213213
def _from_generated(cls, entity):
@@ -217,13 +217,13 @@ def _from_generated(cls, entity):
217217
subcategory=entity.subtype,
218218
grapheme_offset=entity.offset,
219219
grapheme_length=entity.length,
220-
score=entity.score,
220+
confidence_score=entity.score,
221221
)
222222

223223
def __repr__(self):
224224
return "CategorizedEntity(text={}, category={}, subcategory={}, grapheme_offset={}, grapheme_length={}, " \
225-
"score={})".format(self.text, self.category, self.subcategory, self.grapheme_offset,
226-
self.grapheme_length, self.score)[:1024]
225+
"confidence_score={})".format(self.text, self.category, self.subcategory, self.grapheme_offset,
226+
self.grapheme_length, self.confidence_score)[:1024]
227227

228228

229229
class PiiEntity(DictMixin):
@@ -244,9 +244,9 @@ class PiiEntity(DictMixin):
244244
:param grapheme_length: Length (in Unicode characters) for the entity
245245
text.
246246
:type grapheme_length: int
247-
:param score: Confidence score between 0 and 1 of the extracted
247+
:param confidence_score: Confidence score between 0 and 1 of the extracted
248248
entity.
249-
:type score: float
249+
:type confidence_score: float
250250
"""
251251

252252
def __init__(self, **kwargs):
@@ -255,7 +255,7 @@ def __init__(self, **kwargs):
255255
self.subcategory = kwargs.get('subcategory', None)
256256
self.grapheme_offset = kwargs.get('grapheme_offset', None)
257257
self.grapheme_length = kwargs.get('grapheme_length', None)
258-
self.score = kwargs.get('score', None)
258+
self.confidence_score = kwargs.get('confidence_score', None)
259259

260260
@classmethod
261261
def _from_generated(cls, entity):
@@ -265,13 +265,13 @@ def _from_generated(cls, entity):
265265
subcategory=entity.subtype,
266266
grapheme_offset=entity.offset,
267267
grapheme_length=entity.length,
268-
score=entity.score,
268+
confidence_score=entity.score,
269269
)
270270

271271
def __repr__(self):
272272
return "PiiEntity(text={}, category={}, subcategory={}, grapheme_offset={}, grapheme_length={}, " \
273-
"score={})".format(self.text, self.category, self.subcategory, self.grapheme_offset,
274-
self.grapheme_length, self.score)[:1024]
273+
"confidence_score={})".format(self.text, self.category, self.subcategory, self.grapheme_offset,
274+
self.grapheme_length, self.confidence_score)[:1024]
275275

276276

277277
class TextAnalyticsError(DictMixin):
@@ -574,10 +574,10 @@ class LinkedEntityMatch(DictMixin):
574574
the confidence score of the prediction and where the entity
575575
was found in the text.
576576
577-
:param score: If a well-known item is recognized, a
577+
:param confidence_score: If a well-known item is recognized, a
578578
decimal number denoting the confidence level between 0 and 1 will be
579579
returned.
580-
:type score: float
580+
:type confidence_score: float
581581
:param text: Entity text as appears in the request.
582582
:type text: str
583583
:param grapheme_offset: Start position (in Unicode characters) for the
@@ -589,20 +589,23 @@ class LinkedEntityMatch(DictMixin):
589589
"""
590590

591591
def __init__(self, **kwargs):
592-
self.score = kwargs.get("score", None)
592+
self.confidence_score = kwargs.get("confidence_score", None)
593593
self.text = kwargs.get("text", None)
594594
self.grapheme_offset = kwargs.get("grapheme_offset", None)
595595
self.grapheme_length = kwargs.get("grapheme_length", None)
596596

597597
@classmethod
598598
def _from_generated(cls, match):
599599
return cls(
600-
score=match.score, text=match.text, grapheme_offset=match.offset, grapheme_length=match.length
600+
confidence_score=match.score,
601+
text=match.text,
602+
grapheme_offset=match.offset,
603+
grapheme_length=match.length
601604
)
602605

603606
def __repr__(self):
604-
return "LinkedEntityMatch(score={}, text={}, grapheme_offset={}, grapheme_length={})" \
605-
.format(self.score, self.text, self.grapheme_offset, self.grapheme_length)[:1024]
607+
return "LinkedEntityMatch(confidence_score={}, text={}, grapheme_offset={}, grapheme_length={})" \
608+
.format(self.confidence_score, self.text, self.grapheme_offset, self.grapheme_length)[:1024]
606609

607610

608611
class TextDocumentInput(MultiLanguageInput):

sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_recognize_entities_async.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async def recognize_entities_async(self):
4949
print("\nDocument text: {}".format(documents[idx]))
5050
for entity in doc.entities:
5151
print("Entity: \t", entity.text, "\tCategory: \t", entity.category,
52-
"\tConfidence Score: \t", entity.score)
52+
"\tConfidence Score: \t", entity.confidence_score)
5353
# [END batch_recognize_entities_async]
5454

5555

sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_recognize_linked_entities_async.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async def recognize_linked_entities_async(self):
5454
print("Url: {}".format(entity.url))
5555
print("Data Source: {}".format(entity.data_source))
5656
for match in entity.matches:
57-
print("Confidence Score: {}".format(match.score))
57+
print("Confidence Score: {}".format(match.confidence_score))
5858
print("Entity as appears in request: {}".format(match.text))
5959
print("------------------------------------------")
6060
# [END batch_recognize_linked_entities_async]

sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_recognize_pii_entities_async.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async def recognize_pii_entities_async(self):
5050
for entity in doc.entities:
5151
print("Entity: {}".format(entity.text))
5252
print("Category: {}".format(entity.category))
53-
print("Confidence Score: {}\n".format(entity.score))
53+
print("Confidence Score: {}\n".format(entity.confidence_score))
5454
# [END batch_recognize_pii_entities_async]
5555

5656

sdk/textanalytics/azure-ai-textanalytics/samples/sample_recognize_entities.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def recognize_entities(self):
4545
print("\nDocument text: {}".format(documents[idx]))
4646
for entity in doc.entities:
4747
print("Entity: \t", entity.text, "\tCategory: \t", entity.category,
48-
"\tConfidence Score: \t", entity.score)
48+
"\tConfidence Score: \t", entity.confidence_score)
4949
# [END batch_recognize_entities]
5050

5151

sdk/textanalytics/azure-ai-textanalytics/samples/sample_recognize_linked_entities.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def recognize_linked_entities(self):
5050
print("Url: {}".format(entity.url))
5151
print("Data Source: {}".format(entity.data_source))
5252
for match in entity.matches:
53-
print("Confidence Score: {}".format(match.score))
53+
print("Confidence Score: {}".format(match.confidence_score))
5454
print("Entity as appears in request: {}".format(match.text))
5555
print("------------------------------------------")
5656
# [END batch_recognize_linked_entities]

sdk/textanalytics/azure-ai-textanalytics/samples/sample_recognize_pii_entities.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def recognize_pii_entities(self):
4646
for entity in doc.entities:
4747
print("Entity: {}".format(entity.text))
4848
print("Category: {}".format(entity.category))
49-
print("Confidence Score: {}\n".format(entity.score))
49+
print("Confidence Score: {}\n".format(entity.confidence_score))
5050
# [END batch_recognize_pii_entities]
5151

5252

sdk/textanalytics/azure-ai-textanalytics/tests/test_recognize_entities.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_all_successful_passing_dict(self, resource_group, location, text_analyt
4343
self.assertIsNotNone(entity.category)
4444
self.assertIsNotNone(entity.grapheme_offset)
4545
self.assertIsNotNone(entity.grapheme_length)
46-
self.assertIsNotNone(entity.score)
46+
self.assertIsNotNone(entity.confidence_score)
4747

4848
@GlobalTextAnalyticsAccountPreparer()
4949
def test_all_successful_passing_text_document_input(self, resource_group, location, text_analytics_account, text_analytics_account_key):
@@ -63,7 +63,7 @@ def test_all_successful_passing_text_document_input(self, resource_group, locati
6363
self.assertIsNotNone(entity.category)
6464
self.assertIsNotNone(entity.grapheme_offset)
6565
self.assertIsNotNone(entity.grapheme_length)
66-
self.assertIsNotNone(entity.score)
66+
self.assertIsNotNone(entity.confidence_score)
6767

6868
@GlobalTextAnalyticsAccountPreparer()
6969
def test_passing_only_string(self, resource_group, location, text_analytics_account, text_analytics_account_key):

sdk/textanalytics/azure-ai-textanalytics/tests/test_recognize_entities_async.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async def test_all_successful_passing_dict(self, resource_group, location, text_
6060
self.assertIsNotNone(entity.category)
6161
self.assertIsNotNone(entity.grapheme_offset)
6262
self.assertIsNotNone(entity.grapheme_length)
63-
self.assertIsNotNone(entity.score)
63+
self.assertIsNotNone(entity.confidence_score)
6464

6565
@GlobalTextAnalyticsAccountPreparer()
6666
@AsyncTextAnalyticsTest.await_prepared_test
@@ -81,7 +81,7 @@ async def test_all_successful_passing_text_document_input(self, resource_group,
8181
self.assertIsNotNone(entity.category)
8282
self.assertIsNotNone(entity.grapheme_offset)
8383
self.assertIsNotNone(entity.grapheme_length)
84-
self.assertIsNotNone(entity.score)
84+
self.assertIsNotNone(entity.confidence_score)
8585

8686
@GlobalTextAnalyticsAccountPreparer()
8787
@AsyncTextAnalyticsTest.await_prepared_test

sdk/textanalytics/azure-ai-textanalytics/tests/test_recognize_pii_entities.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_all_successful_passing_dict(self, resource_group, location, text_analyt
4848
self.assertIsNotNone(entity.category)
4949
self.assertIsNotNone(entity.grapheme_offset)
5050
self.assertIsNotNone(entity.grapheme_length)
51-
self.assertIsNotNone(entity.score)
51+
self.assertIsNotNone(entity.confidence_score)
5252

5353
@GlobalTextAnalyticsAccountPreparer()
5454
def test_all_successful_passing_text_document_input(self, resource_group, location, text_analytics_account, text_analytics_account_key):
@@ -75,7 +75,7 @@ def test_all_successful_passing_text_document_input(self, resource_group, locati
7575
self.assertIsNotNone(entity.category)
7676
self.assertIsNotNone(entity.grapheme_offset)
7777
self.assertIsNotNone(entity.grapheme_length)
78-
self.assertIsNotNone(entity.score)
78+
self.assertIsNotNone(entity.confidence_score)
7979

8080
@GlobalTextAnalyticsAccountPreparer()
8181
def test_length_with_emoji(self, resource_group, location, text_analytics_account, text_analytics_account_key):

sdk/textanalytics/azure-ai-textanalytics/tests/test_recognize_pii_entities_async.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async def test_all_successful_passing_dict(self, resource_group, location, text_
6565
self.assertIsNotNone(entity.category)
6666
self.assertIsNotNone(entity.grapheme_offset)
6767
self.assertIsNotNone(entity.grapheme_length)
68-
self.assertIsNotNone(entity.score)
68+
self.assertIsNotNone(entity.confidence_score)
6969

7070
@GlobalTextAnalyticsAccountPreparer()
7171
@AsyncTextAnalyticsTest.await_prepared_test
@@ -93,7 +93,7 @@ async def test_all_successful_passing_text_document_input(self, resource_group,
9393
self.assertIsNotNone(entity.category)
9494
self.assertIsNotNone(entity.grapheme_offset)
9595
self.assertIsNotNone(entity.grapheme_length)
96-
self.assertIsNotNone(entity.score)
96+
self.assertIsNotNone(entity.confidence_score)
9797

9898
@GlobalTextAnalyticsAccountPreparer()
9999
@AsyncTextAnalyticsTest.await_prepared_test

sdk/textanalytics/azure-ai-textanalytics/tests/test_text_analytics.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ def test_repr(self):
3030
detected_language = _models.DetectedLanguage(name="English", iso6391_name="en", score=1.0)
3131

3232
categorized_entity = _models.CategorizedEntity(text="Bill Gates", category="Person", subcategory="Age",
33-
grapheme_offset=0, grapheme_length=8, score=0.899)
33+
grapheme_offset=0, grapheme_length=8, confidence_score=0.899)
3434

3535
pii_entity = _models.PiiEntity(text="555-55-5555", category="SSN", subcategory=None, grapheme_offset=0,
36-
grapheme_length=8, score=0.899)
36+
grapheme_length=8, confidence_score=0.899)
3737

3838
text_document_statistics = _models.TextDocumentStatistics(grapheme_count=14, transaction_count=18)
3939

@@ -69,7 +69,7 @@ def test_repr(self):
6969
id="1", key_phrases=["dog", "cat", "bird"], statistics=text_document_statistics, is_error=False
7070
)
7171

72-
linked_entity_match = _models.LinkedEntityMatch(score=0.999, text="Bill Gates", grapheme_offset=0,
72+
linked_entity_match = _models.LinkedEntityMatch(confidence_score=0.999, text="Bill Gates", grapheme_offset=0,
7373
grapheme_length=8)
7474

7575
linked_entity = _models.LinkedEntity(
@@ -120,18 +120,18 @@ def test_repr(self):
120120

121121
self.assertEqual("DetectedLanguage(name=English, iso6391_name=en, score=1.0)", repr(detected_language))
122122
self.assertEqual("CategorizedEntity(text=Bill Gates, category=Person, subcategory=Age, grapheme_offset=0, "
123-
"grapheme_length=8, score=0.899)",
123+
"grapheme_length=8, confidence_score=0.899)",
124124
repr(categorized_entity))
125125
self.assertEqual("PiiEntity(text=555-55-5555, category=SSN, subcategory=None, grapheme_offset=0, "
126-
"grapheme_length=8, score=0.899)", repr(pii_entity))
126+
"grapheme_length=8, confidence_score=0.899)", repr(pii_entity))
127127
self.assertEqual("TextDocumentStatistics(grapheme_count=14, transaction_count=18)",
128128
repr(text_document_statistics))
129129
self.assertEqual("RecognizeEntitiesResult(id=1, entities=[CategorizedEntity(text=Bill Gates, category=Person, "
130-
"subcategory=Age, grapheme_offset=0, grapheme_length=8, score=0.899)], "
130+
"subcategory=Age, grapheme_offset=0, grapheme_length=8, confidence_score=0.899)], "
131131
"statistics=TextDocumentStatistics(grapheme_count=14, transaction_count=18), "
132132
"is_error=False)", repr(recognize_entities_result))
133133
self.assertEqual("RecognizePiiEntitiesResult(id=1, entities=[PiiEntity(text=555-55-5555, category=SSN, "
134-
"subcategory=None, grapheme_offset=0, grapheme_length=8, score=0.899)], "
134+
"subcategory=None, grapheme_offset=0, grapheme_length=8, confidence_score=0.899)], "
135135
"statistics=TextDocumentStatistics(grapheme_count=14, transaction_count=18), "
136136
"is_error=False)", repr(recognize_pii_entities_result))
137137
self.assertEqual("DetectLanguageResult(id=1, primary_language=DetectedLanguage(name=English, "
@@ -142,15 +142,15 @@ def test_repr(self):
142142
self.assertEqual("ExtractKeyPhrasesResult(id=1, key_phrases=['dog', 'cat', 'bird'], statistics="
143143
"TextDocumentStatistics(grapheme_count=14, transaction_count=18), is_error=False)",
144144
repr(extract_key_phrases_result))
145-
self.assertEqual("LinkedEntityMatch(score=0.999, text=Bill Gates, grapheme_offset=0, grapheme_length=8)",
145+
self.assertEqual("LinkedEntityMatch(confidence_score=0.999, text=Bill Gates, grapheme_offset=0, grapheme_length=8)",
146146
repr(linked_entity_match))
147-
self.assertEqual("LinkedEntity(name=Bill Gates, matches=[LinkedEntityMatch(score=0.999, text=Bill Gates, "
148-
"grapheme_offset=0, grapheme_length=8), LinkedEntityMatch(score=0.999, text=Bill Gates, "
147+
self.assertEqual("LinkedEntity(name=Bill Gates, matches=[LinkedEntityMatch(confidence_score=0.999, text=Bill Gates, "
148+
"grapheme_offset=0, grapheme_length=8), LinkedEntityMatch(confidence_score=0.999, text=Bill Gates, "
149149
"grapheme_offset=0, grapheme_length=8)], language=English, data_source_entity_id=Bill Gates, "
150150
"url=https://en.wikipedia.org/wiki/Bill_Gates, data_source=wikipedia)", repr(linked_entity))
151151
self.assertEqual("RecognizeLinkedEntitiesResult(id=1, entities=[LinkedEntity(name=Bill Gates, "
152-
"matches=[LinkedEntityMatch(score=0.999, text=Bill Gates, grapheme_offset=0, "
153-
"grapheme_length=8), LinkedEntityMatch(score=0.999, text=Bill Gates, grapheme_offset=0, "
152+
"matches=[LinkedEntityMatch(confidence_score=0.999, text=Bill Gates, grapheme_offset=0, "
153+
"grapheme_length=8), LinkedEntityMatch(confidence_score=0.999, text=Bill Gates, grapheme_offset=0, "
154154
"grapheme_length=8)], language=English, data_source_entity_id=Bill Gates, "
155155
"url=https://en.wikipedia.org/wiki/Bill_Gates, data_source=wikipedia)], "
156156
"statistics=TextDocumentStatistics(grapheme_count=14, "

0 commit comments

Comments
 (0)