forked from 5gi/DeepJ
		
	Reformatted code, added message and detected language extraction
This commit is contained in:
		
							parent
							
								
									70942c33fb
								
							
						
					
					
						commit
						c6b777577b
					
				
							
								
								
									
										4
									
								
								.idea/modules/core/DeepJ.core.test.iml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								.idea/modules/core/DeepJ.core.test.iml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,4 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<module version="4">
 | 
			
		||||
  <component name="TestModuleProperties" production-module="DeepJ.core.main" />
 | 
			
		||||
</module>
 | 
			
		||||
@ -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'
 | 
			
		||||
 | 
			
		||||
@ -1,2 +1,4 @@
 | 
			
		||||
rootProject.name = 'DeepJ'
 | 
			
		||||
include 'jsonParser'
 | 
			
		||||
include 'core'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user