From 36eede945510e11318a11cfa973b9a43f06a2357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20P=C3=B6mp?= Date: Mon, 9 Nov 2020 18:57:32 +0100 Subject: [PATCH] feat(results): added conversions to WebVTT and SRT --- src/app/app.info.ts | 60 +++++++++++++++---- .../results-table/results-table.component.ts | 26 ++++++-- 2 files changed, 69 insertions(+), 17 deletions(-) diff --git a/src/app/app.info.ts b/src/app/app.info.ts index c5b1c0a..1fee270 100644 --- a/src/app/app.info.ts +++ b/src/app/app.info.ts @@ -5,7 +5,9 @@ import { PartiturConverter, PraatTableConverter, PraatTextgridConverter, - TextConverter + SRTConverter, + TextConverter, + WebVTTConverter } from '@octra/annotation'; declare var ohPortalVersion: string; @@ -20,17 +22,22 @@ export class AppInfo { return this._version; } - private static _converters: { - obj: Converter; - color: string; - }[] = [ + private static _converters: ConverterData[] = [ { obj: new CTMConverter(), - color: 'red' + color: 'red', + tierNameMatches: [ + '^TRN$', + '^OCTRA' + ] }, { obj: new PartiturConverter(), - color: 'forestgreen' + color: 'forestgreen', + tierNameMatches: [ + '^TRN$', + '^OCTRA' + ] }, { obj: new AnnotJSONConverter(), @@ -42,18 +49,45 @@ export class AppInfo { }, { obj: new PraatTableConverter(), - color: 'purple' + color: 'purple', + tierNameMatches: [ + '^TRN$', + '^OCTRA' + ] }, { obj: new TextConverter(), - color: 'darkblue' + color: 'darkblue', + tierNameMatches: [ + '^TRN$', + '^OCTRA' + ] + }, + { + obj: new SRTConverter(), + color: 'pink', + tierNameMatches: [ + '^TRN$', + '^OCTRA' + ] + }, + { + obj: new WebVTTConverter(), + color: 'black', + tierNameMatches: [ + '^TRN$', + '^OCTRA' + ] } ]; - static get converters(): { - obj: Converter, - color: string - }[] { + static get converters(): ConverterData[] { return this._converters; } } + +export interface ConverterData { + obj: Converter; + color: string; + tierNameMatches?: string[]; +} diff --git a/src/app/components/results-table/results-table.component.ts b/src/app/components/results-table/results-table.component.ts index 817c728..8ae88e9 100644 --- a/src/app/components/results-table/results-table.component.ts +++ b/src/app/components/results-table/results-table.component.ts @@ -1,10 +1,10 @@ import {ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, Output, SimpleChanges} from '@angular/core'; import {Operation} from '../../obj/operations/operation'; -import {AppInfo} from '../../app.info'; +import {AppInfo, ConverterData} from '../../app.info'; import {HttpClient} from '@angular/common/http'; import {DomSanitizer} from '@angular/platform-browser'; import {FileInfo, isUnset} from '@octra/utilities'; -import {Converter, IFile, OAudiofile} from '@octra/annotation'; +import {Converter, IFile, OAnnotJSON, OAudiofile} from '@octra/annotation'; import {AudioInfo} from '@octra/media'; @Component({ @@ -137,7 +137,6 @@ export class ResultsTableComponent implements OnChanges { state: 'PENDING', result: null }; - convElem.conversions.push(res); let annotJSON; @@ -156,7 +155,7 @@ export class ResultsTableComponent implements OnChanges { annotJSON = JSON.parse(text); } - const levelnum = 0; + const levelnum = this.getLevelNumforConverter(converter, annotJSON); let preResult = null; @@ -177,6 +176,7 @@ export class ResultsTableComponent implements OnChanges { const url = URL.createObjectURL(expFile); res.result.url = this.sanitizer.bypassSecurityTrustUrl(url); res.state = 'FINISHED'; + convElem.conversions.push(res); } } } @@ -243,4 +243,22 @@ export class ResultsTableComponent implements OnChanges { } } + private getLevelNumforConverter(converterData: ConverterData, annotJSON: OAnnotJSON) { + if (!isUnset(converterData.tierNameMatches)) { + for (const tierNameMatch of converterData.tierNameMatches) { + const regex = new RegExp(tierNameMatch, 'g'); + + for (let i = 0; i < annotJSON.levels.length; i++) { + const level = annotJSON.levels[i]; + if (regex.exec(level.name) !== null) { + return i; + } + } + } + return -1; + } else { + return 0; + } + } + }