d-ser-t-service
Advanced tools
Comparing version 1.1.3 to 1.2.0
@@ -18,2 +18,3 @@ /// <reference types="node" /> | ||
private transcriptionService; | ||
private xmlWriterService; | ||
constructor(harnessConfig: HarnessConfig); | ||
@@ -20,0 +21,0 @@ setTranscriptionService(): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const fs_1 = tslib_1.__importDefault(require("fs")); | ||
const path_1 = tslib_1.__importDefault(require("path")); | ||
@@ -9,2 +10,4 @@ const ResponseAnalyzer_1 = require("./ResponseAnalyzer"); | ||
const TranscriptionService_1 = require("./TranscriptionService"); | ||
const Utils_1 = tslib_1.__importDefault(require("./Utils")); | ||
const XmlWriterService_1 = require("./XmlWriterService"); | ||
class CustomSpeechTestHarness { | ||
@@ -16,4 +19,2 @@ constructor(harnessConfig) { | ||
this.exceptions = harnessConfig.exceptions; | ||
this.outFile = | ||
harnessConfig.outFile || path_1.default.join('.', 'test_results.json'); | ||
this.serviceRegion = harnessConfig.region; | ||
@@ -23,2 +24,15 @@ this.singleFile = harnessConfig.audioFile; | ||
this.transcriptionFile = harnessConfig.transcriptionFile; | ||
if (['json', 'xml'].includes(path_1.default.extname(String(harnessConfig.outFile)).substr(1))) { | ||
this.outFile = String(harnessConfig.outFile); | ||
} | ||
else { | ||
const warnMsg = `\nOutput file types other than .json or .xml are unsupported - using .json by default.\n`; | ||
console.warn(warnMsg); | ||
const defaultDir = './test_results/'; | ||
if (!fs_1.default.existsSync(defaultDir)) { | ||
fs_1.default.mkdirSync(defaultDir); | ||
console.log('Creating default directory test_results for test output.\n'); | ||
} | ||
this.outFile = defaultDir + '/test_results.json'; | ||
} | ||
} | ||
@@ -37,2 +51,3 @@ setTranscriptionService() { | ||
this.responseAnalyzer = new ResponseAnalyzer_1.ResponseAnalyzer(this.transcriptAnalyzer); | ||
this.xmlWriterService = new XmlWriterService_1.XmlWriterService(); | ||
} | ||
@@ -103,8 +118,14 @@ async singleFileTranscription() { | ||
}; | ||
this.outFile | ||
? this.localFileService.writeToTextFile(this.outFile, { | ||
const outputFileType = path_1.default.extname(String(this.outFile)).substr(1); | ||
console.log('Output file type: ' + outputFileType); | ||
if (outputFileType === 'json') { | ||
this.localFileService.writeToTextFile(this.outFile, { | ||
metaData, | ||
results, | ||
}) | ||
: console.warn('Output File not generated'); | ||
}); | ||
} | ||
else if (outputFileType === 'xml') { | ||
const timestamp = Utils_1.default.getCurrentTimestamp(); | ||
this.xmlWriterService.writeToXmlFile(this.outFile, metaData, results, timestamp); | ||
} | ||
console.log(`Runtime: ${totalTestingTime}`); | ||
@@ -111,0 +132,0 @@ } |
@@ -27,2 +27,8 @@ export interface CleanUpConfig { | ||
} | ||
export interface TestMetaData { | ||
transcriptionFile: string; | ||
sentenceErrorRate: string; | ||
averageWordErrorRate: string; | ||
totalTestingTime: string; | ||
} | ||
export interface TranscriptionServiceConfig { | ||
@@ -29,0 +35,0 @@ endpointID?: string; |
@@ -16,2 +16,3 @@ import { UnhandledCharacters } from './types'; | ||
* exists, return undefined. | ||
* | ||
* @returns regex pattern or undefined if none found | ||
@@ -21,3 +22,14 @@ * @param input string | ||
static extractRegExPattern: (input: string) => string | undefined; | ||
/** | ||
* Gets current timestamp and returns a formatted string. | ||
*/ | ||
static getCurrentTimestamp(): string; | ||
/** | ||
* Add a "0" in front of single-digit values in an array (for timestamp | ||
* formatting). | ||
* | ||
* @param arr Array of elements to modify | ||
*/ | ||
static zeroPrefix(arr: string[]): string[]; | ||
} | ||
//# sourceMappingURL=Utils.d.ts.map |
@@ -7,2 +7,35 @@ "use strict"; | ||
class Utils { | ||
/** | ||
* Gets current timestamp and returns a formatted string. | ||
*/ | ||
static getCurrentTimestamp() { | ||
const now = new Date(); | ||
const date = [ | ||
String(now.getUTCFullYear()), | ||
String(now.getUTCMonth() + 1), | ||
String(now.getUTCDate()), | ||
]; | ||
const time = [ | ||
String(now.getUTCHours()), | ||
String(now.getUTCMinutes()), | ||
String(now.getUTCSeconds()), | ||
]; | ||
this.zeroPrefix(date); | ||
this.zeroPrefix(time); | ||
return [date.join('-'), time.join(':')].join(' '); | ||
} | ||
/** | ||
* Add a "0" in front of single-digit values in an array (for timestamp | ||
* formatting). | ||
* | ||
* @param arr Array of elements to modify | ||
*/ | ||
static zeroPrefix(arr) { | ||
arr.forEach((elem, i) => { | ||
if (Number(elem) < 10 && Number(elem) >= 0) { | ||
arr[i] = '0' + elem; | ||
} | ||
}); | ||
return arr; | ||
} | ||
} | ||
@@ -34,2 +67,3 @@ /** | ||
* exists, return undefined. | ||
* | ||
* @returns regex pattern or undefined if none found | ||
@@ -36,0 +70,0 @@ * @param input string |
{ | ||
"name": "d-ser-t-service", | ||
"version": "1.1.3", | ||
"version": "1.2.0", | ||
"description": "Dynamic Sentence Error Rate Testing: A Package for testing the CRIS speech-to-text model, quantifying the quality of the model with respect to its Word Error Rate", | ||
@@ -38,3 +38,4 @@ "license": "MIT", | ||
"tslib": "^1.10.0", | ||
"word-error-rate": "0.0.7" | ||
"word-error-rate": "0.0.7", | ||
"xmlbuilder": "^13.0.2" | ||
}, | ||
@@ -60,3 +61,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "6213c4db47c31cd397dc33c0b44dcfef7ce5a51d" | ||
"gitHead": "7d5061957cec6aa57b6080067f186e54bc42ca5a" | ||
} |
@@ -72,3 +72,3 @@ [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v1.4%20adopted-ff69b4.svg)](CODE_OF_CONDUCT.md) | ||
### Results stored in JSON format. | ||
Testing stores test results in JSON format which is stored in `../test_results.json` by default, storage location can be changed with a flag. | ||
Testing stores test results in JSON format which is stored in `../test_results/test_results.json` by default, storage location can be changed with a flag. | ||
@@ -75,0 +75,0 @@ ```JSON |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
100737
59
1240
6
6
+ Addedxmlbuilder@^13.0.2
+ Addedxmlbuilder@13.0.2(transitive)