-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathconfig.model.ts
299 lines (280 loc) · 10.5 KB
/
config.model.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
import {Tag} from '../../../core/selection/tag.model';
import {FeatureCategories} from '../results/feature-categories.model';
import {QuerySettings} from './query-settings.model';
import * as DEEPMERGE from 'deepmerge';
import {MetadataAccessSpecification} from '../messages/queries/metadata-access-specification.model';
import {MetadataType} from '../messages/queries/metadata-type.model';
import {InputType} from '../../../query/containers/bool/bool-attribute';
export class Config {
/** Context of the Cineast API. */
public static readonly CONTEXT = 'api';
/** Version of the Cineast API. */
public static readonly VERSION = 'v1';
/** Default display duration for Snackbar messages. */
public static SNACKBAR_DURATION = 2500;
_config = {
title: 'vitrivr',
api: {
host: window.location.hostname, /* IP address or hostname (no scheme), pointing to the API endpoint; defaults to hostname of window. */
port: 4567, /* Port for the API. */
http_secure: false, /* Whether or not TLS should be used for HTTP connection. */
ws_secure: false, /* Whether or not TLS should be used for WebSocket connection. */
ping_interval: 5000 /* Default ping interval in milliseconds. */
},
resources: {
/** Path / URL to location where media object thumbnails will be stored. */
host_thumbnails: window.location.protocol + '//' + window.location.hostname + ':4567/thumbnails/:s',
/** Path / URL to location where media object's will be stored. */
host_objects: window.location.protocol + '//' + window.location.hostname + ':4567/objects/:o',
/** Default suffix for thumbnails. */
suffix_default: '.jpg',
/** Per-mediatype suffix definition for thumbnails. */
suffix: {
'IMAGE': 'png',
'VIDEO': 'png'
}
},
competition: {
/* Toggles VBS mode; determines type of information that is submitted. */
vbs: false,
/* Toggles LSC mode; determines type of information that is submitted. */
lsc: false,
/* Host of the DRES endpoint (fqn + port, no protocol). */
host: '',
/* Flag indicating whether or not TLS should be used to communicate with DRES. */
tls: false,
/* Flag indicating whether or not logging (interaction & results) should be enabled. */
log: false,
/* The timer interval at which logs are submitted to the competition server. */
loginterval: 5000,
/* URL to the Collabordinator endpoint. */
collabordinator: null,
/* if textual submissions should be enabled */
textualInput: false
},
tags: [
new Tag('Red', 0),
new Tag('Orange', 30),
new Tag('Blue', 240),
new Tag('Violet', 270),
new Tag('Magenta', 300),
],
mlt: {
'MODEL3D': ['sphericalharmonicsdefault'],
'IMAGE': ['mlt'],
'VIDEO': ['mlt'],
'AUDIO': ['audiofingerprint'],
'IMAGE_SEQUENCE': ['mlt']
},
query: {
history: -1,
scoreFunction: 'average', // the scoring function to use in SEGMENT and OBJECT view
temporalView: true, // Activate or deactivate temporal scoring (view) at all
options: {
image: true,
audio: false,
model3d: false,
text: true,
tag: false,
map: false,
semantic: true,
boolean: true,
skeleton: false
},
metadata: {
object: [
['*', '*']
],
segment: [
['*', '*']
]
},
config: {
queryId: null,
neighboringSegmentLookupCount: 5,
neighboringSegmentLookupAllCount: 200000
},
text: {
categories: [['visualtextcoembedding', 'Description (VTE)'], ['ocr', 'OCR']]
},
boolean: [
{
display: 'Segment Id',
input: InputType.TEXT,
table: 'cineast_segment',
col: 'segmentid',
operators: [
'='
]
},
{
display: 'Object Id',
input: InputType.TEXT,
table: 'cineast_segment',
col: 'objectid',
operators: [
'='
]
}
],
temporal_mode: 'TEMPORAL_DISTANCE',
enableTagPrioritisation: false,
temporal_max_length: 600,
default_temporal_distance: 10
},
refinement: {
filters: [
['dominantcolor.color', 'CHECKBOX'],
['technical.duration', 'SLIDER']
],
showMetadataInViewer: false
}
};
/**
* Default constructor for configuration object. The different configuration type can be passed to this constructor and the will be merged with
* the default configuration.
*
* @param title Optional title for the application as, e.g. loaded from a file.
* @param api Optional Cineast API configuration as, e.g. loaded from a file.
* @param resources Optional resources configuration as, e.g. loaded from a file.
* @param query Optional query configuration, e.g. loaded from a file.
* @param competition Optional competition configuration as, e.g. loaded from a file.
* @param tags Optional tag configurations as, e.g. loaded from a file.
* @param mlt Optional More-Like-This categories as, e.g. loaded from a file.
* @param refinement Optional refinement configuration
*/
constructor(title?: string, api?: any, resources?: any, query?: QuerySettings, competition?: any, tags?: Tag[], mlt?: FeatureCategories[], refinement?: any) {
const overwriteMerge = (destinationArray, sourceArray, options) => sourceArray;
if (title) {
this._config.title = title;
}
if (api) {
this._config.api = DEEPMERGE(this._config.api, api, {arrayMerge: overwriteMerge});
}
if (resources) {
this._config.resources = DEEPMERGE(this._config.resources, resources, {arrayMerge: overwriteMerge});
}
if (query) {
this._config.query = DEEPMERGE(this._config.query, query, {arrayMerge: overwriteMerge});
}
if (competition) {
this._config.competition = DEEPMERGE(this._config.competition, competition, {arrayMerge: overwriteMerge});
}
if (tags) {
this._config.tags = DEEPMERGE(this._config.tags, tags, {arrayMerge: overwriteMerge});
}
if (mlt) {
this._config.mlt = DEEPMERGE(this._config.mlt, mlt, {arrayMerge: overwriteMerge});
}
if (refinement) {
this._config.refinement = DEEPMERGE(this._config.refinement, refinement, {arrayMerge: overwriteMerge});
}
if (this._config.api.host === '$host') {
this._config.api.host = window.location.hostname
}
this._config.resources.host_objects = this._config.resources.host_objects.replace('/$host/', '/' + window.location.hostname + '/');
this._config.resources.host_thumbnails = this._config.resources.host_thumbnails.replace('/$host/', '/' + window.location.hostname + '/');
}
/**
* Returns URL to WebSocket endpoint for Vitrivr NG.
*/
get cineastEndpointWs(): string {
const scheme = this._config.api.ws_secure ? 'wss://' : 'ws://';
if (this._config.api.host && this._config.api.port) {
return scheme + this._config.api.host + ':' + this._config.api.port + '/' + Config.CONTEXT + '/' + Config.VERSION + '/websocket';
} else {
return null;
}
}
/**
* Based on the config, this returns the REST API endpoint.
* Fully qualified with the schema (if secured, this is HTTPS, otherwise HTTP)
* the host and the port.
*/
get cineastEndpointRest(): string {
const scheme = this._config.api.http_secure ? 'https://' : 'http://';
if (this._config.api.host && this._config.api.port) {
return scheme + this._config.api.host + ':' + this._config.api.port;
} else {
return null;
}
}
/**
* Full URL to HTTP/HTTPs RESTful endpoint for DRES.
*/
get dresEndpointRest() {
const scheme = this._config.competition.tls ? 'https://' : 'http://';
if (this._config.competition.host) {
return `${scheme}${this._config.competition.host}`
} else {
return null;
}
}
get metadataAccessSpec(): MetadataAccessSpecification[] {
let spec: MetadataAccessSpecification[] = []
this._config.query.metadata.object.forEach(el => spec.push(new MetadataAccessSpecification(MetadataType.OBJECT, el[0], el[1])))
this._config.query.metadata.segment.forEach(el => spec.push(new MetadataAccessSpecification(MetadataType.SEGMENT, el[0], el[1])))
return spec;
}
/**
* Deserializes a Config object from a given JavaScript object or string.
*
* @param {{} | string} object The object that should be parsed.
* @return {Config} The resulting config object.
*/
public static deserialize(object: {} | string): Config {
if (typeof object === 'string') {
object = JSON.parse(object);
}
if (object['api'] || object['resources'] || object['query'] || object['competition'] || object['tags'] || object['mlt'] || object['refinement']) {
return new Config(object['title'], object['api'], object['resources'], object['query'], object['competition'], object['tags'], object['mlt'], object['refinement']);
} else {
return null;
}
}
/**
* Accesses and returns the config value specified by the given path. Path components are separated by a '.'
* If the value does not exist, then null is returned!
*
* @param {string} path Path relative to this._config; components separated by '.'
* @return {T | null} The config value at the given path or null.
*/
public get<T>(path: string): T {
try {
const separator = '.';
const components = path.replace('[', separator).replace(']', '').split(separator);
return components.reduce((obj, property) => obj[property], this._config);
} catch (err) {
return null;
}
}
/**
* Replaces the config value specified by the given path by the value provided. Path components are separated by a '.'
*
* @param {string} path Path relative to this._config; components separated by '.'
* @param {T} value New value
* @return true on success, false if the path does not exist.
*/
public set<T>(path: string, value: T): boolean {
try {
const separator = '.';
const components = path.replace('[', separator).replace(']', '').split(separator);
const last = components[components.length - 1];
const obj = components.reduce((_obj, property) => {
if (property === last) {
return _obj
} else {
return _obj[property]
}
}, this._config);
if (obj[last] && typeof value === typeof obj[last]) {
obj[last] = value;
return true;
} else {
return false;
}
} catch (err) {
return false;
}
}
}