Reformatted code, added message and detected language extraction

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

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="TestModuleProperties" production-module="DeepJ.core.main" />
</module>

View File

@ -1,10 +1,11 @@
plugins {
id 'java-library'
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '5.2.0'
}
group 'tech.nevets.deepj.api'
version '1.0'
group 'tech.nevets.deepj'
version '1.1'
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_11
@ -13,6 +14,7 @@ repositories {
}
dependencies {
implementation group: 'org.json', name: 'json', version: '20210307'
}
apply plugin: 'maven-publish'

View File

@ -1,2 +1,4 @@
rootProject.name = 'DeepJ'
include 'jsonParser'
include 'core'

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