Skip to content

Commit

Permalink
Fixed bug in analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
isc-lperezra committed Aug 20, 2024
1 parent 0b26651 commit 3e2f99a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 52 deletions.
86 changes: 52 additions & 34 deletions encoder-ui/src/app/analyzer/analyzer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,43 +67,61 @@ export class AnalyzerComponent {
"Text": textToProcess[index],
"Language": this.translocoService.getActiveLang()
};
this.irisService.analyzeText(textData).subscribe({next: res =>{
if (res.length > 0){
this.diagnostics = this.diagnostics.concat(res);
}
this.irisService.analyzeText(textData).subscribe({next: resp =>{
this.totalReceived += forReading;
if (this.totalReceived >= 100){
this.diagnostics.forEach((diagnostic, indexDiag) => {
let phrase = "";
if (diagnostic.RawText.split(" ").length == 3){
phrase = textOriginal.match(new RegExp(diagnostic.RawText.split(" ")[0] + " (.{0,100}) " +diagnostic.RawText.split(" ")[2],"ig"))[0];
this.irisService.getAnalysisDetails(raw.id).subscribe({next: res => {
if (res.length > 0){
this.diagnostics = this.diagnostics.concat(res);
}
else if (diagnostic.RawText.split(" ").length == 2){
phrase = textOriginal.match(new RegExp(diagnostic.RawText.split(" ")[0] + " (.{0,100}) " +diagnostic.RawText.split(" ")[1],"ig"))[0];
}
else if (diagnostic.RawText.split(" ").length == 4){
phrase = textOriginal.match(new RegExp(diagnostic.RawText.split(" ")[0] + " (.{0,100}) " +diagnostic.RawText.split(" ")[3],"ig"))[0];
}
else if (diagnostic.RawText.split(" ").length == 1){
phrase = textOriginal.match(diagnostic.RawText);
}
var indexDiag = this.textAndDiagnosticList.findIndex(obj => obj.rawText == phrase);
const diagnosticEncoded: Diagnostic = {code: diagnostic.CodeId, description: diagnostic.Description, similarity: diagnostic.Similarity}
if (indexDiag == -1)
{
textHTML = textHTML.replace(phrase,"<mark>"+phrase+"</mark>");
let textAndDiagnostic: TextAndDiagnostic = {rawText: phrase, diagnostics: []};
textAndDiagnostic.diagnostics.push(diagnosticEncoded);
this.textAndDiagnosticList.push(textAndDiagnostic);
}
else {
this.textAndDiagnosticList[indexDiag].diagnostics.push(diagnosticEncoded)
}
})
this.textUpdated = textHTML
this.loading = false;
}
},
this.diagnostics.forEach((diagnostic, indexDiag) => {
let phrase: string = "";
if (diagnostic.RawText.split(" ").length == 3){
const matchValue = textOriginal.match(new RegExp(diagnostic.RawText.split(" ")[0] + " (.{0,100}) " +diagnostic.RawText.split(" ")[2],"ig"));
if (matchValue) {
phrase = matchValue[0];
}
}
else if (diagnostic.RawText.split(" ").length == 2){
const matchValue = textOriginal.match(new RegExp(diagnostic.RawText.split(" ")[0] + " (.{0,100}) " +diagnostic.RawText.split(" ")[1],"ig"));
if (matchValue) {
phrase = matchValue[0];
}
}
else if (diagnostic.RawText.split(" ").length == 4){
const matchValue = textOriginal.match(new RegExp(diagnostic.RawText.split(" ")[0] + " (.{0,100}) " +diagnostic.RawText.split(" ")[3],"ig"));
if (matchValue) {
phrase = matchValue[0];
}
}
else if (diagnostic.RawText.split(" ").length == 1){
const matchValue = textOriginal.match(diagnostic.RawText);
if (matchValue) {
phrase = matchValue[0];
}
}
var indexDiag = this.textAndDiagnosticList.findIndex(obj => obj.rawText == phrase);
const diagnosticEncoded: Diagnostic = {code: diagnostic.CodeId, description: diagnostic.Description, similarity: diagnostic.Similarity}
if (indexDiag == -1)
{
textHTML = textHTML.replace(phrase,"<mark>"+phrase+"</mark>");
let textAndDiagnostic: TextAndDiagnostic = {rawText: phrase, diagnostics: []};
textAndDiagnostic.diagnostics.push(diagnosticEncoded);
this.textAndDiagnosticList.push(textAndDiagnostic);
}
else {
this.textAndDiagnosticList[indexDiag].diagnostics.push(diagnosticEncoded)
}
})
this.textUpdated = textHTML
this.loading = false;
},
error: err => {
this.error = true;
this.loading = false;
}});
}
},
error: err => {
this.error = true;
this.loading = false;
Expand Down
19 changes: 1 addition & 18 deletions src/ENCODER/WS/Service.cls
Original file line number Diff line number Diff line change
Expand Up @@ -156,24 +156,7 @@ ClassMethod AnalyzeText() As %Status
// Creation of BS instance
set status = ##class(Ens.Director).CreateBusinessService("ENCODER.BS.AnalyzeTextService", .instance)
set tSC = instance.SendRequestSync("ENCODER.BP.AnalyzeTextProcess", analysisRequest, .response)

set sql =
"SELECT CodeId, RawText, Description, max(Similarity) as Similarity FROM ENCODER_Object.TextMatches WHERE AnalysisId = ? GROUP BY CodeId ORDER BY Similarity DESC"

set statement = ##class(%SQL.Statement).%New()
$$$ThrowOnError(statement.%Prepare(sql))
set rs = statement.%Execute(response.AnalysisRequestId)

set array = []
while rs.%Next() {
do array.%Push({
"CodeId": (rs.%Get("CodeId")),
"RawText": (rs.%Get("RawText")),
"Description": (rs.%Get("Description")),
"Similarity": (rs.%Get("Similarity"))
})
}
write array.%ToJSON()

set %response.Status = ..#HTTP200OK

} catch ex {
Expand Down

0 comments on commit 3e2f99a

Please sign in to comment.