Skip to content

Commit

Permalink
feat(results): added conversions to WebVTT and SRT
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpoemp committed Nov 9, 2020
1 parent ed1e38f commit 36eede9
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 17 deletions.
60 changes: 47 additions & 13 deletions src/app/app.info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
PartiturConverter,
PraatTableConverter,
PraatTextgridConverter,
TextConverter
SRTConverter,
TextConverter,
WebVTTConverter
} from '@octra/annotation';

declare var ohPortalVersion: string;
Expand All @@ -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(),
Expand All @@ -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[];
}
26 changes: 22 additions & 4 deletions src/app/components/results-table/results-table.component.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -137,7 +137,6 @@ export class ResultsTableComponent implements OnChanges {
state: 'PENDING',
result: null
};
convElem.conversions.push(res);

let annotJSON;

Expand All @@ -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;

Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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;
}
}

}

0 comments on commit 36eede9

Please sign in to comment.