forked from Steven/DeepJ
Reformatted code, added message and detected language extraction
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package tech.nevets.deepj.api;
|
||||
package tech.nevets.deepj;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@@ -43,4 +43,6 @@ public class DeepJ {
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package tech.nevets.deepj.api;
|
||||
package tech.nevets.deepj;
|
||||
|
||||
public enum Languages {
|
||||
BG,
|
||||
37
src/main/java/tech/nevets/deepj/json/JsonExtractor.java
Normal file
37
src/main/java/tech/nevets/deepj/json/JsonExtractor.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package tech.nevets.deepj.json;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class JsonExtractor {
|
||||
public JsonExtractor() {
|
||||
}
|
||||
|
||||
public String extractMessage(String jsonResponse) {
|
||||
String message = "Error Processing Request";
|
||||
|
||||
JSONObject jo = new JSONObject(jsonResponse);
|
||||
JSONArray ja = jo.getJSONArray("translations");
|
||||
|
||||
for (int i = 0; i < ja.length(); i++) {
|
||||
JSONObject joo = ja.getJSONObject(i);
|
||||
message = joo.getString("text");
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
public String extractDetectedLang(String jsonResponse) {
|
||||
String lang = "Error Processing Request";
|
||||
|
||||
JSONObject jo = new JSONObject(jsonResponse);
|
||||
JSONArray ja = jo.getJSONArray("translations");
|
||||
|
||||
for (int i = 0; i < ja.length(); i++) {
|
||||
JSONObject joo = ja.getJSONObject(i);
|
||||
lang = joo.getString("detected_source_language");
|
||||
}
|
||||
|
||||
return lang;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user