Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

English concatination issue fix and sending construct text from learner ai to text eval api #72

Open
wants to merge 2 commits into
base: release-2.0-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions src/mongodb/scores.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class ScoresController {
missing_token_scoresArr = identifyTokens.missing_token_scoresArr;
anomaly_scoreArr = identifyTokens.anomaly_scoreArr;

const textEvalMatrices = await this.scoresService.getTextMetrics(originalText, constructText, language, audioFile)
const textEvalMatrices = await this.scoresService.getTextMetrics(originalText, language, constructText)

if (process.env.denoiserEnabled === "true") {
let improved = false;
Expand Down Expand Up @@ -1197,10 +1197,9 @@ export class ScoresController {
const url = process.env.ALL_TEXT_EVAL_API + "/getTextMatrices";

const textData = {
reference: CreateLearnerProfileDto.original_text,
hypothesis: CreateLearnerProfileDto.output[0].source,
language: 'kn',
base64_string: audioFile.toString('base64'),
"reference": CreateLearnerProfileDto.original_text,
"construct_text": constructText,
language: 'kn'
};

const textEvalMatrices = await lastValueFrom(
Expand Down Expand Up @@ -1500,7 +1499,13 @@ export class ScoresController {

responseText = await this.scoresService.processText(CreateLearnerProfileDto.output[0].source);

const textEvalMatrices = await this.scoresService.getTextMetrics(originalText, responseText, language, audioFile)
// Constructed Logic starts from here
let constructedTextRepCountData = await this.scoresService.getConstructedText(originalText, responseText);
let constructText = constructedTextRepCountData.constructText;
let repetitions = constructedTextRepCountData.reptitionCount;
// End Constructed Text Logic

const textEvalMatrices = await this.scoresService.getTextMetrics(originalText, language, constructText)

for (const confidence_char of textEvalMatrices.confidence_char_list) {
const hexcode = await this.scoresService.getTokenHexcode(tokenHexcodeDataArr, confidence_char);
Expand Down Expand Up @@ -1569,11 +1574,6 @@ export class ScoresController {
await this.scoresService.addDenoisedOutputLog(createDenoiserOutputLog);
}

// Constructed Logic starts from here
let constructedTextRepCountData = await this.scoresService.getConstructedText(originalText, responseText);
let repetitions = constructedTextRepCountData.reptitionCount;
// End Constructed Text Logic

let fluencyScore = await this.scoresService.getCalculatedFluency(textEvalMatrices, repetitions, originalText, responseText, pause_count);

let createdAt = new Date().toISOString().replace('Z', '+00:00')
Expand Down Expand Up @@ -2233,9 +2233,8 @@ export class ScoresController {

const textData = {
"reference": CreateLearnerProfileDto.original_text,
"hypothesis": CreateLearnerProfileDto.output[0].source,
"construct_text": constructText,
"language": "te",
"base64_string": audioFile.toString('base64')
};

const textEvalMatrices = await lastValueFrom(
Expand Down
70 changes: 55 additions & 15 deletions src/mongodb/scores.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2188,23 +2188,67 @@ export class ScoresService {
async getConstructedText(original_text: string, response_text: string) {
let constructText = '';
const compareCharArr = [];
const constructTextSet = new Set();
const constructTextSet = [];
let reptitionCount = 0;

for (const originalEle of original_text.split(
' ',
)) {
const original_text_arr = original_text.split(' ');
const response_text_arr = response_text.split(' ');

for (const [originalEleindex, originalEle] of original_text_arr.entries()) {
let originalSplitText = '';
if (originalEleindex < original_text_arr.length - 1 && originalEle.length > 2) {
originalSplitText = originalEle + original_text_arr[originalEleindex + 1];
}
let originalRepCount = 0;
for (const sourceEle of response_text.split(' ')) {

let similiaritythreshold = 0.85;

for (const [sourceEleindex, sourceEle] of response_text_arr.entries()) {
let responseSplitText = '';
if (sourceEleindex < response_text_arr.length - 1 && sourceEle.length > 2) {
responseSplitText = sourceEle + response_text_arr[sourceEleindex + 1];
}
const similarityScore = await this.getTextSimilarity(originalEle, sourceEle);
if (similarityScore >= 0.4) {
if (similarityScore >= similiaritythreshold) {
compareCharArr.push({
original_text: originalEle,
response_text: sourceEle,
score: similarityScore,
});
break;
}
if (similarityScore >= 0.6) {

const originalSimilarityScoreSplit = await this.getTextSimilarity(originalSplitText, sourceEle);

if (originalSimilarityScoreSplit >= similiaritythreshold) {
compareCharArr.push({
original_text: originalEle,
response_text: originalEle,
score: originalSimilarityScoreSplit,
});

compareCharArr.push({
original_text: originalSplitText,
response_text: original_text_arr[originalEleindex + 1],
score: originalSimilarityScoreSplit,
});

break;

}

const responseSimilarityScoreSplit = await this.getTextSimilarity(originalEle, responseSplitText);

if (responseSimilarityScoreSplit >= similiaritythreshold) {
compareCharArr.push({
original_text: originalEle,
response_text: responseSplitText,
score: responseSimilarityScoreSplit,
});
break;
}

if (similarityScore >= similiaritythreshold) {
originalRepCount++;
}
}
Expand All @@ -2217,17 +2261,14 @@ export class ScoresService {
let score = 0;
let word = '';
for (const compareCharArrCmpEle of compareCharArr) {
if (
compareCharArrEle.original_text ===
compareCharArrCmpEle.original_text
) {
if (compareCharArrEle.original_text === compareCharArrCmpEle.original_text) {
if (compareCharArrCmpEle.score > score) {
score = compareCharArrCmpEle.score;
word = compareCharArrCmpEle.response_text;
}
}
}
constructTextSet.add(word);
constructTextSet.push(word);
}

for (const constructTextSetEle of constructTextSet) {
Expand All @@ -2239,14 +2280,13 @@ export class ScoresService {
return { constructText, reptitionCount }
}

async getTextMetrics(original_text: string, response_text: string, language: string, base64_string) {
async getTextMetrics(original_text: string, language: string, construct_text: string) {
const url = process.env.ALL_TEXT_EVAL_API + "/getTextMatrices";

const textData = {
reference: original_text,
hypothesis: response_text,
language: language,
base64_string: base64_string.toString('base64'),
construct_text: construct_text
};

const textEvalMatrices = await lastValueFrom(
Expand Down