<commit_before>import { CsvService } from "angular2-json2csv";

import { Injectable, EventEmitter } from '@angular/core';

export class Annotation {
  id: string;
  start: number;
  end: number;
  speaker: string;
  caption: string;
  cap_type: string;

  cap_options: Array<string>;

  constructor(id: string,
              start: number, end: number,
              speaker: string, caption: string,
              cap_type: string="text") {
    this.id = id;
    this.start = start;
    this.end = end;
    this.speaker = speaker;
    this.caption = caption;
    this.cap_type = cap_type;

    this.cap_options = [
      "text", "noise"
    ];
  }
}

@Injectable()
export class AnnotatorService {
  annotationsEvent:EventEmitter<any> = new EventEmitter();
  annotationsUpdate:EventEmitter<any> = new EventEmitter();

  audioFile: any;
  audioFileName: string;
  audioFileURL: string;

  annotations: Array<Annotation>;

  selectedAnnotation: Annotation;

  constructor(private csvService: CsvService) {}

  rebase(annotations: Array<Annotation>): any {
    this.annotations = annotations;
    this.selectFirst();
  }

  emitUpdate(): any {
    this.annotationsUpdate.emit({})
  }

  getAnnotations(): any {
    return this.annotations;
  }

  rebuild(segments: any): void {
    this.annotations = [];
    let counter = 0;

    for (let segment of segments) {
      this.createAnnotationFromSegment(
          {
            'id': counter.toString(),
            'start': segment.start,
            'end': segment.end,
          }
        );
      counter += 1;
    }

    this.annotationsEvent.emit({"type":"rebuild"});

    this.selectFirst();
  }

  selectFirst() {
    if (this.annotations.length > 0) {
      this.selectAnnotation(this.annotations[0]);
    }
  }

  createAnnotationFromSegment(segment: any): string {
    this.annotations.push(new Annotation(
      segment['id'],
      segment['start'],
      segment['end'],
      segment['speaker'],
      segment['caption'],
      segment['cap_type']
    ));

    return segment['id'];
  }<commit_msg>Bugfix: Select nothing if no first element available<commit_after>import { CsvService } from "angular2-json2csv";

import { Injectable, EventEmitter } from '@angular/core';

export class Annotation {
  id: string;
  start: number;
  end: number;
  speaker: string;
  caption: string;
  cap_type: string;

  cap_options: Array<string>;

  constructor(id: string,
              start: number, end: number,
              speaker: string, caption: string,
              cap_type: string="text") {
    this.id = id;
    this.start = start;
    this.end = end;
    this.speaker = speaker;
    this.caption = caption;
    this.cap_type = cap_type;

    this.cap_options = [
      "text", "noise"
    ];
  }
}

@Injectable()
export class AnnotatorService {
  annotationsEvent:EventEmitter<any> = new EventEmitter();
  annotationsUpdate:EventEmitter<any> = new EventEmitter();

  audioFile: any;
  audioFileName: string;
  audioFileURL: string;

  annotations: Array<Annotation>;

  selectedAnnotation: Annotation;

  constructor(private csvService: CsvService) {}

  rebase(annotations: Array<Annotation>): any {
    this.annotations = annotations;
    this.selectFirst();
  }

  emitUpdate(): any {
    this.annotationsUpdate.emit({})
  }

  getAnnotations(): any {
    return this.annotations;
  }

  rebuild(segments: any): void {
    this.annotations = [];
    let counter = 0;

    for (let segment of segments) {
      this.createAnnotationFromSegment(
          {
            'id': counter.toString(),
            'start': segment.start,
            'end': segment.end,
          }
        );
      counter += 1;
    }

    this.annotationsEvent.emit({"type":"rebuild"});

    this.selectFirst();
  }

  selectFirst() {
    if (this.annotations.length > 0) {
      this.selectAnnotation(this.annotations[0]);
    } else {
      this.selectAnnotation(null);
    }
  }

  createAnnotationFromSegment(segment: any): string {
    this.annotations.push(new Annotation(
      segment['id'],
      segment['start'],
      segment['end'],
      segment['speaker'],
      segment['caption'],
      segment['cap_type']
    ));

    return segment['id'];
  }
{'fraction_non_alphanumeric': 0.1315101070154578, 'fraction_numerical': 0.002853745541022592, 'mean_word_length': 2.8132366273798732, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1075975', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1254, 'n_words': 269}