Changeset 35249 for gs3-extensions
- Timestamp:
- 2021-08-04T15:06:10+12:00 (3 years ago)
- Location:
- gs3-extensions/atea-nlp-tools/trunk/src/koreromaori-proxy
- Files:
-
- 2 added
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
gs3-extensions/atea-nlp-tools/trunk/src/koreromaori-proxy/src/main/java/org/atea/nlptools/koreromaoriinterface/TranscriptionServlet.java
r35248 r35249 23 23 import org.apache.logging.log4j.LogManager; 24 24 import org.apache.logging.log4j.Logger; 25 import org.atea.nlptools.koreromaoriinterface.exceptions.ReoTuhituhiException;26 25 import org.atea.nlptools.koreromaoriinterface.models.AudioFilePart; 27 import org.atea.nlptools.koreromaoriinterface.models. MyTranscriptionResponse;26 import org.atea.nlptools.koreromaoriinterface.models.TranscriptionResultDto; 28 27 import org.atea.nlptools.koreromaoriinterface.models.TranscriptionResult; 29 28 import org.atea.nlptools.koreromaoriinterface.services.ReoTuhituhiApiService; … … 115 114 116 115 // Transform the Tuhituhi response into our own format 117 List< MyTranscriptionResponse> responses = new ArrayList<MyTranscriptionResponse>(results.size());116 List<TranscriptionResultDto> responses = new ArrayList<TranscriptionResultDto>(results.size()); 118 117 for (AudioFilePart result : results) { 119 responses.add( MyTranscriptionResponse.FromTranscriptionResult(result.getTranscriptionResult(), result.fileName));118 responses.add(TranscriptionResultDto.FromTranscriptionResult(result.getTranscriptionResult(), result.fileName)); 120 119 } 121 120 … … 123 122 String json = jsonSerialiser.toJson(responses, transcriptionListType); 124 123 writer.append(json); 125 }126 catch (ReoTuhituhiException rtex)127 {128 response.sendError(502, "Call to the Reo Tuhituhi API failed.");129 124 } 130 125 catch (Exception ex) -
gs3-extensions/atea-nlp-tools/trunk/src/koreromaori-proxy/src/main/java/org/atea/nlptools/koreromaoriinterface/models/TranscriptionResult.java
r35239 r35249 11 11 private String transcription; 12 12 13 public String getLog() { 13 /** 14 * Initialises an empty instance of the {@link TranscriptionResult} class. 15 */ 16 public TranscriptionResult() { 17 18 } 19 20 /** 21 * Initialises a new instance of the {@link TranscriptionResult} class. 22 * 23 * @param log 24 * @param metadata 25 * @param modelVersion 26 * @param success 27 * @param transcription 28 */ 29 public TranscriptionResult( 30 String log, 31 TranscriptionResultMetadata[] metadata, 32 String modelVersion, 33 Boolean success, 34 String transcription) 35 { 36 this.log = log; 37 this.metadata = metadata; 38 this.modelVersion = modelVersion; 39 this.success = success; 40 this.transcription = transcription; 41 } 42 43 /** 44 * Initialises a new instance of the {@link TranscriptionResult} class, with the intention of logging an unsuccessful result. 45 * As such, each field is set to null bar the provided log, and {@link getSuccess} being set to false. 46 * 47 * @param log 48 */ 49 public TranscriptionResult( 50 String log) 51 { 52 this.log = log; 53 this.metadata = null; 54 this.modelVersion = null; 55 this.success = false; 56 this.transcription = null; 57 } 58 59 public String getLog() 60 { 14 61 return log; 15 62 } 16 63 17 public TranscriptionResultMetadata[] getMetadata() { 64 public TranscriptionResultMetadata[] getMetadata() 65 { 18 66 return metadata; 19 67 } 20 68 21 public String getModelVersion() { 69 public String getModelVersion() 70 { 22 71 return modelVersion; 23 72 } 24 73 25 public Boolean getSuccess() { 74 public Boolean getSuccess() 75 { 26 76 return success; 27 77 } 28 78 29 public String getTranscription() { 79 public String getTranscription() 80 { 30 81 return transcription; 31 82 } -
gs3-extensions/atea-nlp-tools/trunk/src/koreromaori-proxy/src/main/java/org/atea/nlptools/koreromaoriinterface/services/ReoTuhituhiApiService.java
r35248 r35249 3 3 import java.io.IOException; 4 4 import java.io.InputStream; 5 import java.net.SocketTimeoutException; 5 6 import java.util.LinkedList; 6 7 import java.util.List; … … 43 44 */ 44 45 public List<AudioFilePart> getTranscriptions(Iterable<AudioFilePart> audioFileParts) 45 throws HttpRequestException, JsonSyntaxException,Exception46 throws HttpRequestException, IOException 46 47 { 47 48 List<AudioFilePart> apiResults = new LinkedList<AudioFilePart>(); … … 49 50 for (AudioFilePart part : audioFileParts) 50 51 { 51 TranscriptionResult res = getTranscription(part.dataStream); 52 TranscriptionResult res = null; 53 try 54 { 55 res = getTranscription(part.dataStream); 56 } 57 catch (ReoTuhituhiException rtex) 58 { 59 res = new TranscriptionResult("The Reo Tuhituhi API didn't respond successfully."); 60 } 61 catch (JsonSyntaxException jsex) 62 { 63 res = new TranscriptionResult("That's on me! I failed to parse the response from the Reo Tuhituhi API."); 64 } 65 catch (HttpRequestException hrex) 66 { 67 if (hrex.getCause().getClass() == SocketTimeoutException.class) { 68 res = new TranscriptionResult("The Reo Tuhituhi API timed out."); 69 } 70 else { 71 throw hrex; 72 } 73 } 74 52 75 part.setTranscriptionResult(res); 53 54 76 apiResults.add(part); 55 77 } … … 66 88 * @throws JsonSyntaxException Thrown when the result cannot be parsed. 67 89 * @throws ReoTuhituhiException Thrown when the Reo Tuhituhi API returns an invalid response. 90 * @throws IOException Thrown at any time. 68 91 */ 69 92 public TranscriptionResult getTranscription(InputStream audioStream) … … 74 97 HttpRequestService request = HttpRequestService 75 98 .post(apiEndpoint) 99 .connectTimeout(2000) 100 .readTimeout(5000) 76 101 .authorization("Basic " + apiKey) 77 102 .send(audioStream); … … 87 112 ); 88 113 89 throw new ReoTuhituhiException(request.code(), request.message(), " Non-OK status code");114 throw new ReoTuhituhiException(request.code(), request.message(), "API returned a non-OK status code"); 90 115 } 91 116 … … 100 125 ); 101 126 102 throw new ReoTuhituhiException(request.code(), request.message(), " Invalid content type: " + request.contentType());127 throw new ReoTuhituhiException(request.code(), request.message(), "API specified an invalid content type: " + request.contentType()); 103 128 } 104 129
Note:
See TracChangeset
for help on using the changeset viewer.