diff --git a/libs/annotation/package.json b/libs/annotation/package.json index 4f3d4821e..86c04e268 100644 --- a/libs/annotation/package.json +++ b/libs/annotation/package.json @@ -1,6 +1,6 @@ { "name": "@octra/annotation", - "version": "0.1.3", + "version": "0.1.4", "type": "module", "peerDependencies": { "x2js": "^3.4.4" diff --git a/libs/annotation/project.json b/libs/annotation/project.json index 3e86740ee..fb833f869 100644 --- a/libs/annotation/project.json +++ b/libs/annotation/project.json @@ -6,7 +6,6 @@ "targets": { "build": { "executor": "@nrwl/rollup:rollup", - "dependsOn": ["media"], "outputs": [ "{options.outputPath}" ], diff --git a/libs/annotation/src/lib/annotjson.ts b/libs/annotation/src/lib/annotjson.ts index c887de852..d91126d66 100644 --- a/libs/annotation/src/lib/annotjson.ts +++ b/libs/annotation/src/lib/annotjson.ts @@ -126,7 +126,7 @@ export class OAnnotJSON } static deserialize(jsonObject: IAnnotJSON): OAnnotJSON | undefined { - if(jsonObject) { + if (jsonObject) { return new OAnnotJSON( jsonObject.annotates, jsonObject.name, @@ -135,7 +135,7 @@ export class OAnnotJSON jsonObject.links ); } - return undefined + return undefined; } deserialize(jsonObject: IAnnotJSON): OAnnotJSON | undefined { @@ -155,7 +155,11 @@ export class OLevel implements ILevel { } clone() { - return new OLevel(this.name, this.type, this.items.map(a => a.clone())); + return new OLevel( + this.name, + this.type, + this.items.map((a) => a.clone()) + ); } } @@ -280,6 +284,10 @@ export class OItem implements IItem, Serializable { return new OItem(jsonObject.id, jsonObject.labels); } + getFirstLabelWithoutName(notName: string) { + return this.labels?.find((a) => a.name !== notName); + } + clone(id?: number) { return new OItem(id ?? this.id, [...this.labels]); } @@ -413,7 +421,7 @@ export class OLink implements ILink, Serializable { return new OLink(jsonObject.fromID, jsonObject.toID); } - clone(){ + clone() { return new OLink(this.fromID, this.toID); } } diff --git a/libs/annotation/src/lib/converters/CTMConverter.ts b/libs/annotation/src/lib/converters/CTMConverter.ts index 8decc4737..0560a61f6 100644 --- a/libs/annotation/src/lib/converters/CTMConverter.ts +++ b/libs/annotation/src/lib/converters/CTMConverter.ts @@ -63,7 +63,8 @@ export class CTMConverter extends Converter { const level = annotation.levels[levelnum]; for (const levelItem of level.items as OSegment[]) { - const transcript = levelItem.labels[0].value; + const transcript = + levelItem.getFirstLabelWithoutName('Speaker')?.value ?? ''; const start = Math.round((levelItem.sampleStart! / audiofile.sampleRate) * 100) / 100; const duration = diff --git a/libs/annotation/src/lib/converters/ELANConverter.ts b/libs/annotation/src/lib/converters/ELANConverter.ts index 21dc1ddfc..3ffdbdca2 100644 --- a/libs/annotation/src/lib/converters/ELANConverter.ts +++ b/libs/annotation/src/lib/converters/ELANConverter.ts @@ -111,7 +111,7 @@ export class ELANConverter extends Converter { ALIGNABLE_ANNOTATION: { _ANNOTATION_ID: `a${aidCounter}`, ANNOTATION_VALUE: - segment.labels.find((a) => a.name !== 'Speaker')?.value ?? '', + segment.getFirstLabelWithoutName('Speaker')?.value ?? '', _TIME_SLOT_REF1: `ts${tsidCounter - 1}`, _TIME_SLOT_REF2: `ts${tsidCounter}`, }, diff --git a/libs/annotation/src/lib/converters/PartiturConverter.ts b/libs/annotation/src/lib/converters/PartiturConverter.ts index dda606a55..7ed35220b 100644 --- a/libs/annotation/src/lib/converters/PartiturConverter.ts +++ b/libs/annotation/src/lib/converters/PartiturConverter.ts @@ -70,9 +70,9 @@ LBD:\n`; let ortCounter = 0; for (const item of annotation.levels[levelnum].items as OSegment[]) { - const words = item.labels - .filter((a) => a.name !== 'Speaker')[0] - .value.split(' '); + const words = ( + item.getFirstLabelWithoutName('Speaker')?.value ?? '' + ).split(' '); ort = ort.concat(words); let trnLine = `TRN: ${item.sampleStart} ${item.sampleDur} `; @@ -84,7 +84,7 @@ LBD:\n`; } ortCounter += words.length; trnLine += ` ${ - item.labels.filter((a) => a.name !== 'Speaker')[0].value + item.getFirstLabelWithoutName('Speaker')?.value ?? '' }\n`; trn.push(trnLine); } diff --git a/libs/annotation/src/lib/converters/PraatTableConverter.ts b/libs/annotation/src/lib/converters/PraatTableConverter.ts index 47e575aa2..b050a46c4 100644 --- a/libs/annotation/src/lib/converters/PraatTableConverter.ts +++ b/libs/annotation/src/lib/converters/PraatTableConverter.ts @@ -6,7 +6,6 @@ import { OctraAnnotationFormatType, } from './Converter'; import { - ISegment, OAnnotJSON, OAnyLevel, OLabel, @@ -47,14 +46,13 @@ export class PraatTableConverter extends Converter { const addEntry = ( res: string, level: OAnyLevel, - segment: ISegment + segment: OSegment ) => { const tmin = segment.sampleStart / annotation.sampleRate; const tmax = (segment.sampleStart + segment.sampleDur) / annotation.sampleRate; - const transcript = segment.labels.find( - (a) => a.name !== 'Speaker' - )?.value; + const transcript = + segment.getFirstLabelWithoutName('Speaker')?.value ?? ''; return `${res}${tmin}\t${level.name}\t${transcript}\t${tmax}\n`; }; @@ -64,8 +62,8 @@ export class PraatTableConverter extends Converter { for (const level of annotation.levels) { // export segments only if (level.type === 'SEGMENT') { - for (const segment of level.items) { - result = addEntry(result, level, segment as ISegment); + for (const segment of level.items as OSegment[]) { + result = addEntry(result, level, segment); } } } diff --git a/libs/annotation/src/lib/converters/PraatTextgridConverter.ts b/libs/annotation/src/lib/converters/PraatTextgridConverter.ts index c56d763a1..8d5e7e702 100644 --- a/libs/annotation/src/lib/converters/PraatTextgridConverter.ts +++ b/libs/annotation/src/lib/converters/PraatTextgridConverter.ts @@ -99,7 +99,7 @@ export class PraatTextgridConverter extends Converter { ` xmin = ${secondsStart} \n` + ` xmax = ${secondsEnd} \n` + ` text = "${ - segment.labels.find((a) => a.name !== 'Speaker')?.value + segment.getFirstLabelWithoutName('Speaker')?.value ?? '' }" \n`; } } diff --git a/libs/annotation/src/lib/converters/SRTConverter.ts b/libs/annotation/src/lib/converters/SRTConverter.ts index 60ecaae24..c28cf2782 100644 --- a/libs/annotation/src/lib/converters/SRTConverter.ts +++ b/libs/annotation/src/lib/converters/SRTConverter.ts @@ -86,7 +86,8 @@ export class SRTConverter extends Converter { let counter = 1; if (level.type === 'SEGMENT') { for (const item of level.items as OSegment[]) { - const transcript = item.labels[0].value; + const transcript = + item.getFirstLabelWithoutName('Speaker')?.value ?? ''; const start = this.getTimeStringFromSamples( item.sampleStart, annotation.sampleRate diff --git a/libs/annotation/src/lib/converters/TextConverter.ts b/libs/annotation/src/lib/converters/TextConverter.ts index 0981d58ce..abe2da6de 100644 --- a/libs/annotation/src/lib/converters/TextConverter.ts +++ b/libs/annotation/src/lib/converters/TextConverter.ts @@ -65,7 +65,8 @@ export class TextConverter extends Converter { if (level.type === 'SEGMENT') { for (let j = 0; j < level.items.length; j++) { const item = level.items[j] as OSegment; - const transcript = item.labels[0].value; + const transcript = + item.getFirstLabelWithoutName('Speaker')?.value ?? ''; result += transcript; if (j < level.items.length - 1) { diff --git a/libs/annotation/src/lib/converters/WebVTTConverter.ts b/libs/annotation/src/lib/converters/WebVTTConverter.ts index 85fa862b4..223e87ab7 100644 --- a/libs/annotation/src/lib/converters/WebVTTConverter.ts +++ b/libs/annotation/src/lib/converters/WebVTTConverter.ts @@ -63,7 +63,9 @@ export class WebVTTConverter extends Converter { if (level.type === 'SEGMENT') { for (let j = 0; j < level.items.length; j++) { const item = level.items[j] as OSegment; - const transcript = item.labels[0].value + const transcript = ( + item.getFirstLabelWithoutName('Speaker')?.value ?? '' + ) .replace(//g, '>'); const start = this.getTimeStringFromSamples( diff --git a/libs/annotation/src/lib/octraAnnotationSegment.ts b/libs/annotation/src/lib/octraAnnotationSegment.ts index 8d95875c5..a42e9c883 100644 --- a/libs/annotation/src/lib/octraAnnotationSegment.ts +++ b/libs/annotation/src/lib/octraAnnotationSegment.ts @@ -49,6 +49,10 @@ export class OctraAnnotationEvent ...this.labels, ]); } + + getFirstLabelWithoutName(notName: string) { + return this.labels?.find((a) => a.name !== notName); + } } export class OctraAnnotationSegment