From 0419bd4a21079eb2dc5e4ea617680090f0fce919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20P=C3=B6mp?= Date: Wed, 28 Feb 2024 16:07:39 +0100 Subject: [PATCH] fix(annotation): full name instead of name set on AnnotJSON on format import --- libs/annotation/src/lib/annotjson.ts | 11 +++++++++++ .../src/lib/converters/AnnotJSONConverter.ts | 2 +- libs/annotation/src/lib/converters/CTMConverter.ts | 2 +- libs/annotation/src/lib/converters/Converter.ts | 12 ++++++++++++ libs/annotation/src/lib/converters/ELANConverter.ts | 2 +- .../src/lib/converters/PartiturConverter.ts | 2 +- .../src/lib/converters/PraatTableConverter.ts | 2 +- .../src/lib/converters/PraatTextgridConverter.ts | 5 +---- libs/annotation/src/lib/converters/SRTConverter.ts | 2 +- libs/annotation/src/lib/converters/TextConverter.ts | 2 +- .../annotation/src/lib/converters/WebVTTConverter.ts | 2 +- .../src/lib/converters/WhisperJSONConverter.ts | 2 +- 12 files changed, 33 insertions(+), 13 deletions(-) diff --git a/libs/annotation/src/lib/annotjson.ts b/libs/annotation/src/lib/annotjson.ts index 5b77d6e98..9347818fc 100644 --- a/libs/annotation/src/lib/annotjson.ts +++ b/libs/annotation/src/lib/annotjson.ts @@ -69,6 +69,9 @@ export interface IAudioFile { export class OAnnotJSON implements IAnnotJSON, Serializable { + /** + * name of the annotation file WITHOUT extension + */ name = ''; annotates = ''; sampleRate; @@ -88,6 +91,14 @@ export class OAnnotJSON return Math.max(1, last(this.levels.map((a, i) => i + 1))!); } + /** + * initiates a new AnnotJSON object + * @param annotates + * @param name file name WITHOUT extension + * @param sampleRate + * @param levels + * @param links + */ constructor( annotates: string, name: string, diff --git a/libs/annotation/src/lib/converters/AnnotJSONConverter.ts b/libs/annotation/src/lib/converters/AnnotJSONConverter.ts index 103816972..214fbbe1c 100644 --- a/libs/annotation/src/lib/converters/AnnotJSONConverter.ts +++ b/libs/annotation/src/lib/converters/AnnotJSONConverter.ts @@ -42,7 +42,7 @@ export class AnnotJSONConverter extends Converter { if (audiofile) { let result = new OAnnotJSON( audiofile.name, - file.name, + this.getFileName(file.name), audiofile.sampleRate ); const content = file.content; diff --git a/libs/annotation/src/lib/converters/CTMConverter.ts b/libs/annotation/src/lib/converters/CTMConverter.ts index 0560a61f6..796040636 100644 --- a/libs/annotation/src/lib/converters/CTMConverter.ts +++ b/libs/annotation/src/lib/converters/CTMConverter.ts @@ -103,7 +103,7 @@ export class CTMConverter extends Converter { const result = new OAnnotJSON( audiofile.name, - file.name, + this.getFileName(file.name), audiofile.sampleRate ); diff --git a/libs/annotation/src/lib/converters/Converter.ts b/libs/annotation/src/lib/converters/Converter.ts index 251b66fe4..563f798fa 100644 --- a/libs/annotation/src/lib/converters/Converter.ts +++ b/libs/annotation/src/lib/converters/Converter.ts @@ -114,4 +114,16 @@ export abstract class Converter { * returns object with an annotjson or an error. */ public abstract import(file: IFile, audiofile: OAudiofile): ImportResult; + + /** + * removes the extension of the current convert from the filename + * @param fullname + * @protected + */ + protected getFileName(fullname: string) { + return fullname.replace( + new RegExp(this._extension.replace(/\./g, '\\.') + '$'), + '' + ); + } } diff --git a/libs/annotation/src/lib/converters/ELANConverter.ts b/libs/annotation/src/lib/converters/ELANConverter.ts index b58c8b936..bee5c66b0 100644 --- a/libs/annotation/src/lib/converters/ELANConverter.ts +++ b/libs/annotation/src/lib/converters/ELANConverter.ts @@ -154,7 +154,7 @@ export class ELANConverter extends Converter { result.annotjson = new OAnnotJSON( audiofile.name, - file.name, + this.getFileName(file.name), audiofile.sampleRate ); diff --git a/libs/annotation/src/lib/converters/PartiturConverter.ts b/libs/annotation/src/lib/converters/PartiturConverter.ts index 7ed35220b..ad45e6273 100644 --- a/libs/annotation/src/lib/converters/PartiturConverter.ts +++ b/libs/annotation/src/lib/converters/PartiturConverter.ts @@ -125,7 +125,7 @@ LBD:\n`; const result = new OAnnotJSON( audiofile.name, - file.name, + this.getFileName(file.name), audiofile.sampleRate ); const tiers: any = {}; diff --git a/libs/annotation/src/lib/converters/PraatTableConverter.ts b/libs/annotation/src/lib/converters/PraatTableConverter.ts index b050a46c4..6173c2545 100644 --- a/libs/annotation/src/lib/converters/PraatTableConverter.ts +++ b/libs/annotation/src/lib/converters/PraatTableConverter.ts @@ -102,7 +102,7 @@ export class PraatTableConverter extends Converter { const lines: string[] = content.split('\n'); // check if filename is equal with audio file - const filename = file.name.substr(0, file.name.indexOf('.Table')); + const filename = this.getFileName(file.name); if (contains(audiofile.name, filename)) { const tiers: string[] = []; diff --git a/libs/annotation/src/lib/converters/PraatTextgridConverter.ts b/libs/annotation/src/lib/converters/PraatTextgridConverter.ts index 8d5e7e702..e3c972900 100644 --- a/libs/annotation/src/lib/converters/PraatTextgridConverter.ts +++ b/libs/annotation/src/lib/converters/PraatTextgridConverter.ts @@ -130,10 +130,7 @@ export class PraatTextgridConverter extends Converter { } const name = audiofile.name.substr(0, audiofile.name.lastIndexOf('.')); - const fileName = - file.name.indexOf('.') > -1 - ? file.name.substr(0, file.name.lastIndexOf('.')) - : file.name; + const fileName = this.getFileName(file.name); if (name === fileName) { const result = new OAnnotJSON( audiofile.name, diff --git a/libs/annotation/src/lib/converters/SRTConverter.ts b/libs/annotation/src/lib/converters/SRTConverter.ts index c28cf2782..1e00d7d70 100644 --- a/libs/annotation/src/lib/converters/SRTConverter.ts +++ b/libs/annotation/src/lib/converters/SRTConverter.ts @@ -143,7 +143,7 @@ export class SRTConverter extends Converter { if (audiofile) { const result = new OAnnotJSON( audiofile.name, - file.name, + this.getFileName(file.name), audiofile.sampleRate ); diff --git a/libs/annotation/src/lib/converters/TextConverter.ts b/libs/annotation/src/lib/converters/TextConverter.ts index abe2da6de..8cc3fba58 100644 --- a/libs/annotation/src/lib/converters/TextConverter.ts +++ b/libs/annotation/src/lib/converters/TextConverter.ts @@ -144,7 +144,7 @@ export class TextConverter extends Converter { const result = new OAnnotJSON( audiofile.name, - file.name, + this.getFileName(file.name), audiofile.sampleRate, [], [] diff --git a/libs/annotation/src/lib/converters/WebVTTConverter.ts b/libs/annotation/src/lib/converters/WebVTTConverter.ts index 223e87ab7..f942d2f2e 100644 --- a/libs/annotation/src/lib/converters/WebVTTConverter.ts +++ b/libs/annotation/src/lib/converters/WebVTTConverter.ts @@ -121,7 +121,7 @@ export class WebVTTConverter extends Converter { } const result = new OAnnotJSON( audiofile.name, - file.name, + this.getFileName(file.name), audiofile.sampleRate ); result.levels.push(new OSegmentLevel(`OCTRA_1`)); diff --git a/libs/annotation/src/lib/converters/WhisperJSONConverter.ts b/libs/annotation/src/lib/converters/WhisperJSONConverter.ts index 7bc2920f5..20fc28cf6 100644 --- a/libs/annotation/src/lib/converters/WhisperJSONConverter.ts +++ b/libs/annotation/src/lib/converters/WhisperJSONConverter.ts @@ -54,7 +54,7 @@ export class WhisperJSONConverter extends Converter { result.annotjson = new OAnnotJSON( audiofile.name, - file.name, + this.getFileName(file.name), audiofile.sampleRate );