<commit_before>import { Component, Input, OnChanges, OnDestroy, OnInit } from '@angular/core';
import { ContentItem } from '../shared/model/content-item';
import { EditPageConfig } from '../../core/shared/model/edit-page-config';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import { isNullOrUndefined } from 'util';
import 'rxjs/add/operator/startWith';

@Component({
  selector: 'app-content-metadata',
  templateUrl: './content-metadata.component.html',
  styleUrls: ['./content-metadata.component.css']
})
export class ContentMetadataComponent implements OnInit, OnChanges, OnDestroy {
  private componentDestroyed = new Subject();

  @Input() pageConfig: EditPageConfig;
  @Input() contentItem$: Observable<ContentItem>;
  @Input() formGroup: FormGroup;

  contentItem: ContentItem;

  constructor() {}

  ngOnInit() {
    this.contentItem$.takeUntil(this.componentDestroyed).subscribe(item => {
      this.contentItem = item;
      this.ngOnChanges();
    });
    this.createForm();
    this.ngOnChanges();
  }

  private createForm() {
    this.formGroup.setControl('metadata', this.generateDisplayedMetadataGroup());
    this.formGroup.setControl('label', new FormControl('', Validators.required));
    this.formGroup.get('label').disable();
  }

  private filterOptions(name: string, options: any[]) {
    return options.filter(option => option.toLowerCase().indexOf(name.toLowerCase()) === 0);
  }

  private generateDisplayedMetadataGroup(): FormGroup {
    const group: any = {};
    this.pageConfig.fieldsToDisplay.map(field => {
      if (field.type === 'typeahead' && field.options && field.options.length > 0) {
        field.filteredOptions = new Observable<any[]>();<commit_msg>support match in the middle as well<commit_after>import { Component, Input, OnChanges, OnDestroy, OnInit } from '@angular/core';
import { ContentItem } from '../shared/model/content-item';
import { EditPageConfig } from '../../core/shared/model/edit-page-config';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import { isNullOrUndefined } from 'util';
import 'rxjs/add/operator/startWith';

@Component({
  selector: 'app-content-metadata',
  templateUrl: './content-metadata.component.html',
  styleUrls: ['./content-metadata.component.css']
})
export class ContentMetadataComponent implements OnInit, OnChanges, OnDestroy {
  private componentDestroyed = new Subject();

  @Input() pageConfig: EditPageConfig;
  @Input() contentItem$: Observable<ContentItem>;
  @Input() formGroup: FormGroup;

  contentItem: ContentItem;

  constructor() {}

  ngOnInit() {
    this.contentItem$.takeUntil(this.componentDestroyed).subscribe(item => {
      this.contentItem = item;
      this.ngOnChanges();
    });
    this.createForm();
    this.ngOnChanges();
  }

  private createForm() {
    this.formGroup.setControl('metadata', this.generateDisplayedMetadataGroup());
    this.formGroup.setControl('label', new FormControl('', Validators.required));
    this.formGroup.get('label').disable();
  }

  private filterOptions(name: string, options: any[]) {
    return options.filter(option => option.toLowerCase().indexOf(name.toLowerCase()) >= 0);
  }

  private generateDisplayedMetadataGroup(): FormGroup {
    const group: any = {};
    this.pageConfig.fieldsToDisplay.map(field => {
      if (field.type === 'typeahead' && field.options && field.options.length > 0) {
        field.filteredOptions = new Observable<any[]>();
{'fraction_non_alphanumeric': 0.15111478117258464, 'fraction_numerical': 0.0011010184420589045, 'mean_word_length': 4.651632970451011, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 16, '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': '4331898', 'n_tokens_mistral': 1037, 'n_tokens_neox': 1024, 'n_words': 219}