Reformatted code, added message and detected language extraction

This commit is contained in:
2022-02-02 19:45:30 -05:00
parent 70942c33fb
commit c6b777577b
6 changed files with 51 additions and 4 deletions

View File

@@ -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;
}
}

View File

@@ -1,4 +1,4 @@
package tech.nevets.deepj.api;
package tech.nevets.deepj;
public enum Languages {
BG,

View 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;
}
}