Skip to content

Commit 67ed6bb

Browse files
authored
Merge pull request #1 from origma/benmmclean/documentation/general
Benmmclean/documentation/general
2 parents bbaf352 + e3ca748 commit 67ed6bb

File tree

13 files changed

+400
-91
lines changed

13 files changed

+400
-91
lines changed

src/au/com/origma/perspectiveapi/v1alpha1/PerspectiveAPI.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,39 @@
99
import au.com.origma.perspectiveapi.v1alpha1.models.AnalyzeCommentRequest;
1010
import au.com.origma.perspectiveapi.v1alpha1.models.AnalyzeCommentResponse;
1111

12+
/**
13+
* Interact with Google's PerspectiveAPI to analyze comments and content.<br>
14+
* See the API documentation
15+
* <a href="https://github.com/conversationai/perspectiveapi/blob/master/2-api/README.md">here</a>
16+
*
17+
* @author Ben McLean &lt;ben@origma.com.au&gt;
18+
*/
1219
public interface PerspectiveAPI {
1320

21+
/**
22+
* The endpoint to which analysis requests are sent
23+
*/
1424
public static final String ANALYZE_ENDPOINT = "https://commentanalyzer.googleapis.com/v1alpha1/comments:analyze";
1525

26+
/**
27+
* Analyze a comment
28+
* @param request The request
29+
* @return The analysis of the request
30+
*/
1631
public AnalyzeCommentResponse analyze(AnalyzeCommentRequest request);
32+
33+
/**
34+
* Analyze a comment with the default settings
35+
* @param comment The comment to analyze
36+
* @return The analysis of the request
37+
*/
1738
public AnalyzeCommentResponse analyze(String comment);
1839

40+
/**
41+
* Instantiate the default implementation of the PerspectiveAPI
42+
* @param apiKey The Google API key
43+
* @return The default implementation of the PerspectiveAPI
44+
*/
1945
public static PerspectiveAPI create(String apiKey) {
2046
return new UnirestPerspectiveAPI(apiKey);
2147
}

src/au/com/origma/perspectiveapi/v1alpha1/UnirestPerspectiveAPI.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,20 @@
1414
import kong.unirest.HttpResponse;
1515
import kong.unirest.Unirest;
1616

17+
/**
18+
* The default implementation of the PerspectiveAPI client, made using the Unirest library
19+
*
20+
* @author Ben McLean &lt;ben@origma.com.au&gt;
21+
*/
1722
public class UnirestPerspectiveAPI implements PerspectiveAPI {
1823

1924
String apiKey;
2025
boolean doNotStore = true;
2126

27+
/**
28+
* Create a new instance of UnirestPerspectiveAPI
29+
* @param apiKey Your Google API Key
30+
*/
2231
public UnirestPerspectiveAPI(String apiKey) {
2332
super();
2433
this.apiKey = apiKey;
@@ -50,10 +59,18 @@ public AnalyzeCommentResponse analyze(String comment) {
5059
.build());
5160
}
5261

62+
/**
63+
* If the simple analysis will default to do not store
64+
* @return the simple analysis will default to do not store
65+
*/
5366
public boolean isDoNotStore() {
5467
return doNotStore;
5568
}
5669

70+
/**
71+
* The default do not store setting
72+
* @param doNotStore The default do not store setting
73+
*/
5774
public void setDoNotStore(boolean doNotStore) {
5875
this.doNotStore = doNotStore;
5976
}

src/au/com/origma/perspectiveapi/v1alpha1/models/AnalyzeCommentRequest.java

Lines changed: 100 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
import java.util.List;
1212
import java.util.Map;
1313

14+
/**
15+
* A request to analyze a string of text for attributes
16+
* @author Ben McLean &lt;ben@origma.com.au&gt;
17+
*/
1418
public class AnalyzeCommentRequest {
1519

1620
Entry comment;
@@ -21,89 +25,77 @@ public class AnalyzeCommentRequest {
2125
String clientToken;
2226
String sessionId;
2327
Double suggestCommentScore;
24-
25-
public AnalyzeCommentRequest() {
26-
super();
27-
}
28-
29-
public AnalyzeCommentRequest(Entry comment, Context context, Map<AttributeType, RequestedAttribute> requestedAttributes,
30-
List<String> languages, Boolean doNotStore, String clientToken, String sessionId,
31-
Double suggestCommentScore) {
32-
super();
33-
this.comment = comment;
34-
this.context = context;
35-
this.requestedAttributes = requestedAttributes;
36-
this.languages = languages;
37-
this.doNotStore = doNotStore;
38-
this.clientToken = clientToken;
39-
this.sessionId = sessionId;
40-
this.suggestCommentScore = suggestCommentScore;
41-
}
42-
28+
29+
/**
30+
* Returns the comment to be analyzed by the request
31+
* @return
32+
*/
4333
public Entry getComment() {
4434
return comment;
4535
}
4636

47-
public void setComment(Entry comment) {
48-
this.comment = comment;
49-
}
50-
37+
/**
38+
* Returns the content of the request
39+
* @return the content of the request
40+
*/
5141
public Context getContext() {
5242
return context;
5343
}
5444

55-
public void setContext(Context context) {
56-
this.context = context;
57-
}
58-
45+
/**
46+
* Returns the attributes that will be requested
47+
* @return the attributes that will be requested
48+
*/
5949
public Map<AttributeType, RequestedAttribute> getRequestedAttributes() {
6050
return requestedAttributes;
6151
}
6252

63-
public void setRequestedAttributes(Map<AttributeType, RequestedAttribute> requestedAttributes) {
64-
this.requestedAttributes = requestedAttributes;
65-
}
66-
53+
/**
54+
* Returns the set languages for the request
55+
* @return the set languages for the request
56+
*/
6757
public List<String> getLanguages() {
6858
return languages;
6959
}
70-
71-
public void setLanguages(List<String> languages) {
72-
this.languages = languages;
73-
}
74-
60+
61+
/**
62+
* Returns whether the comment will be stored for analysis or not
63+
* @return whether the comment will be stored for analysis or not
64+
*/
7565
public Boolean getDoNotStore() {
7666
return doNotStore;
7767
}
7868

79-
public void setDoNotStore(Boolean doNotStore) {
80-
this.doNotStore = doNotStore;
81-
}
82-
69+
/**
70+
* Returns the client token of the request
71+
* @return the client token of the request
72+
*/
8373
public String getClientToken() {
8474
return clientToken;
8575
}
8676

87-
public void setClientToken(String clientToken) {
88-
this.clientToken = clientToken;
89-
}
90-
77+
/**
78+
* Returns the session ID of the request
79+
* @return the session ID of the request
80+
*/
9181
public String getSessionId() {
9282
return sessionId;
9383
}
9484

95-
public void setSessionId(String sessionId) {
96-
this.sessionId = sessionId;
97-
}
98-
85+
/**
86+
* Returns the comment score suggested to the analyzer
87+
* @return the comment score suggested to the analyzer
88+
*/
9989
public Double getSuggestCommentScore() {
10090
return suggestCommentScore;
10191
}
10292

103-
public void setSuggestCommentScore(Double suggestCommentScore) {
104-
this.suggestCommentScore = suggestCommentScore;
105-
}
106-
93+
/**
94+
* Builds an AnalyzeCommentRequest
95+
*
96+
* @author Ben McLean &lt;ben@origma.com.au&gt;
97+
*
98+
*/
10799
public static class Builder {
108100
private Entry comment;
109101
private Context context;
@@ -114,60 +106,115 @@ public static class Builder {
114106
private String sessionId;
115107
private Double suggestCommentScore;
116108

109+
/**
110+
* Set the comment of the future AnalyzeCommentRequest
111+
* @param comment the comment of the future AnalyzeCommentRequest
112+
* @return The builder
113+
*/
117114
public Builder comment(Entry comment) {
118115
this.comment = comment;
119116
return this;
120117
}
121118

119+
/**
120+
* Set the context of the future AnalyzeCommentRequest
121+
* @param context the context of the future AnalyzeCommentRequest
122+
* @return The builder
123+
*/
122124
public Builder context(Context context) {
123125
this.context = context;
124126
return this;
125127
}
126128

129+
/**
130+
* Set the requested attributes of the future AnalyzeCommentRequest
131+
* @param requestedAttributes the requested attributes of the future AnalyzeCommentRequest
132+
* @return The builder
133+
*/
127134
public Builder requestedAttributes(Map<AttributeType, RequestedAttribute> requestedAttributes) {
128135
this.requestedAttributes = requestedAttributes;
129136
return this;
130137
}
131138

139+
/**
140+
* Add a requested attribute to the future AnalyzeCommentRequest
141+
* @param type The type of the requested attribute
142+
* @param requestedAttribute The parameters of the requested attribute
143+
* @return The builder
144+
*/
132145
public Builder addRequestedAttribute(AttributeType type, RequestedAttribute requestedAttribute) {
133146
if(requestedAttribute != null){
134147
requestedAttributes.put(type, requestedAttribute);
135148
}else{
136-
requestedAttributes.put(type, new RequestedAttribute());
149+
requestedAttributes.put(type, new RequestedAttribute.Builder().build());
137150
}
138151
return this;
139152
}
140153

154+
/**
155+
* Set the languages of the future AnalyzeCommentRequest
156+
* @param languages the languages of the future AnalyzeCommentRequest in ISO 639-1
157+
* @return The builder
158+
*/
141159
public Builder languages(List<String> languages) {
142160
this.languages = languages;
143161
return this;
144162
}
145163

164+
/**
165+
* Add a language to the future AnalyzeCommentRequest
166+
* @param language The language in ISO 639-1
167+
* @return The builder
168+
*/
146169
public Builder addLanguage(String language){
147170
languages.add(language);
148171
return this;
149172
}
150173

174+
/**
175+
* Set the do not store of the future AnalyzeCommentRequest
176+
* @param doNotStore the do not store of the future AnalyzeCommentRequest
177+
* @return The builder
178+
*/
151179
public Builder doNotStore(Boolean doNotStore) {
152180
this.doNotStore = doNotStore;
153181
return this;
154182
}
155183

184+
/**
185+
* Set the client token of the future AnalyzeCommentRequest
186+
* @param clientToken the clientToken of the future AnalyzeCommentRequest
187+
* @return The builder
188+
*/
156189
public Builder clientToken(String clientToken) {
157190
this.clientToken = clientToken;
158191
return this;
159192
}
160193

194+
/**
195+
* Set the session ID of the future AnalyzeCommentRequest
196+
* @param sessionId the sessionId of the future AnalyzeCommentRequest
197+
* @return The builder
198+
*/
161199
public Builder sessionId(String sessionId) {
162200
this.sessionId = sessionId;
163201
return this;
164202
}
165203

204+
/**
205+
* Set the suggested comment score of the future AnalyzeCommentRequest
206+
* @param suggestCommentScore the suggested comment score of the future AnalyzeCommentRequest
207+
* @return The builder
208+
*/
166209
public Builder suggestCommentScore(Double suggestCommentScore) {
167210
this.suggestCommentScore = suggestCommentScore;
168211
return this;
169212
}
170213

214+
/**
215+
* Build and create a new instance of AnalyzeCommentRequest
216+
* @return The builder
217+
*/
171218
public AnalyzeCommentRequest build() {
172219
return new AnalyzeCommentRequest(this);
173220
}

0 commit comments

Comments
 (0)