From 14d1252b31a57db436eefd5cd3821fbd147f7796 Mon Sep 17 00:00:00 2001 From: ehennestad Date: Fri, 28 Mar 2025 16:59:42 +0100 Subject: [PATCH 1/2] Update TypesEnumeration - Add utility properties / methods --- .../+openminds/+abstract/TypesEnumeration.m | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/code/internal/+openminds/+abstract/TypesEnumeration.m b/code/internal/+openminds/+abstract/TypesEnumeration.m index 49a570cbe..410347a2a 100644 --- a/code/internal/+openminds/+abstract/TypesEnumeration.m +++ b/code/internal/+openminds/+abstract/TypesEnumeration.m @@ -3,12 +3,14 @@ properties (SetAccess=immutable) ClassName (1,1) string AliasClassName (1,1) string + TypeURI (1,1) string end methods function obj = TypesEnumeration(name) obj.ClassName = name; obj.AliasClassName = obj.createAliasClassName(); + obj.TypeURI = obj.getTypeURI(); end end @@ -38,11 +40,18 @@ aliasClassName = strjoin(classNameParts([1,2,end]), '.'); end end + + function typeURI = getTypeURI(obj) + if obj.ClassName == "None" + typeURI = "None"; + else + typeURI = eval(sprintf('%s.X_TYPE', obj.ClassName)); + end + end end methods (Static) function typeEnum = fromClassName(className) - if ischar(className) className = string(className); end @@ -56,5 +65,25 @@ splitName = strsplit(className, '.'); typeEnum = openminds.enum.Types(splitName{end}); end + + function typeEnum = fromAtType(typeName) + % Todo: validate typename... + assert(startsWith(typeName, openminds.constant.BaseURI), ... + 'OPENMINDS_MATLAB:Types:InvalidAtType', ... + 'Expected @type to start with "%s"', openminds.constant.BaseURI) + + if ischar(typeName) + typeName = string(typeName); + end + + if numel(typeName) > 1 + if iscell(typeName); typeName = string(typeName); end + typeEnum = arrayfun(@(str) openminds.enum.Types.fromAtType(str), typeName); + return + end + + splitName = strsplit(typeName, '/'); + typeEnum = eval(sprintf('openminds.enum.Types.%s', splitName{end})); + end end end From 064779e5d83dd0023fc6af99f3a1d47c916ba6c4 Mon Sep 17 00:00:00 2001 From: ehennestad Date: Fri, 28 Mar 2025 17:17:34 +0100 Subject: [PATCH 2/2] Add docstring for static methods --- .../+openminds/+abstract/TypesEnumeration.m | 70 +++++++++++++++---- 1 file changed, 58 insertions(+), 12 deletions(-) diff --git a/code/internal/+openminds/+abstract/TypesEnumeration.m b/code/internal/+openminds/+abstract/TypesEnumeration.m index 410347a2a..9f478580b 100644 --- a/code/internal/+openminds/+abstract/TypesEnumeration.m +++ b/code/internal/+openminds/+abstract/TypesEnumeration.m @@ -52,12 +52,35 @@ methods (Static) function typeEnum = fromClassName(className) - if ischar(className) - className = string(className); + % fromClassName - Get a Type enum from a class name + % + % Syntax: + % typeEnum = openminds.enum.Types.fromClassName(className) Converts + % the provided class name(s) into the appropriate enumeration value (s). + % + % Input Arguments: + % className - A string array representing the class name(s) to be + % converted. + % + % Output Arguments: + % typeEnum - The corresponding enumeration value(s) from + % openminds.enum.Types. + % + % Example: + % + % openminds.enum.Types.fromClassName("openminds.core.Person") + % + % ans = + % + % Types enumeration + % + % Person + + arguments + className (1,:) string end if numel(className) > 1 - if iscell(className); className = string(className); end typeEnum = arrayfun(@(str) openminds.enum.Types.fromClassName(str), className); return end @@ -67,21 +90,44 @@ end function typeEnum = fromAtType(typeName) - % Todo: validate typename... - assert(startsWith(typeName, openminds.constant.BaseURI), ... + % fromAtType - Convert an @type string to its corresponding enumeration. + % + % Syntax: + % typeEnum = openminds.enum.Types.fromAtType(typeName) Converts the + % provided @type string into the appropriate enumeration value. + % + % Input Arguments: + % typeName - A string array representing the @type to be converted. + % The @type URI is expected to match Base URI for the + % currently active openMINDS version + % + % Output Arguments: + % typeEnum - The corresponding enumeration value(s) from + % openminds.enum.Types. + % + % Example: + % + % openminds.enum.Types.fromAtType("https://openminds.om-i.org/types/Person") + % + % ans = + % + % Types enumeration + % + % Person + + arguments + typeName (1,:) string + end + + assert(all(startsWith(typeName, openminds.constant.BaseURI)), ... 'OPENMINDS_MATLAB:Types:InvalidAtType', ... 'Expected @type to start with "%s"', openminds.constant.BaseURI) - - if ischar(typeName) - typeName = string(typeName); - end - + if numel(typeName) > 1 - if iscell(typeName); typeName = string(typeName); end typeEnum = arrayfun(@(str) openminds.enum.Types.fromAtType(str), typeName); return end - + splitName = strsplit(typeName, '/'); typeEnum = eval(sprintf('openminds.enum.Types.%s', splitName{end})); end