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

Add offset and length to SentenceSentiment #14599

Merged
merged 2 commits into from
Aug 31, 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
2 changes: 1 addition & 1 deletion sdk/textanalytics/azure-ai-textanalytics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Release History
## 5.1.0-beta.1 (Unreleased)
- Added `offset` and `length` properties for `CategorizedEntity` and `LinkedEntityMatch`.
- Added `offset` and `length` properties for `CategorizedEntity`, `LinkedEntityMatch` and `SentenceSentiment`
- `length` is the number of characters in the text of these models
- `offset` is the offset of the text from the start of the document

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@

import static com.azure.ai.textanalytics.TextAnalyticsAsyncClient.COGNITIVE_TRACING_NAMESPACE_VALUE;
import static com.azure.ai.textanalytics.implementation.Utility.inputDocumentsValidation;
import static com.azure.ai.textanalytics.implementation.Utility.mapToHttpResponseExceptionIfExist;
import static com.azure.ai.textanalytics.implementation.Utility.toBatchStatistics;
import static com.azure.ai.textanalytics.implementation.Utility.toMultiLanguageInput;
import static com.azure.ai.textanalytics.implementation.Utility.toTextAnalyticsError;
Expand Down Expand Up @@ -160,9 +159,11 @@ private AnalyzeSentimentResult convertToAnalyzeSentimentResult(DocumentSentiment
final SentenceSentimentValue sentenceSentimentValue = sentenceSentiment.getSentiment();
return new SentenceSentiment(sentenceSentiment.getText(),
TextSentiment.fromString(sentenceSentimentValue == null ? null : sentenceSentimentValue.toString()),
toMinedOpinionList(sentenceSentiment, documentSentimentList),
new SentimentConfidenceScores(confidenceScorePerSentence.getNegative(),
confidenceScorePerSentence.getNeutral(), confidenceScorePerSentence.getPositive())
confidenceScorePerSentence.getNeutral(), confidenceScorePerSentence.getPositive()),
toMinedOpinionList(sentenceSentiment, documentSentimentList),
sentenceSentiment.getOffset(),
sentenceSentiment.getLength()
);
}).collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private IterableStream<LinkedEntity> mapLinkedEntity(
linkedEntitiesList.add(new LinkedEntity(
linkedEntity.getName(),
new IterableStream<>(linkedEntity.getMatches().stream().map(match -> new LinkedEntityMatch(
match.getText(), match.getOffset(), match.getLength(), match.getConfidenceScore()))
match.getText(), match.getConfidenceScore(), match.getOffset(), match.getLength()))
.collect(Collectors.toList())),
linkedEntity.getLanguage(),
linkedEntity.getId(), linkedEntity.getUrl(), linkedEntity.getDataSource()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,21 @@
*/
@Immutable
public final class CategorizedEntity {
/*
* CategorizedEntity text as appears in the request.
*/
private final String text;

/*
* CategorizedEntity category, such as Person/Location/Org/SSN etc.
*/
private final EntityCategory category;

/*
* CategorizedEntity sub category, such as Age/Year/TimeRange etc.
*/
private final String subcategory;

/*
* Start position for the entity text.
*/
private final double confidenceScore;
mssfang marked this conversation as resolved.
Show resolved Hide resolved
private final int offset;

/*
* Length for the entity text.
*/
private final int length;

/*
* Confidence score between 0 and 1 of the extracted entity.
*/
private final double confidenceScore;

/**
* Creates a {@link CategorizedEntity} model that describes entity.
*
* @param text The entity text as appears in the request.
* @param category The entity category, such as Person/Location/Org/SSN etc.
* @param subcategory The entity subcategory, such as Age/Year/TimeRange etc.
* @param confidenceScore A confidence score between 0 and 1 of the extracted entity.
* @param confidenceScore If a well-known item is recognized, a decimal number denoting the confidence level
* between 0 and 1 will be returned.
*/
public CategorizedEntity(String text, EntityCategory category, String subcategory, double confidenceScore) {
this.text = text;
Expand All @@ -59,10 +37,12 @@ public CategorizedEntity(String text, EntityCategory category, String subcategor

/**
* Creates a {@link CategorizedEntity} model that describes entity.
*
* @param text The entity text as appears in the request.
* @param category The entity category, such as Person/Location/Org/SSN etc.
* @param subcategory The entity subcategory, such as Age/Year/TimeRange etc.
* @param confidenceScore A confidence score between 0 and 1 of the extracted entity.
* @param confidenceScore If a well-known item is recognized, a decimal number denoting the confidence level
* between 0 and 1 will be returned.
* @param offset The start position for the entity text.
* @param length The length for the entity text.
*/
Expand Down Expand Up @@ -104,7 +84,17 @@ public String getSubcategory() {
}

/**
* Get the offset of entity text.
* Get the score property: If a well-known item is recognized, a decimal
* number denoting the confidence level between 0 and 1 will be returned.
*
* @return The score value.
*/
public double getConfidenceScore() {
return this.confidenceScore;
}

/**
* Get the offset of entity text. The start position for the entity text in a document.
mssfang marked this conversation as resolved.
Show resolved Hide resolved
*
* @return The offset of entity text.
*/
Expand All @@ -120,13 +110,4 @@ public int getOffset() {
public int getLength() {
return length;
}

/**
* Get the score property: Confidence score between 0 and 1 of the extracted entity.
*
* @return The score value.
*/
public double getConfidenceScore() {
return this.confidenceScore;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,15 @@
*/
@Immutable
public final class LinkedEntityMatch {
/*
* If a well-known item is recognized, a decimal number denoting the
* confidence level between 0 and 1 will be returned.
*/
private final double confidenceScore;

/*
* Linked entity match text as appears in the request.
*/
private final String text;

/*
* Start position for the linked entity match text.
*/
private final double confidenceScore;
private final int offset;

/*
* Length for the linked entity match text.
*/
private final int length;

/**
* Creates a {@link LinkedEntityMatch} model that describes linked entity match.
*
* @param text The entity text as appears in the request.
* @param text The linked entity match text as appears in the request.
* @param confidenceScore If a well-known item is recognized, a decimal number denoting the
* confidence level between 0 and 1 will be returned.
*/
Expand All @@ -48,40 +32,40 @@ public LinkedEntityMatch(String text, double confidenceScore) {
/**
* Creates a {@link LinkedEntityMatch} model that describes linked entity match.
*
* @param text The entity text as appears in the request.
* @param offset The start position for the entity text.
* @param length The length for the entity text.
* @param text The linked entity match text as appears in the request.
* @param confidenceScore If a well-known item is recognized, a decimal number denoting the
* confidence level between 0 and 1 will be returned.
* @param offset The start position for the linked entity match text in a document.
* @param length The length of linked entity match text.
*/
public LinkedEntityMatch(String text, int offset, int length, double confidenceScore) {
public LinkedEntityMatch(String text, double confidenceScore, int offset, int length) {
this.text = text;
this.offset = offset;
this.length = length;
this.confidenceScore = confidenceScore;
}

/**
* Get the score property: If a well-known item is recognized, a decimal
* number denoting the confidence level between 0 and 1 will be returned.
* Get the linked entity match text property: linked entity text as appears in the request.
*
* @return The score value.
* @return The text value.
*/
public double getConfidenceScore() {
return this.confidenceScore;
public String getText() {
return this.text;
}

/**
* Get the linked entity match text property: Entity text as appears in the request.
* Get the score property: If a well-known item is recognized, a decimal
* number denoting the confidence level between 0 and 1 will be returned.
*
* @return The text value.
* @return The score value.
*/
public String getText() {
return this.text;
public double getConfidenceScore() {
return this.confidenceScore;
}

/**
* Get the offset of linked entity match text.
* Get the offset of linked entity match text. The start position for the linked entity match text in a document.
*
* @return The offset of linked entity match text.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public PiiEntity(String text, EntityCategory category, String subcategory, doubl
this.text = text;
this.category = category;
this.subcategory = subcategory;
this.confidenceScore = confidenceScore;
this.offset = offset;
this.length = length;
this.confidenceScore = confidenceScore;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,61 @@
import com.azure.core.util.IterableStream;

/**
* The {@link SentenceSentiment} model that contains a sentiment label of a sentence, confidence score of the
* sentiment label, length of the sentence and offset of the sentence within a document.
* The {@link SentenceSentiment} model that contains a sentiment label of a sentence, confidence scores of the
* sentiment label, mined opinions, offset of sentence, and length of sentence within a document.
*/
@Immutable
public final class SentenceSentiment {
private final String text;
private final SentimentConfidenceScores confidenceScores;
private final TextSentiment sentiment;
private final SentimentConfidenceScores confidenceScores;
private final IterableStream<MinedOpinion> minedOpinions;
private final int offset;
private final int length;

/**
* Creates a {@link SentenceSentiment} model that describes the sentiment analysis of sentence.
*
* @param text The sentence text.
* @param sentiment The sentiment label of the sentence.
* @param confidenceScores The sentiment confidence score (Softmax score) between 0 and 1, for each sentiment label.
* Higher values signify higher confidence.
* Higher values signify higher confidence.
*/
public SentenceSentiment(String text, TextSentiment sentiment, SentimentConfidenceScores confidenceScores) {
this.text = text;
this.sentiment = sentiment;
this.minedOpinions = null;
this.confidenceScores = confidenceScores;
this.minedOpinions = null;
this.offset = 0;
this.length = 0;
Comment on lines +35 to +36
Copy link
Member

Choose a reason for hiding this comment

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

These initializations are only on SentenceSentiment and not on LinkedEntityMatch or CategorizedEntity ?

Copy link
Member Author

Choose a reason for hiding this comment

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

}

/**
* Creates a {@link SentenceSentiment} model that describes the sentiment analysis of sentence.
*
* @param text The sentence text.
* @param sentiment The sentiment label of the sentence.
* @param confidenceScores The sentiment confidence score (Softmax score) between 0 and 1, for each sentiment label.
* Higher values signify higher confidence.
* @param minedOpinions The mined opinions of the sentence sentiment. This is only returned if you pass the
* opinion mining parameter to the analyze sentiment APIs.
* @param confidenceScores The sentiment confidence score (Softmax score) between 0 and 1, for each sentiment label.
* Higher values signify higher confidence.
* @param offset The start position for the sentence in a document.
* @param length The length of sentence.
*/
public SentenceSentiment(String text, TextSentiment sentiment, IterableStream<MinedOpinion> minedOpinions,
SentimentConfidenceScores confidenceScores) {
public SentenceSentiment(String text, TextSentiment sentiment, SentimentConfidenceScores confidenceScores,
IterableStream<MinedOpinion> minedOpinions, int offset, int length) {
this.text = text;
this.sentiment = sentiment;
this.minedOpinions = minedOpinions;
this.confidenceScores = confidenceScores;
this.offset = offset;
this.length = length;
}

/**
* Get the sentence text property.
*
* @return the text property value.
* @return The text property value.
*/
public String getText() {
return this.text;
Expand All @@ -66,6 +76,16 @@ public TextSentiment getSentiment() {
return sentiment;
}

/**
* Get the confidence score of the sentiment label. All score values sum up to 1, the higher the score, the
* higher the confidence in the sentiment.
*
* @return The {@link SentimentConfidenceScores}.
*/
public SentimentConfidenceScores getConfidenceScores() {
return confidenceScores;
}

/**
* Get the mined opinions of sentence sentiment.
* This is only returned if you pass the opinion mining parameter to the analyze sentiment APIs.
Expand All @@ -77,12 +97,20 @@ public IterableStream<MinedOpinion> getMinedOpinions() {
}

/**
* Get the confidence score of the sentiment label. All score values sum up to 1, the higher the score, the
* higher the confidence in the sentiment.
* Get the offset of sentence. The start position for the sentence in a document.
*
* @return The {@link SentimentConfidenceScores}.
* @return The offset of sentence.
Copy link
Member

Choose a reason for hiding this comment

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

nit: Consider updating to start position for the sentence in a document.

Copy link
Member Author

Choose a reason for hiding this comment

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

I feel it is too redundant for having it both in the method description and the return value.

*/
public SentimentConfidenceScores getConfidenceScores() {
return confidenceScores;
public int getOffset() {
return offset;
}

/**
* Get the length of sentence.
*
* @return The length of sentence.
*/
public int getLength() {
return length;
mssfang marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading