dev@74
|
1 import {
|
dev@236
|
2 Component,
|
dev@236
|
3 OnInit,
|
dev@236
|
4 Output,
|
dev@236
|
5 EventEmitter,
|
dev@236
|
6 Input,
|
dev@74
|
7 OnDestroy
|
dev@74
|
8 } from '@angular/core';
|
dev@236
|
9 import {
|
dev@236
|
10 FeatureExtractionService
|
dev@236
|
11 } from '../services/feature-extraction/feature-extraction.service';
|
dev@236
|
12 import {ListResponse} from 'piper';
|
dev@236
|
13 import {Subscription} from 'rxjs/Subscription';
|
dev@44
|
14
|
dev@47
|
15 export interface ExtractorOutputInfo {
|
dev@47
|
16 extractorKey: string;
|
dev@47
|
17 combinedKey: string;
|
dev@47
|
18 outputId: string;
|
dev@44
|
19 name: string;
|
dev@44
|
20 }
|
dev@44
|
21
|
dev@44
|
22 @Component({
|
dev@236
|
23 selector: 'ugly-feature-extraction-menu',
|
dev@44
|
24 templateUrl: './feature-extraction-menu.component.html',
|
dev@44
|
25 styleUrls: ['./feature-extraction-menu.component.css']
|
dev@44
|
26 })
|
dev@74
|
27 export class FeatureExtractionMenuComponent implements OnInit, OnDestroy {
|
dev@44
|
28
|
dev@48
|
29 @Input()
|
dev@48
|
30 set disabled(isDisabled: boolean) {
|
dev@48
|
31 this.isDisabled = isDisabled;
|
dev@48
|
32 }
|
dev@48
|
33
|
dev@48
|
34 get disabled() {
|
dev@48
|
35 return this.isDisabled;
|
dev@48
|
36 }
|
dev@48
|
37
|
dev@47
|
38 @Output() requestOutput: EventEmitter<ExtractorOutputInfo>;
|
dev@47
|
39
|
dev@48
|
40 private isDisabled: boolean;
|
dev@47
|
41 private extractorsMap: Map<string, ExtractorOutputInfo>;
|
dev@74
|
42 private populateExtractors: (available: ListResponse) => void;
|
dev@47
|
43 extractors: Iterable<ExtractorOutputInfo>;
|
dev@74
|
44 private librariesUpdatedSubscription: Subscription;
|
dev@44
|
45
|
dev@44
|
46 constructor(private piperService: FeatureExtractionService) {
|
dev@47
|
47 this.extractorsMap = new Map();
|
dev@44
|
48 this.extractors = [];
|
dev@51
|
49 this.requestOutput = new EventEmitter<ExtractorOutputInfo>();
|
dev@48
|
50 this.isDisabled = true;
|
dev@74
|
51 this.populateExtractors = available => {
|
dev@46
|
52 const maxCharacterLimit = 50;
|
dev@46
|
53 available.available.forEach(staticData => {
|
dev@47
|
54 const isSingleOutputExtractor = staticData.basicOutputInfo.length === 1;
|
dev@47
|
55 staticData.basicOutputInfo.forEach(output => {
|
dev@47
|
56 const combinedKey = `${staticData.key}:${output.identifier}`;
|
dev@47
|
57 this.extractorsMap.set(combinedKey, {
|
dev@47
|
58 extractorKey: staticData.key,
|
dev@47
|
59 combinedKey: combinedKey,
|
dev@47
|
60 name: (
|
dev@47
|
61 isSingleOutputExtractor
|
dev@47
|
62 ? staticData.basic.name
|
dev@47
|
63 : `${staticData.basic.name}: ${output.name}`
|
dev@47
|
64 ).substr(0, maxCharacterLimit) + '...',
|
dev@47
|
65 outputId: output.identifier
|
dev@46
|
66 });
|
dev@47
|
67 });
|
dev@46
|
68 });
|
dev@47
|
69 this.extractors = [...this.extractorsMap.values()];
|
dev@74
|
70 };
|
dev@74
|
71 }
|
dev@74
|
72
|
dev@74
|
73 ngOnInit() {
|
dev@74
|
74 this.piperService.list().then(this.populateExtractors);
|
dev@236
|
75 this.librariesUpdatedSubscription =
|
dev@236
|
76 this.piperService.librariesUpdated$.subscribe(this.populateExtractors);
|
dev@44
|
77 }
|
dev@44
|
78
|
dev@47
|
79 extract(combinedKey: string): void {
|
dev@100
|
80 const info: ExtractorOutputInfo =
|
dev@100
|
81 this.extractorsMap.get(combinedKey);
|
dev@100
|
82 if (info) {
|
dev@100
|
83 this.requestOutput.emit(info);
|
dev@100
|
84 }
|
dev@47
|
85 }
|
dev@47
|
86
|
dev@238
|
87 load(): void {
|
dev@74
|
88 this.piperService.updateAvailableLibraries().subscribe(res => {
|
dev@74
|
89 Object.keys(res).forEach(key => this.piperService.load(key));
|
dev@74
|
90 });
|
dev@74
|
91 }
|
dev@74
|
92
|
dev@74
|
93 ngOnDestroy(): void {
|
dev@74
|
94 this.librariesUpdatedSubscription.unsubscribe();
|
dev@74
|
95 }
|
dev@44
|
96 }
|