Skip to content

Commit

Permalink
fix(annotation): full name instead of name set on AnnotJSON on format…
Browse files Browse the repository at this point in the history
… import
  • Loading branch information
julianpoemp committed Feb 28, 2024
1 parent 6ce2c75 commit 0419bd4
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 13 deletions.
11 changes: 11 additions & 0 deletions libs/annotation/src/lib/annotjson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export interface IAudioFile {
export class OAnnotJSON
implements IAnnotJSON, Serializable<IAnnotJSON, OAnnotJSON>
{
/**
* name of the annotation file WITHOUT extension
*/
name = '';
annotates = '';
sampleRate;
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion libs/annotation/src/lib/converters/AnnotJSONConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libs/annotation/src/lib/converters/CTMConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class CTMConverter extends Converter {

const result = new OAnnotJSON(
audiofile.name,
file.name,
this.getFileName(file.name),
audiofile.sampleRate
);

Expand Down
12 changes: 12 additions & 0 deletions libs/annotation/src/lib/converters/Converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, '\\.') + '$'),
''
);
}
}
2 changes: 1 addition & 1 deletion libs/annotation/src/lib/converters/ELANConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class ELANConverter extends Converter {

result.annotjson = new OAnnotJSON(
audiofile.name,
file.name,
this.getFileName(file.name),
audiofile.sampleRate
);

Expand Down
2 changes: 1 addition & 1 deletion libs/annotation/src/lib/converters/PartiturConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ LBD:\n`;

const result = new OAnnotJSON(
audiofile.name,
file.name,
this.getFileName(file.name),
audiofile.sampleRate
);
const tiers: any = {};
Expand Down
2 changes: 1 addition & 1 deletion libs/annotation/src/lib/converters/PraatTableConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down
5 changes: 1 addition & 4 deletions libs/annotation/src/lib/converters/PraatTextgridConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion libs/annotation/src/lib/converters/SRTConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down
2 changes: 1 addition & 1 deletion libs/annotation/src/lib/converters/TextConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class TextConverter extends Converter {

const result = new OAnnotJSON(
audiofile.name,
file.name,
this.getFileName(file.name),
audiofile.sampleRate,
[],
[]
Expand Down
2 changes: 1 addition & 1 deletion libs/annotation/src/lib/converters/WebVTTConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`));
Expand Down
2 changes: 1 addition & 1 deletion libs/annotation/src/lib/converters/WhisperJSONConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class WhisperJSONConverter extends Converter {

result.annotjson = new OAnnotJSON(
audiofile.name,
file.name,
this.getFileName(file.name),
audiofile.sampleRate
);

Expand Down

0 comments on commit 0419bd4

Please sign in to comment.