Skip to content

Commit 4af8f0c

Browse files
authored
Merge pull request #107149 from suhas92/patch-29
[Cog Svcs] Update Text Analytics Java Quickstarts with preview.3
2 parents ffe802b + c0cca2b commit 4af8f0c

File tree

1 file changed

+40
-44
lines changed
  • articles/cognitive-services/text-analytics/includes/quickstarts

1 file changed

+40
-44
lines changed

articles/cognitive-services/text-analytics/includes/quickstarts/java-sdk.md

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.subservice: text-analytics
88
ms.topic: include
99
ms.date: 02/26/2020
1010
ms.author: aahi
11-
ms.reviewer: tasharm, assafi
11+
ms.reviewer: tasharm, assafi, sumeh
1212
---
1313

1414
<a name="HOLTop"></a>
@@ -34,7 +34,7 @@ Add the following text analytics dependency to your project. This version of the
3434
<dependency>
3535
<groupId>com.azure</groupId>
3636
<artifactId>azure-ai-textanalytics</artifactId>
37-
<version>1.0.0-beta.2</version>
37+
<version>1.0.0-beta.3</version>
3838
</dependency>
3939
</dependencies>
4040
```
@@ -115,31 +115,32 @@ static void sentimentAnalysisExample(TextAnalyticsClient client)
115115
String text = "I had the best day of my life. I wish you were there with me.";
116116

117117
DocumentSentiment documentSentiment = client.analyzeSentiment(text);
118+
System.out.printf(
119+
"Recognized document sentiment: %s, positive score: %s, neutral score: %s, negative score: %s.%n",
120+
documentSentiment.getSentiment(),
121+
documentSentiment.getConfidenceScores().getPositive(),
122+
documentSentiment.getConfidenceScores().getNeutral(),
123+
documentSentiment.getConfidenceScores().getNegative());
124+
125+
for (SentenceSentiment sentenceSentiment : documentSentiment.getSentences()) {
118126
System.out.printf(
119-
"Recognized document sentiment: %s, positive score: %.2f, neutral score: %.2f, negative score: %.2f.%n",
120-
documentSentiment.getSentiment(),
121-
documentSentiment.getSentimentScores().getPositive(),
122-
documentSentiment.getSentimentScores().getNeutral(),
123-
documentSentiment.getSentimentScores().getNegative());
124-
125-
for (SentenceSentiment sentenceSentiment : documentSentiment.getSentences()) {
126-
System.out.printf(
127-
"Recognized sentence sentiment: %s, positive score: %.2f, neutral score: %.2f, negative score: %.2f.%n",
128-
sentenceSentiment.getSentiment(),
129-
sentenceSentiment.getSentimentScores().getPositive(),
130-
sentenceSentiment.getSentimentScores().getNeutral(),
131-
sentenceSentiment.getSentimentScores().getNegative());
132-
}
127+
"Recognized sentence sentiment: %s, positive score: %s, neutral score: %s, negative score: %s.%n",
128+
sentenceSentiment.getSentiment(),
129+
sentenceSentiment.getConfidenceScores().getPositive(),
130+
sentenceSentiment.getConfidenceScores().getNeutral(),
131+
sentenceSentiment.getConfidenceScores().getNegative());
132+
}
133133
}
134134
```
135135

136136
### Output
137137

138138
```console
139-
Recognized document sentiment: positive, Positive Score: 1.00, Neutral Score: 0.00, Negative Score: 0.00.
140-
Recognized sentence sentiment: positive, positive score: 1.00, neutral score: 0.00, negative score: 0.00.
139+
Recognized document sentiment: positive, positive score: 1.0, neutral score: 0.0, negative score: 0.0.
140+
Recognized sentence sentiment: positive, positive score: 1.0, neutral score: 0.0, negative score: 0.0.
141141
Recognized sentence sentiment: neutral, positive score: 0.21, neutral score: 0.77, negative score: 0.02.
142142
```
143+
143144
## Language detection
144145

145146
Create a new function called `detectLanguageExample()` that takes the client that you created earlier, and call its `detectLanguage()` function. The returned `DetectLanguageResult` object will contain a primary language detected, a list of other languages detected if successful, or an `errorMessage` if not.
@@ -183,22 +184,20 @@ static void recognizeEntitiesExample(TextAnalyticsClient client)
183184

184185
for (CategorizedEntity entity : client.recognizeEntities(text)) {
185186
System.out.printf(
186-
"Recognized entity: %s, entity category: %s, entity sub-category: %s, offset: %s, length: %s, score: %.2f.%n",
187+
"Recognized entity: %s, entity category: %s, entity sub-category: %s, score: %s.%n",
187188
entity.getText(),
188189
entity.getCategory(),
189-
entity.getSubCategory() == null || entity.getSubCategory().isEmpty() ? "N/A" : entity.getSubCategory(),
190-
entity.getOffset(),
191-
entity.getLength(),
192-
entity.getScore());
190+
entity.getSubCategory(),
191+
entity.getConfidenceScore());
193192
}
194193
}
195194
```
196195

197196
### Output
198197

199198
```console
200-
Recognized entity: Seattle, entity category: Location, entity sub-category: GPE, offset: 26, length: 7, score: 0.92.
201-
Recognized entity: last week, entity category: DateTime, entity sub-category: DateRange, offset: 34, length: 9, score: 0.80.
199+
Recognized entity: Seattle, entity category: Location, entity sub-category: GPE, score: 0.92.
200+
Recognized entity: last week, entity category: DateTime, entity sub-category: DateRange, score: 0.8.
202201
```
203202

204203
## Using NER to recognize personal information
@@ -213,21 +212,20 @@ static void recognizePIIEntitiesExample(TextAnalyticsClient client)
213212

214213
for (PiiEntity entity : client.recognizePiiEntities(text)) {
215214
System.out.printf(
216-
"Recognized personal identifiable information entity: %s, entity category: %s, entity sub-category: %s, offset: %s, length: %s, score: %.2f.%n",
215+
"Recognized personal identifiable information entity: %s, entity category: %s, %nentity sub-category: %s, score: %s.%n",
217216
entity.getText(),
218217
entity.getCategory(),
219-
entity.getSubCategory() == null || entity.getSubCategory().isEmpty() ? "N/A" : entity.getSubCategory(),
220-
entity.getOffset(),
221-
entity.getLength(),
222-
entity.getScore());
218+
entity.getSubCategory(),
219+
entity.getConfidenceScore());
223220
}
224221
}
225222
```
226223

227224
### Output
228225

229226
```console
230-
Recognized personal identifiable information entity: 123-12-1234, entity category: U.S. Social Security Number (SSN), entity sub-category: N/A, offset: 33, length: 11, score: 0.85.
227+
Recognized personal identifiable information entity: 123-12-1234, entity category: U.S. Social Security Number (SSN),
228+
entity sub-category: null, score: 0.85.
231229
```
232230

233231
## Entity linking
@@ -248,16 +246,14 @@ static void recognizeLinkedEntitiesExample(TextAnalyticsClient client)
248246
for (LinkedEntity linkedEntity : client.recognizeLinkedEntities(text)) {
249247
System.out.printf("Name: %s, ID: %s, URL: %s, Data Source: %s.%n",
250248
linkedEntity.getName(),
251-
linkedEntity.getId(),
249+
linkedEntity.getDataSourceEntityId(),
252250
linkedEntity.getUrl(),
253251
linkedEntity.getDataSource());
254252
System.out.printf("Matches:%n");
255253
for (LinkedEntityMatch linkedEntityMatch : linkedEntity.getLinkedEntityMatches()) {
256-
System.out.printf("Text: %s, Offset: %s, Length: %s, Score: %.2f.%n",
254+
System.out.printf("Text: %s, Score: %.2f%n",
257255
linkedEntityMatch.getText(),
258-
linkedEntityMatch.getOffset(),
259-
linkedEntityMatch.getLength(),
260-
linkedEntityMatch.getScore());
256+
linkedEntityMatch.getConfidenceScore());
261257
}
262258
}
263259
}
@@ -269,24 +265,24 @@ static void recognizeLinkedEntitiesExample(TextAnalyticsClient client)
269265
Linked Entities:
270266
Name: Altair 8800, ID: Altair 8800, URL: https://en.wikipedia.org/wiki/Altair_8800, Data Source: Wikipedia.
271267
Matches:
272-
Text: Altair 8800, Offset: 11, Length: 116, Score: 0.78.
268+
Text: Altair 8800, Score: 0.78
273269
Name: Bill Gates, ID: Bill Gates, URL: https://en.wikipedia.org/wiki/Bill_Gates, Data Source: Wikipedia.
274270
Matches:
275-
Text: Bill Gates, Offset: 10, Length: 25, Score: 0.55.
276-
Text: Gates, Offset: 5, Length: 161, Score: 0.55.
271+
Text: Bill Gates, Score: 0.55
272+
Text: Gates, Score: 0.55
277273
Name: Paul Allen, ID: Paul Allen, URL: https://en.wikipedia.org/wiki/Paul_Allen, Data Source: Wikipedia.
278274
Matches:
279-
Text: Paul Allen, Offset: 10, Length: 40, Score: 0.53.
275+
Text: Paul Allen, Score: 0.53
280276
Name: Microsoft, ID: Microsoft, URL: https://en.wikipedia.org/wiki/Microsoft, Data Source: Wikipedia.
281277
Matches:
282-
Text: Microsoft, Offset: 9, Length: 0, Score: 0.47.
283-
Text: Microsoft, Offset: 9, Length: 150, Score: 0.47.
278+
Text: Microsoft, Score: 0.47
279+
Text: Microsoft, Score: 0.47
284280
Name: April 4, ID: April 4, URL: https://en.wikipedia.org/wiki/April_4, Data Source: Wikipedia.
285281
Matches:
286-
Text: April 4, Offset: 7, Length: 54, Score: 0.25.
282+
Text: April 4, Score: 0.25
287283
Name: BASIC, ID: BASIC, URL: https://en.wikipedia.org/wiki/BASIC, Data Source: Wikipedia.
288284
Matches:
289-
Text: BASIC, Offset: 5, Length: 89, Score: 0.28.
285+
Text: BASIC, Score: 0.28
290286
```
291287
## Key phrase extraction
292288

0 commit comments

Comments
 (0)