Skip to content

Commit 7dea4c7

Browse files
author
Li Xu
authored
WS-1220: add salience option (#107)
* WS-1220: add salience option * WS-1220: checkstyle * WS-1220: checkstyle again
1 parent 750aff4 commit 7dea4c7

File tree

6 files changed

+136
-14
lines changed

6 files changed

+136
-14
lines changed

json/src/main/java/com/basistech/rosette/apimodel/jackson/EntitiesOptionsMixin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public final class EntitiesOptionsMixin extends OptionsMixin {
2525
@JsonCreator
2626
private EntitiesOptionsMixin(
2727
@JsonProperty("calculateConfidence") Boolean calculateConfidence,
28+
@JsonProperty("calculateSalience") Boolean calculateSalience,
2829
@JsonProperty("linkEntities") Boolean linkEntities
2930
) {
3031
//

json/src/main/java/com/basistech/rosette/apimodel/jackson/SentimentOptionsMixin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
public abstract class SentimentOptionsMixin extends OptionsMixin {
2525
@JsonCreator
2626
protected SentimentOptionsMixin(
27-
@JsonProperty("calculateEntityConfidence") Boolean calculateEntityConfidence
27+
@JsonProperty("calculateEntityConfidence") Boolean calculateEntityConfidence,
28+
@JsonProperty("calculateEntitySalience") Boolean calculateEntitySalience
2829
) {
2930
//
3031
}

model/src/main/java/com/basistech/rosette/apimodel/EntitiesOptions.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
*/
2424
public final class EntitiesOptions extends Options {
2525

26-
public static final EntitiesOptions DEFAULT_OPTIONS = new EntitiesOptions(false, true);
26+
public static final EntitiesOptions DEFAULT_OPTIONS = new EntitiesOptions(false, false, true);
2727
private Boolean calculateConfidence;
28+
private Boolean calculateSalience;
2829
private Boolean linkEntities;
2930

3031
/**
@@ -33,8 +34,9 @@ public final class EntitiesOptions extends Options {
3334
* @param calculateConfidence return confidence score for the extraction.
3435
* @param linkEntities perform entity linking in addition to extraction.
3536
*/
36-
protected EntitiesOptions(Boolean calculateConfidence, Boolean linkEntities) {
37+
protected EntitiesOptions(Boolean calculateConfidence, Boolean calculateSalience, Boolean linkEntities) {
3738
this.calculateConfidence = calculateConfidence;
39+
this.calculateSalience = calculateSalience;
3840
this.linkEntities = linkEntities;
3941
}
4042

@@ -52,6 +54,13 @@ public Boolean getCalculateConfidence() {
5254
return calculateConfidence;
5355
}
5456

57+
/**
58+
* @return the calculateSalience flag.
59+
*/
60+
public Boolean getCalculateSalience() {
61+
return calculateSalience;
62+
}
63+
5564
@Override
5665
public boolean equals(Object o) {
5766
if (this == o) {
@@ -62,16 +71,18 @@ public boolean equals(Object o) {
6271
}
6372
EntitiesOptions that = (EntitiesOptions) o;
6473
return Objects.equals(linkEntities, that.linkEntities)
65-
&& Objects.equals(calculateConfidence, that.calculateConfidence);
74+
&& Objects.equals(calculateConfidence, that.calculateConfidence)
75+
&& Objects.equals(calculateSalience, that.calculateSalience);
6676
}
6777

6878
@Override
6979
public int hashCode() {
70-
return Objects.hash(calculateConfidence, linkEntities);
80+
return Objects.hash(calculateConfidence, calculateSalience, linkEntities);
7181
}
7282

7383
public static class Builder {
7484
private Boolean calculateConfidence;
85+
private Boolean calculateSalience;
7586
private Boolean linkEntities;
7687

7788
public Builder() {
@@ -89,6 +100,17 @@ public Builder calculateConfidence(Boolean calculateConfidence) {
89100
return this;
90101
}
91102

103+
/**
104+
* DocumentRequest calculate salience score. If the value is {@code true}, then the endpoint will
105+
* return salience scores. If {@code false} or {@code null}, not.
106+
* @param calculateSalience whether to get salience score.
107+
* @return this.
108+
*/
109+
public Builder calculateSalience(Boolean calculateSalience) {
110+
this.calculateSalience = calculateSalience;
111+
return this;
112+
}
113+
92114
/**
93115
* DocumentRequest entity linking. If the value is {@code true}, then the the endpoint will link entities to the
94116
* knowledge base. If {@code false}, not. If {@code null}, the endpoint will perform default processing.
@@ -101,7 +123,7 @@ public Builder linkEntities(Boolean linkEntities) {
101123
}
102124

103125
public EntitiesOptions build() {
104-
return new EntitiesOptions(calculateConfidence, linkEntities);
126+
return new EntitiesOptions(calculateConfidence, calculateSalience, linkEntities);
105127
}
106128
}
107129
}

model/src/main/java/com/basistech/rosette/apimodel/EntityMention.java

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public final class EntityMention {
3131
private final Integer count;
3232
private final String entityId;
3333
private final Double confidence;
34+
private final Double salience;
3435

3536
/**
3637
* constructor for {@code EntityMention}
@@ -40,6 +41,7 @@ public final class EntityMention {
4041
* @param normalized normalized mention text
4142
* @param count mention count
4243
* @param entityId if the entity was linked, the ID from the knowledge base.
44+
* @param confidence entity confidence
4345
*/
4446
@Deprecated
4547
public EntityMention(
@@ -58,6 +60,7 @@ public EntityMention(
5860
this.count = count;
5961
this.entityId = entityId;
6062
this.confidence = confidence;
63+
this.salience = null;
6164
}
6265

6366
/**
@@ -67,6 +70,7 @@ public EntityMention(
6770
* @param normalized normalized mention text
6871
* @param entityId if the entity was linked, the ID from the knowledge base.
6972
* @param count mention count
73+
* @param confidence entity confidence
7074
*/
7175
public EntityMention(
7276
String type,
@@ -83,6 +87,36 @@ public EntityMention(
8387
this.entityId = entityId;
8488
this.count = count;
8589
this.confidence = confidence;
90+
this.salience = null;
91+
}
92+
93+
/**
94+
* constructor for {@code EntityMention}
95+
* @param type entity type
96+
* @param mention mention text
97+
* @param normalized normalized mention text
98+
* @param entityId if the entity was linked, the ID from the knowledge base.
99+
* @param count mention count
100+
* @param confidence entity confidence
101+
* @param salience entity salience
102+
*/
103+
public EntityMention(
104+
String type,
105+
String mention,
106+
String normalized,
107+
String entityId,
108+
Integer count,
109+
Double confidence,
110+
Double salience
111+
) {
112+
this.indocChainId = null;
113+
this.type = type;
114+
this.mention = mention;
115+
this.normalized = normalized;
116+
this.entityId = entityId;
117+
this.count = count;
118+
this.confidence = confidence;
119+
this.salience = salience;
86120
}
87121

88122
/**
@@ -144,6 +178,14 @@ public Double getConfidence() {
144178
return confidence;
145179
}
146180

181+
/**
182+
* get the salience score for the entity.
183+
* @return the salience score (0.0-1.0)
184+
*/
185+
public Double getSalience() {
186+
return salience;
187+
}
188+
147189
@Override
148190
public boolean equals(Object o) {
149191
if (this == o) {
@@ -159,11 +201,12 @@ public boolean equals(Object o) {
159201
&& Objects.equals(normalized, that.normalized)
160202
&& Objects.equals(count, that.count)
161203
&& Objects.equals(entityId, that.entityId)
162-
&& Objects.equals(confidence, that.confidence);
204+
&& Objects.equals(confidence, that.confidence)
205+
&& Objects.equals(salience, that.salience);
163206
}
164207

165208
@Override
166209
public int hashCode() {
167-
return Objects.hash(indocChainId, type, mention, normalized, count, entityId, confidence);
210+
return Objects.hash(indocChainId, type, mention, normalized, count, entityId, confidence, salience);
168211
}
169212
}

model/src/main/java/com/basistech/rosette/apimodel/EntitySentiment.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public final class EntitySentiment {
2929
private final Integer count;
3030
private final String entityId;
3131
private final Double confidence;
32+
private final Double salience;
3233
private final Label sentiment;
3334

3435
/**
@@ -48,12 +49,35 @@ public EntitySentiment(String type,
4849
String entityId,
4950
Double confidence,
5051
Label sentiment) {
52+
this(type, mention, normalized, count, entityId, confidence, null, sentiment);
53+
}
54+
55+
/**
56+
* constructor for {@code EntitySentiment}
57+
* @param type entity type
58+
* @param mention mention text
59+
* @param normalized normalized mention text
60+
* @param count mention count
61+
* @param entityId if the entity was linked, the ID from the knowledge base.
62+
* @param confidence entity confidence.
63+
* @param salience entity salience.
64+
* @param sentiment the sentiment information.
65+
*/
66+
public EntitySentiment(String type,
67+
String mention,
68+
String normalized,
69+
Integer count,
70+
String entityId,
71+
Double confidence,
72+
Double salience,
73+
Label sentiment) {
5174
this.type = type;
5275
this.mention = mention;
5376
this.normalized = normalized;
5477
this.count = count;
5578
this.entityId = entityId;
5679
this.confidence = confidence;
80+
this.salience = salience;
5781
this.sentiment = sentiment;
5882
}
5983

@@ -107,6 +131,14 @@ public Double getConfidence() {
107131
return confidence;
108132
}
109133

134+
/**
135+
* get the entity salience
136+
* @return the entity salience
137+
*/
138+
public Double getSalience() {
139+
return salience;
140+
}
141+
110142
/**
111143
* @return the sentiment information.
112144
*/
@@ -129,11 +161,12 @@ public boolean equals(Object o) {
129161
&& Objects.equals(count, that.count)
130162
&& Objects.equals(entityId, that.entityId)
131163
&& Objects.equals(confidence, that.confidence)
164+
&& Objects.equals(salience, that.salience)
132165
&& Objects.equals(sentiment, that.sentiment);
133166
}
134167

135168
@Override
136169
public int hashCode() {
137-
return Objects.hash(type, mention, normalized, count, entityId, confidence, sentiment);
170+
return Objects.hash(type, mention, normalized, count, entityId, confidence, salience, sentiment);
138171
}
139172
}

model/src/main/java/com/basistech/rosette/apimodel/SentimentOptions.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@
2222
* Sentiment options.
2323
*/
2424
public final class SentimentOptions extends Options {
25-
public static final SentimentOptions DEGAULT_OPTIONS = new SentimentOptions(false);
25+
public static final SentimentOptions DEGAULT_OPTIONS = new SentimentOptions(false, false);
2626
private Boolean calculateEntityConfidence;
27+
private Boolean calculateEntitySalience;
2728

2829
/**
2930
* Constructor for {@code SentimentOptions}
3031
*
3132
* @param calculateEntityConfidence return confidence score for the entities.
3233
*/
33-
protected SentimentOptions(Boolean calculateEntityConfidence) {
34+
protected SentimentOptions(Boolean calculateEntityConfidence, Boolean calculateEntitySalience) {
3435
this.calculateEntityConfidence = calculateEntityConfidence;
36+
this.calculateEntitySalience = calculateEntitySalience;
3537
}
3638

3739
/**
@@ -41,6 +43,13 @@ public Boolean getCalculateEntityConfidence() {
4143
return calculateEntityConfidence;
4244
}
4345

46+
/**
47+
* @return the calculateEntitySalience flag.
48+
*/
49+
public Boolean getCalculateEntitySalience() {
50+
return calculateEntitySalience;
51+
}
52+
4453
@Override
4554
public boolean equals(Object o) {
4655
if (this == o) {
@@ -50,16 +59,18 @@ public boolean equals(Object o) {
5059
return false;
5160
}
5261
SentimentOptions that = (SentimentOptions)o;
53-
return Objects.equals(this.calculateEntityConfidence, that.calculateEntityConfidence);
62+
return Objects.equals(this.calculateEntityConfidence, that.calculateEntityConfidence)
63+
&& Objects.equals(this.calculateEntitySalience, that.calculateEntitySalience);
5464
}
5565

5666
@Override
5767
public int hashCode() {
58-
return Objects.hash(calculateEntityConfidence);
68+
return Objects.hash(calculateEntityConfidence, calculateEntitySalience);
5969
}
6070

6171
public static class Builder {
6272
private Boolean calculateEntityConfidence;
73+
private Boolean calculateEntitySalience;
6374

6475
/**
6576
* DocumentRequest calculate entity confidence score. If the value is {@code true}, then the endpoint will
@@ -72,8 +83,19 @@ public Builder calculateEntityConfidence(Boolean calculateEntityConfidence) {
7283
return this;
7384
}
7485

86+
/**
87+
* DocumentRequest calculate entity salience score. If the value is {@code true}, then the endpoint will
88+
* return salience scores. If {@code false} or {@code null}, not.
89+
* @param calculateEntitySalience whether to get entity salience score.
90+
* @return this.
91+
*/
92+
public Builder calculateEntitySalience(Boolean calculateEntitySalience) {
93+
this.calculateEntitySalience = calculateEntitySalience;
94+
return this;
95+
}
96+
7597
public SentimentOptions build() {
76-
return new SentimentOptions(calculateEntityConfidence);
98+
return new SentimentOptions(calculateEntityConfidence, calculateEntitySalience);
7799
}
78100
}
79101
}

0 commit comments

Comments
 (0)