Skip to content

Commit e0382d9

Browse files
authored
Add support for profanity detection endpoint
1 parent 3b52172 commit e0382d9

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.translated.lara.translator;
2+
3+
public enum ContentType {
4+
5+
TEXT("text/plain"),
6+
HTML("text/html"),
7+
XML("text/xml"),
8+
XLIFF("application/xliff+xml");
9+
10+
private final String value;
11+
12+
ContentType(String value) {
13+
this.value = value;
14+
}
15+
16+
@Override
17+
public String toString() {
18+
return value;
19+
}
20+
21+
public static String toString(ContentType contentType) {
22+
return contentType != null ? contentType.toString() : null;
23+
}
24+
}

src/main/java/com/translated/lara/translator/Translator.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,16 @@ public DetectResult detectAny(Object text, String hint, Collection<String> passl
104104
params.set("passlist", passlist);
105105
}
106106

107-
return client.post("/v2/detect", params.build()).as(DetectResult.class);
107+
return client.post("/v2/detect/language", params.build()).as(DetectResult.class);
108+
}
109+
110+
public ProfanityDetectResult detectProfanities(String text, String language, ContentType contentType) throws LaraException {
111+
HttpParams<Object> params = new HttpParams<>();
112+
params.set("text", text);
113+
params.set("language", language);
114+
params.set("content_type", contentType.toString());
115+
116+
return client.post("/v2/detect/profanities", params.build()).as(ProfanityDetectResult.class);
108117
}
109118

110119
public TextResult translate(String text, String source, String target) throws LaraException {

0 commit comments

Comments
 (0)