|
| 1 | +/* |
| 2 | + * Copyright 2019 Origma Pty Ltd (ACN 629 381 184) and contributors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + * Written by Ben McLean <ben@origma.com.au>, November 2019 |
| 17 | + */ |
| 18 | +package au.com.origma.perspectiveapi.v1alpha1.models; |
| 19 | + |
| 20 | +import java.util.ArrayList; |
| 21 | +import java.util.HashMap; |
| 22 | +import java.util.List; |
| 23 | +import java.util.Map; |
| 24 | + |
| 25 | +/** |
| 26 | + * Send a suggested score for a request |
| 27 | + * |
| 28 | + * @author Ben McLean <ben@origma.com.au> |
| 29 | + * |
| 30 | + */ |
| 31 | +public class SuggestScoreRequest { |
| 32 | + |
| 33 | + Entry comment; |
| 34 | + Context context; |
| 35 | + Map<AttributeType, AttributeScore> attributeScores; |
| 36 | + List<String> languages; |
| 37 | + String communityId; |
| 38 | + String clientToken; |
| 39 | + |
| 40 | + /** |
| 41 | + * Same as AnalyzeComment request. |
| 42 | + * |
| 43 | + * @return the comment for which the score is being suggested |
| 44 | + */ |
| 45 | + public Entry getComment() { |
| 46 | + return comment; |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Same as AnalyzeComment request. |
| 51 | + * |
| 52 | + * @return the context of the request |
| 53 | + */ |
| 54 | + public Context getContext() { |
| 55 | + return context; |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Similar to AnalyzeComment response. This holds the attribute scores that the |
| 60 | + * client believes the comment should have. It has the same format as the |
| 61 | + * attributeScores field in the AnalyzeComment response, as it's what the client |
| 62 | + * believes is the correct "answer" for what this comment should be scored as. |
| 63 | + * The client can specify just summary scores, just span scores, or both. |
| 64 | + * |
| 65 | + * @return the attribute scores of the request |
| 66 | + */ |
| 67 | + public Map<AttributeType, AttributeScore> getAttributeScores() { |
| 68 | + return attributeScores; |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Returns the languages of the request |
| 73 | + * |
| 74 | + * @return the languages of the request |
| 75 | + */ |
| 76 | + public List<String> getLanguages() { |
| 77 | + return languages; |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * Opaque identifier associating this score suggestion with a particular |
| 82 | + * community. If set, this field allows us to differentiate suggestions from |
| 83 | + * different communities, as each community may have different norms. |
| 84 | + * |
| 85 | + * @return the community id |
| 86 | + */ |
| 87 | + public String getCommunityId() { |
| 88 | + return communityId; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * An opaque token that is echoed back in the response. |
| 93 | + * |
| 94 | + * @return the client token |
| 95 | + */ |
| 96 | + public String getClientToken() { |
| 97 | + return clientToken; |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Builds a SuggestScoreRequest |
| 102 | + * |
| 103 | + * @author Ben McLean <ben@origma.com.au> |
| 104 | + * |
| 105 | + */ |
| 106 | + public static class Builder { |
| 107 | + private Entry comment; |
| 108 | + private Context context; |
| 109 | + private Map<AttributeType, AttributeScore> attributeScores = new HashMap<>(); |
| 110 | + private List<String> languages = new ArrayList<>(); |
| 111 | + private String communityId; |
| 112 | + private String clientToken; |
| 113 | + |
| 114 | + /** |
| 115 | + * Set the comment for a suggestion |
| 116 | + * @param comment the comment |
| 117 | + * @return The builder |
| 118 | + */ |
| 119 | + public Builder comment(Entry comment) { |
| 120 | + this.comment = comment; |
| 121 | + return this; |
| 122 | + } |
| 123 | + |
| 124 | + /** |
| 125 | + * Set the context for a suggestion |
| 126 | + * @param context the context |
| 127 | + * @return The builder |
| 128 | + */ |
| 129 | + public Builder context(Context context) { |
| 130 | + this.context = context; |
| 131 | + return this; |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * Set the attribute scores for a suggestion |
| 136 | + * @param attributeScores the attribute scores |
| 137 | + * @return The builder |
| 138 | + */ |
| 139 | + public Builder attributeScores(Map<AttributeType, AttributeScore> attributeScores) { |
| 140 | + this.attributeScores = attributeScores; |
| 141 | + return this; |
| 142 | + } |
| 143 | + |
| 144 | + /** |
| 145 | + * Add an attribute score |
| 146 | + * @param type The attribute type |
| 147 | + * @param score The attribute score |
| 148 | + * @return The builder |
| 149 | + */ |
| 150 | + public Builder addAttributeScore(AttributeType type, AttributeScore score) { |
| 151 | + this.attributeScores.put(type, score); |
| 152 | + return this; |
| 153 | + } |
| 154 | + |
| 155 | + /** |
| 156 | + * Set the languages for a suggestion |
| 157 | + * @param languages the languages |
| 158 | + * @return The builder |
| 159 | + */ |
| 160 | + public Builder languages(List<String> languages) { |
| 161 | + this.languages = languages; |
| 162 | + return this; |
| 163 | + } |
| 164 | + |
| 165 | + /** |
| 166 | + * Add a language |
| 167 | + * @param language the language |
| 168 | + * @return The builder |
| 169 | + */ |
| 170 | + public Builder addLanugage(String language) { |
| 171 | + this.languages.add(language); |
| 172 | + return this; |
| 173 | + } |
| 174 | + |
| 175 | + /** |
| 176 | + * Set the community id |
| 177 | + * @param communityId the community id |
| 178 | + * @return The builder |
| 179 | + */ |
| 180 | + public Builder communityId(String communityId) { |
| 181 | + this.communityId = communityId; |
| 182 | + return this; |
| 183 | + } |
| 184 | + |
| 185 | + /** |
| 186 | + * Set the client token |
| 187 | + * @param clientToken the client token |
| 188 | + * @return The builder |
| 189 | + */ |
| 190 | + public Builder clientToken(String clientToken) { |
| 191 | + this.clientToken = clientToken; |
| 192 | + return this; |
| 193 | + } |
| 194 | + |
| 195 | + /** |
| 196 | + * Build a new SuggestScoreRequest instance |
| 197 | + * @return a new SuggestScoreRequest instance |
| 198 | + */ |
| 199 | + public SuggestScoreRequest build() { |
| 200 | + return new SuggestScoreRequest(this); |
| 201 | + } |
| 202 | + } |
| 203 | + |
| 204 | + private SuggestScoreRequest(Builder builder) { |
| 205 | + this.comment = builder.comment; |
| 206 | + this.context = builder.context; |
| 207 | + this.attributeScores = builder.attributeScores; |
| 208 | + this.languages = builder.languages; |
| 209 | + this.communityId = builder.communityId; |
| 210 | + this.clientToken = builder.clientToken; |
| 211 | + } |
| 212 | +} |
0 commit comments