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@497
|
12 import {ListResponse} from 'piper-js/core';
|
dev@236
|
13 import {Subscription} from 'rxjs/Subscription';
|
dev@441
|
14 import {HigherLevelFeatureShape} from '../visualisations/FeatureUtilities';
|
dev@44
|
15
|
dev@47
|
16 export interface ExtractorOutputInfo {
|
dev@47
|
17 extractorKey: string;
|
dev@47
|
18 combinedKey: string;
|
dev@47
|
19 outputId: string;
|
dev@44
|
20 name: string;
|
dev@441
|
21 typeUri?: string;
|
dev@44
|
22 }
|
dev@44
|
23
|
dev@423
|
24 interface ExtractorInfo {
|
dev@423
|
25 name: string;
|
dev@423
|
26 outputs: ExtractorOutputInfo[];
|
dev@423
|
27 }
|
dev@423
|
28
|
dev@440
|
29 const crudeTypeUriMap: {[key: string]: HigherLevelFeatureShape} = {
|
dev@440
|
30 'http://purl.org/ontology/af/Beat': 'instants',
|
dev@440
|
31 'http://purl.org/ontology/af/Chromagram': 'matrix',
|
dev@440
|
32 'http://purl.org/ontology/af/Spectrogram': 'matrix',
|
dev@440
|
33 'http://purl.org/ontology/af/KeyChange': 'instants',
|
dev@440
|
34 'http://purl.org/ontology/af/OnsetDetectionFunction': 'vector',
|
dev@440
|
35 'http://purl.org/ontology/af/Onset': 'instants',
|
dev@440
|
36 'http://purl.org/ontology/af/StructuralSegment': 'instants',
|
dev@440
|
37 'http://purl.org/ontology/af/TonalOnset': 'instants',
|
dev@440
|
38 'http://purl.org/ontology/af/Note': 'notes',
|
dev@440
|
39 'http://purl.org/ontology/af/ChordSegment': 'instants',
|
dev@440
|
40 'http://purl.org/ontology/af/MusicSegment': 'instants',
|
dev@440
|
41 'http://purl.org/ontology/af/Pitch': 'tracks'
|
dev@440
|
42 };
|
dev@440
|
43
|
dev@44
|
44 @Component({
|
dev@236
|
45 selector: 'ugly-feature-extraction-menu',
|
dev@44
|
46 templateUrl: './feature-extraction-menu.component.html',
|
dev@44
|
47 styleUrls: ['./feature-extraction-menu.component.css']
|
dev@44
|
48 })
|
dev@74
|
49 export class FeatureExtractionMenuComponent implements OnInit, OnDestroy {
|
dev@44
|
50
|
dev@48
|
51 @Input()
|
dev@48
|
52 set disabled(isDisabled: boolean) {
|
dev@48
|
53 this.isDisabled = isDisabled;
|
dev@48
|
54 }
|
dev@48
|
55
|
dev@48
|
56 get disabled() {
|
dev@48
|
57 return this.isDisabled;
|
dev@48
|
58 }
|
dev@426
|
59 @Input() onRequestOutput: () => void;
|
dev@48
|
60
|
dev@47
|
61 @Output() requestOutput: EventEmitter<ExtractorOutputInfo>;
|
dev@47
|
62
|
dev@48
|
63 private isDisabled: boolean;
|
dev@74
|
64 private populateExtractors: (available: ListResponse) => void;
|
dev@423
|
65 extractors: Iterable<ExtractorInfo>;
|
dev@74
|
66 private librariesUpdatedSubscription: Subscription;
|
dev@433
|
67 private isLoading: boolean;
|
dev@44
|
68
|
dev@44
|
69 constructor(private piperService: FeatureExtractionService) {
|
dev@44
|
70 this.extractors = [];
|
dev@51
|
71 this.requestOutput = new EventEmitter<ExtractorOutputInfo>();
|
dev@48
|
72 this.isDisabled = true;
|
dev@74
|
73 this.populateExtractors = available => {
|
dev@423
|
74 this.extractors = available.available.reduce((acc, staticData) => {
|
dev@423
|
75 const name = staticData.basic.name;
|
dev@423
|
76 const outputs: ExtractorOutputInfo[] =
|
dev@423
|
77 staticData.basicOutputInfo.map(output => {
|
dev@423
|
78 const combinedKey = `${staticData.key}:${output.identifier}`;
|
dev@441
|
79 const maybeTypeInfo = staticData.staticOutputInfo &&
|
dev@440
|
80 staticData.staticOutputInfo.get(output.identifier) &&
|
dev@440
|
81 staticData.staticOutputInfo.get(output.identifier).typeURI;
|
dev@440
|
82 return Object.assign({
|
dev@440
|
83 extractorKey: staticData.key,
|
dev@440
|
84 combinedKey: combinedKey,
|
dev@440
|
85 name: output.name,
|
dev@440
|
86 outputId: output.identifier
|
dev@440
|
87 },
|
dev@441
|
88 maybeTypeInfo ? {typeUri: maybeTypeInfo} : {}
|
dev@440
|
89 );
|
dev@46
|
90 });
|
dev@423
|
91 acc.push({name, outputs});
|
dev@423
|
92 return acc;
|
dev@423
|
93 }, [] as ExtractorInfo[]);
|
dev@433
|
94 this.isLoading = false;
|
dev@74
|
95 };
|
dev@74
|
96 }
|
dev@74
|
97
|
dev@74
|
98 ngOnInit() {
|
dev@236
|
99 this.librariesUpdatedSubscription =
|
dev@236
|
100 this.piperService.librariesUpdated$.subscribe(this.populateExtractors);
|
dev@324
|
101 this.piperService.list().then(this.populateExtractors);
|
dev@44
|
102 }
|
dev@44
|
103
|
dev@423
|
104 extract(info: ExtractorOutputInfo): void {
|
dev@426
|
105 if (this.onRequestOutput) {
|
dev@426
|
106 this.onRequestOutput();
|
dev@426
|
107 }
|
dev@431
|
108 if (info && !this.disabled) {
|
dev@100
|
109 this.requestOutput.emit(info);
|
dev@100
|
110 }
|
dev@47
|
111 }
|
dev@47
|
112
|
dev@238
|
113 load(): void {
|
dev@433
|
114 this.isLoading = true;
|
dev@324
|
115 this.piperService.updateAvailableLibraries();
|
dev@74
|
116 }
|
dev@74
|
117
|
dev@441
|
118 getFeatureIconName(outputInfo: ExtractorOutputInfo): string {
|
dev@442
|
119 return {
|
dev@441
|
120 vector: 'show_chart',
|
dev@441
|
121 matrix: 'grid_on',
|
dev@441
|
122 tracks: 'multiline_chart',
|
dev@441
|
123 instants: 'view_week',
|
dev@441
|
124 notes: 'audiotrack',
|
dev@442
|
125 }[crudeTypeUriMap[outputInfo.typeUri]] || 'extension';
|
dev@441
|
126 }
|
dev@441
|
127
|
dev@74
|
128 ngOnDestroy(): void {
|
dev@74
|
129 this.librariesUpdatedSubscription.unsubscribe();
|
dev@74
|
130 }
|
dev@44
|
131 }
|