|
@@ -20,7 +20,7 @@ import java.util.Map;
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
-public class NerResults implements InferenceResults {
|
|
|
|
|
|
+public class NerResults extends NlpInferenceResults {
|
|
|
|
|
|
public static final String NAME = "ner_result";
|
|
public static final String NAME = "ner_result";
|
|
public static final String ENTITY_FIELD = "entities";
|
|
public static final String ENTITY_FIELD = "entities";
|
|
@@ -30,27 +30,28 @@ public class NerResults implements InferenceResults {
|
|
|
|
|
|
private final List<EntityGroup> entityGroups;
|
|
private final List<EntityGroup> entityGroups;
|
|
|
|
|
|
- public NerResults(String resultsField, String annotatedResult, List<EntityGroup> entityGroups) {
|
|
|
|
|
|
+ public NerResults(String resultsField, String annotatedResult, List<EntityGroup> entityGroups, boolean isTruncated) {
|
|
|
|
+ super(isTruncated);
|
|
this.entityGroups = Objects.requireNonNull(entityGroups);
|
|
this.entityGroups = Objects.requireNonNull(entityGroups);
|
|
this.resultsField = Objects.requireNonNull(resultsField);
|
|
this.resultsField = Objects.requireNonNull(resultsField);
|
|
this.annotatedResult = Objects.requireNonNull(annotatedResult);
|
|
this.annotatedResult = Objects.requireNonNull(annotatedResult);
|
|
}
|
|
}
|
|
|
|
|
|
public NerResults(StreamInput in) throws IOException {
|
|
public NerResults(StreamInput in) throws IOException {
|
|
|
|
+ super(in);
|
|
entityGroups = in.readList(EntityGroup::new);
|
|
entityGroups = in.readList(EntityGroup::new);
|
|
resultsField = in.readString();
|
|
resultsField = in.readString();
|
|
annotatedResult = in.readString();
|
|
annotatedResult = in.readString();
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
|
|
|
|
|
+ void doXContentBody(XContentBuilder builder, Params params) throws IOException {
|
|
builder.field(resultsField, annotatedResult);
|
|
builder.field(resultsField, annotatedResult);
|
|
builder.startArray("entities");
|
|
builder.startArray("entities");
|
|
for (EntityGroup entity : entityGroups) {
|
|
for (EntityGroup entity : entityGroups) {
|
|
entity.toXContent(builder, params);
|
|
entity.toXContent(builder, params);
|
|
}
|
|
}
|
|
builder.endArray();
|
|
builder.endArray();
|
|
- return builder;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -59,18 +60,16 @@ public class NerResults implements InferenceResults {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void writeTo(StreamOutput out) throws IOException {
|
|
|
|
|
|
+ void doWriteTo(StreamOutput out) throws IOException {
|
|
out.writeList(entityGroups);
|
|
out.writeList(entityGroups);
|
|
out.writeString(resultsField);
|
|
out.writeString(resultsField);
|
|
out.writeString(annotatedResult);
|
|
out.writeString(annotatedResult);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public Map<String, Object> asMap() {
|
|
|
|
- Map<String, Object> map = new LinkedHashMap<>();
|
|
|
|
|
|
+ void addMapFields(Map<String, Object> map) {
|
|
map.put(resultsField, annotatedResult);
|
|
map.put(resultsField, annotatedResult);
|
|
map.put(ENTITY_FIELD, entityGroups.stream().map(EntityGroup::toMap).collect(Collectors.toList()));
|
|
map.put(ENTITY_FIELD, entityGroups.stream().map(EntityGroup::toMap).collect(Collectors.toList()));
|
|
- return map;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -95,15 +94,16 @@ public class NerResults implements InferenceResults {
|
|
public boolean equals(Object o) {
|
|
public boolean equals(Object o) {
|
|
if (this == o) return true;
|
|
if (this == o) return true;
|
|
if (o == null || getClass() != o.getClass()) return false;
|
|
if (o == null || getClass() != o.getClass()) return false;
|
|
|
|
+ if (super.equals(o) == false) return false;
|
|
NerResults that = (NerResults) o;
|
|
NerResults that = (NerResults) o;
|
|
- return Objects.equals(entityGroups, that.entityGroups)
|
|
|
|
- && Objects.equals(resultsField, that.resultsField)
|
|
|
|
- && Objects.equals(annotatedResult, that.annotatedResult);
|
|
|
|
|
|
+ return Objects.equals(resultsField, that.resultsField)
|
|
|
|
+ && Objects.equals(annotatedResult, that.annotatedResult)
|
|
|
|
+ && Objects.equals(entityGroups, that.entityGroups);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public int hashCode() {
|
|
public int hashCode() {
|
|
- return Objects.hash(entityGroups, resultsField, annotatedResult);
|
|
|
|
|
|
+ return Objects.hash(super.hashCode(), resultsField, annotatedResult, entityGroups);
|
|
}
|
|
}
|
|
|
|
|
|
public static class EntityGroup implements ToXContentObject, Writeable {
|
|
public static class EntityGroup implements ToXContentObject, Writeable {
|