-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgetSchemaName.m
More file actions
55 lines (46 loc) · 1.7 KB
/
getSchemaName.m
File metadata and controls
55 lines (46 loc) · 1.7 KB
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
function schemaName = getSchemaName(nameAlias)
% getSchemaName - Get name (or type) for a schema given a name alias.
%
% schemaName = openminds.internal.vocab.getSchemaName(nameAlias) returns
% the name (or type) of a Schema given a name alias. A name alias can be
% a variation of the schema name, like a lowercase representation of the
% schema name, or the label for a schema.
%
% Examples:
% openminds.internal.vocab.getSchemaName("person")
% ans =
%
% "Person"
%
% openminds.internal.vocab.getSchemaName("protocol execution")
% ans =
%
% "ProtocolExecution"
persistent typesVocab
if isempty(typesVocab)
typesVocab = openminds.internal.vocab.loadVocabJson("types");
end
C = struct2cell(typesVocab);
allNames = cellfun(@(c) string(c.name), C);
isMatch = strcmpi(allNames, nameAlias);
if ~any(isMatch)
allLabels = cellfun(@(c) string(c.label), C);
isMatch = strcmpi(allLabels, nameAlias);
end
schemaName = string( allNames(isMatch) );
if isscalar(schemaName)
return
elseif isempty(schemaName)
throwEmptySchemaNameException(nameAlias);
else
throwMultipleSchemaNamesException(nameAlias);
end
end
function throwEmptySchemaNameException(schemaAlias)
% THROWEMPTYSCHEMANAMEEXCEPTION Throws an exception for empty schemaName.
error('OPENMINDS:SchemaNameNotFound', 'No schema name matching "%s" was found.', schemaAlias);
end
function throwMultipleSchemaNamesException(schemaAlias)
% THROWMULTIPLESCHEMANAMESEXCEPTION Throws an exception for multiple schemaNames.
error('OPENMINDS:MultipleSchemaNamesFound', 'Multiple schema names matched "%s".', schemaAlias)
end