Mercurial > hg > ugly-duckling
comparison src/app/feature-extraction-menu/feature-extraction-menu.component.ts @ 441:55e17af8a0ee
Small refactor.
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Mon, 26 Jun 2017 11:00:21 +0100 |
parents | 8f658642d031 |
children | 51a5df5569a4 |
comparison
equal
deleted
inserted
replaced
440:8f658642d031 | 441:55e17af8a0ee |
---|---|
9 import { | 9 import { |
10 FeatureExtractionService | 10 FeatureExtractionService |
11 } from '../services/feature-extraction/feature-extraction.service'; | 11 } from '../services/feature-extraction/feature-extraction.service'; |
12 import {ListResponse} from 'piper'; | 12 import {ListResponse} from 'piper'; |
13 import {Subscription} from 'rxjs/Subscription'; | 13 import {Subscription} from 'rxjs/Subscription'; |
14 import {HigherLevelFeatureShape} from "../visualisations/FeatureUtilities"; | 14 import {HigherLevelFeatureShape} from '../visualisations/FeatureUtilities'; |
15 | 15 |
16 export interface ExtractorOutputInfo { | 16 export interface ExtractorOutputInfo { |
17 extractorKey: string; | 17 extractorKey: string; |
18 combinedKey: string; | 18 combinedKey: string; |
19 outputId: string; | 19 outputId: string; |
20 name: string; | 20 name: string; |
21 iconName?: string; | 21 typeUri?: string; |
22 } | 22 } |
23 | 23 |
24 interface ExtractorInfo { | 24 interface ExtractorInfo { |
25 name: string; | 25 name: string; |
26 outputs: ExtractorOutputInfo[]; | 26 outputs: ExtractorOutputInfo[]; |
37 'http://purl.org/ontology/af/TonalOnset': 'instants', | 37 'http://purl.org/ontology/af/TonalOnset': 'instants', |
38 'http://purl.org/ontology/af/Note': 'notes', | 38 'http://purl.org/ontology/af/Note': 'notes', |
39 'http://purl.org/ontology/af/ChordSegment': 'instants', | 39 'http://purl.org/ontology/af/ChordSegment': 'instants', |
40 'http://purl.org/ontology/af/MusicSegment': 'instants', | 40 'http://purl.org/ontology/af/MusicSegment': 'instants', |
41 'http://purl.org/ontology/af/Pitch': 'tracks' | 41 'http://purl.org/ontology/af/Pitch': 'tracks' |
42 }; | |
43 | |
44 const featureIconMap = { | |
45 vector: 'show_chart', | |
46 matrix: 'grid_on', | |
47 tracks: 'multiline_chart', | |
48 instants: 'view_week', | |
49 notes: 'audiotrack', | |
50 }; | 42 }; |
51 | 43 |
52 @Component({ | 44 @Component({ |
53 selector: 'ugly-feature-extraction-menu', | 45 selector: 'ugly-feature-extraction-menu', |
54 templateUrl: './feature-extraction-menu.component.html', | 46 templateUrl: './feature-extraction-menu.component.html', |
82 this.extractors = available.available.reduce((acc, staticData) => { | 74 this.extractors = available.available.reduce((acc, staticData) => { |
83 const name = staticData.basic.name; | 75 const name = staticData.basic.name; |
84 const outputs: ExtractorOutputInfo[] = | 76 const outputs: ExtractorOutputInfo[] = |
85 staticData.basicOutputInfo.map(output => { | 77 staticData.basicOutputInfo.map(output => { |
86 const combinedKey = `${staticData.key}:${output.identifier}`; | 78 const combinedKey = `${staticData.key}:${output.identifier}`; |
87 const hasTypeInfo = staticData.staticOutputInfo && | 79 const maybeTypeInfo = staticData.staticOutputInfo && |
88 staticData.staticOutputInfo.get(output.identifier) && | 80 staticData.staticOutputInfo.get(output.identifier) && |
89 staticData.staticOutputInfo.get(output.identifier).typeURI; | 81 staticData.staticOutputInfo.get(output.identifier).typeURI; |
90 const getIcon = () => featureIconMap[crudeTypeUriMap[ | |
91 staticData.staticOutputInfo.get(output.identifier).typeURI | |
92 ]]; | |
93 const hasIcon = hasTypeInfo && getIcon(); | |
94 return Object.assign({ | 82 return Object.assign({ |
95 extractorKey: staticData.key, | 83 extractorKey: staticData.key, |
96 combinedKey: combinedKey, | 84 combinedKey: combinedKey, |
97 name: output.name, | 85 name: output.name, |
98 outputId: output.identifier | 86 outputId: output.identifier |
99 }, | 87 }, |
100 hasIcon ? {iconName: getIcon()} : {} | 88 maybeTypeInfo ? {typeUri: maybeTypeInfo} : {} |
101 ); | 89 ); |
102 }); | 90 }); |
103 acc.push({name, outputs}); | 91 acc.push({name, outputs}); |
104 return acc; | 92 return acc; |
105 }, [] as ExtractorInfo[]); | 93 }, [] as ExtractorInfo[]); |
125 load(): void { | 113 load(): void { |
126 this.isLoading = true; | 114 this.isLoading = true; |
127 this.piperService.updateAvailableLibraries(); | 115 this.piperService.updateAvailableLibraries(); |
128 } | 116 } |
129 | 117 |
118 getFeatureIconName(outputInfo: ExtractorOutputInfo): string { | |
119 const featureIconMap = { | |
120 vector: 'show_chart', | |
121 matrix: 'grid_on', | |
122 tracks: 'multiline_chart', | |
123 instants: 'view_week', | |
124 notes: 'audiotrack', | |
125 }; | |
126 const maybeIcon = featureIconMap[crudeTypeUriMap[outputInfo.typeUri]]; | |
127 return maybeIcon ? maybeIcon : 'extension'; | |
128 } | |
129 | |
130 ngOnDestroy(): void { | 130 ngOnDestroy(): void { |
131 this.librariesUpdatedSubscription.unsubscribe(); | 131 this.librariesUpdatedSubscription.unsubscribe(); |
132 } | 132 } |
133 } | 133 } |