Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/badges/code_issues.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion .github/badges/tests.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion code/+openminds/@Collection/saveInstances.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
%buildSingleInstanceFilepath Build filepath for single instance.
%
% Use the @type to create a filepath consisting of a folder hierarchy
% base on the openMINDS model the instance belong to.
% based on the openMINDS module the instance belong to.
%
% Example:
%
Expand Down
16 changes: 16 additions & 0 deletions code/internal/+openminds/+base/ModulesEnumerationBase.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
classdef ModulesEnumerationBase
methods
function types = listTypes(obj)
% listTypes - List types for this module

moduleNamespaceName = lower(string(obj));

types = enumeration( 'openminds.enum.Types' );
classNames = [types.ClassName];
namespacePrefix = sprintf('openminds.%s', moduleNamespaceName);
keep = startsWith( classNames, namespacePrefix);

types = types(keep);
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@
end

methods
function instance = create(obj)
% create - Create a new instance (same as createInstance)
instance = obj.createInstance();
end

function instance = createInstance(obj)
% createInstance - Create a new instance
if numel(obj) == 1

Check notice

Code scanning / Code Analyzer

To improve performance, use 'isscalar' instead of length comparison. Note

To improve performance, use 'isscalar' instead of length comparison.
instance = feval(obj.ClassName);
else
error('Can not create instances for list of types')
end
end

function tf = ismissing(obj)
tf = strcmp(obj.ClassName, 'None');
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ function writeStaticInstanceMethods(obj, instanceTable)

methods (Static)

function instances = getInstancesForSchema(schemaName, modelName)
function instances = getInstancesForSchema(schemaName, moduleName)

% Make singleton class that can be reset...
persistent allInstancesTable
Expand All @@ -975,7 +975,7 @@ function writeStaticInstanceMethods(obj, instanceTable)

% Todo: match on camel case!!!

isRequested = allInstancesTable.ModuleName == modelName & strcmpi(allInstancesTable.SchemaName, schemaName);
isRequested = allInstancesTable.ModuleName == moduleName & strcmpi(allInstancesTable.SchemaName, schemaName);

instances = allInstancesTable(isRequested, :);
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
if startsWith(openmindsType, "https://openminds.om-i.org/types")
className = openminds.enum.Types(schemaName).ClassName;
else
modelName = lower( typeSplit{end-1} );
className = sprintf('openminds.%s.%s', modelName, schemaName);
moduleName = lower( typeSplit{end-1} );
className = sprintf('openminds.%s.%s', moduleName, schemaName);
end
end
18 changes: 9 additions & 9 deletions code/internal/+openminds/+internal/+utility/getSchemaDocLink.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@
isMatch = strcmpi(schemaManifest.Name, string(schemaName));
version = openminds.getModelVersion();

modelName = schemaManifest{isMatch, "Model"};
moduleName = schemaManifest{isMatch, "Module"};
subgroupName = schemaManifest{isMatch, "Group"};
schemaName = schemaManifest{isMatch, "Name"};

if contains(schemaClassName, 'mixedtype')
[~, fragment] = openminds.internal.utility.string.packageParts(schemaClassName);
url = generateDocumentationUrl(version, modelName, subgroupName, schemaName, fragment);
url = generateDocumentationUrl(version, moduleName, subgroupName, schemaName, fragment);
displayLabel = fragment;
else
url = generateDocumentationUrl(version, modelName, subgroupName, schemaName);
url = generateDocumentationUrl(version, moduleName, subgroupName, schemaName);
displayLabel = openminds.internal.utility.getSchemaName(schemaClassName);
end

Expand All @@ -95,9 +95,9 @@
str = sprintf('<a href="matlab:web %s %s" style="font-weight:bold">%s</a>', filepath, browserOption, schemaName);
end

function str = getOnlineHtmlLink(version, modelName, subgroupName, schemaName, browserOption, fragment) %#ok<DEFNU>
function str = getOnlineHtmlLink(version, moduleName, subgroupName, schemaName, browserOption, fragment) %#ok<DEFNU>

filepath = generateDocumentationUrl(version, modelName, subgroupName, schemaName, fragment);
filepath = generateDocumentationUrl(version, moduleName, subgroupName, schemaName, fragment);

str = sprintf('<a href="matlab:web %s %s" style="font-weight:bold">%s</a>', filepath, browserOption, schemaName);
end
Expand All @@ -106,7 +106,7 @@
weblink = sprintf('<a href="matlab:web %s %s" style="font-weight:bold">%s</a>', urlString, browserOption, displayLabel);
end

function urlStr = generateDocumentationUrl(version, modelName, subgroupName, schemaName, fragment)
function urlStr = generateDocumentationUrl(version, moduleName, subgroupName, schemaName, fragment)

if nargin < 5
fragment = '';
Expand All @@ -115,7 +115,7 @@
import openminds.internal.utility.string.uriJoin
BASE_URL = openminds.internal.constants.url.OpenMindsDocumentation;

urlStr = uriJoin(BASE_URL, version, 'schema_specifications', modelName, subgroupName, schemaName);
urlStr = uriJoin(BASE_URL, version, 'schema_specifications', moduleName, subgroupName, schemaName);
urlStr = urlStr + ".html";

if ~isempty(fragment)
Expand All @@ -128,8 +128,8 @@
schemaClass = strrep(schemaClass, 'https://openminds.ebrains.eu/', '');
splitStr = strsplit(schemaClass, '/');

modelName = lower(splitStr{1});
moduleName = lower(splitStr{1});
schemaName = splitStr{2};

schemaClass = strjoin({'openminds', modelName, schemaName}, '.');
schemaClass = strjoin({'openminds', moduleName, schemaName}, '.');
end
36 changes: 18 additions & 18 deletions code/internal/+openminds/+internal/getControlledInstance.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function data = getControlledInstance(instanceName, schemaName, modelName, versionNumber, options)
function data = getControlledInstance(instanceName, schemaName, moduleName, versionNumber, options)

arguments
instanceName (1,1) string
schemaName (1,1) string
modelName (1,1) string = "controlledTerms"
moduleName (1,1) string = "controlledTerms"
versionNumber (1,1) openminds.internal.utility.VersionNumber ...
{openminds.mustBeValidVersion(versionNumber)} = missing
options.FileSource (1,1) string ...
Expand All @@ -23,36 +23,36 @@

if options.FileSource == "local"
try
data = getOfflineInstance(instanceName, schemaName, modelName, versionNumber);
data = getOfflineInstance(instanceName, schemaName, moduleName, versionNumber);
catch
data = getOnlineInstance(instanceName, schemaName, modelName, versionNumber);
data = getOnlineInstance(instanceName, schemaName, moduleName, versionNumber);
end
else
data = getOnlineInstance(instanceName, schemaName, modelName, versionNumber);
data = getOnlineInstance(instanceName, schemaName, moduleName, versionNumber);
end
end

function data = getOnlineInstance(instanceName, schemaName, modelName, versionNumber)
function data = getOnlineInstance(instanceName, schemaName, moduleName, versionNumber)

filePath = getOnlineFilepath(instanceName, schemaName, modelName, versionNumber);
filePath = getOnlineFilepath(instanceName, schemaName, moduleName, versionNumber);
jsonStr = webread(filePath);
data = openminds.internal.utility.json.decode(jsonStr);

% Save instance locally
filePath = getOfflineFilepath(instanceName, schemaName, modelName, versionNumber);
filePath = getOfflineFilepath(instanceName, schemaName, moduleName, versionNumber);
openminds.internal.utility.filewrite(filePath, jsonStr)
end

function data = getOfflineInstance(instanceName, schemaName, modelName, versionNumber)
function data = getOfflineInstance(instanceName, schemaName, moduleName, versionNumber)

% import openminds.internal.listControlledInstances

% instanceTable = listControlledInstances(schemaName, modelName, instanceName);
% instanceTable = listControlledInstances(schemaName, moduleName, instanceName);

% assert(size(instanceTable, 1) == 1, 'Expected a single match for instance "%s", but %d was found.', instanceName, size(instanceTable, 1))
% jsonStr = fileread(instanceTable.Filepath);

filePath = getOfflineFilepath(instanceName, schemaName, modelName, versionNumber);
filePath = getOfflineFilepath(instanceName, schemaName, moduleName, versionNumber);

if ~isfile(filePath)
error('File does not exist')
Expand All @@ -63,26 +63,26 @@
data = openminds.internal.utility.json.decode(jsonStr);
end

function pathStr = getOnlineFilepath(instanceName, schemaName, modelName, versionNumber)
function pathStr = getOnlineFilepath(instanceName, schemaName, moduleName, versionNumber)
import openminds.internal.constants.Github
import openminds.internal.utility.string.uriJoin

fileParts = getRelativeInstanceFileParts(instanceName, schemaName, modelName);
fileParts = getRelativeInstanceFileParts(instanceName, schemaName, moduleName);
relativePath = uriJoin(["main", "instances", versionNumber, fileParts]);
pathStr = Github.getRawFileUrl("instances", relativePath);
end

function pathStr = getOfflineFilepath(instanceName, schemaName, modelName, versionNumber)
function pathStr = getOfflineFilepath(instanceName, schemaName, moduleName, versionNumber)
rootPath = openminds.internal.PathConstants.LocalInstanceFolder;
fileParts = getRelativeInstanceFileParts(instanceName, schemaName, modelName);
fileParts = getRelativeInstanceFileParts(instanceName, schemaName, moduleName);

pathStr = fullfile(rootPath, versionNumber, fileParts{:});
end

function fileParts = getRelativeInstanceFileParts(instanceName, schemaName, modelName)
function fileParts = getRelativeInstanceFileParts(instanceName, schemaName, moduleName)

% Initialize the folder list with foldername given the model
switch modelName
% Initialize the folder list with foldername determined by the module name
switch moduleName
case 'controlledTerms'
folderList = "terminologies";
case 'sands'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
%
% This function returns a table containing information about instances.
% Input arguments can be used to control whether to show instances for
% particular schemas or models.
% particular schemas or modules.
%
% Syntax:
% instances = listControlledInstances() list all available controlled
Expand Down
2 changes: 1 addition & 1 deletion code/internal/+openminds/+internal/listValidVersions.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function validVersions = listValidVersions()
% listValidVersions - List valid versions of the openminds model
% listValidVersions - List valid versions of the openminds metadata model
schemaFolder = fullfile(openminds.internal.rootpath, 'types');
L = dir(schemaFolder);
L(startsWith({L.name}, '.')|~[L.isdir])=[];
Expand Down
9 changes: 5 additions & 4 deletions code/internal/+openminds/+internal/loadSchemaManifest.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
% manifest : A table containing the following variables for each
% schema:
% Name - Name of the schema
% Model - Name of the model the schema belongs to
% Group - Name of the group the schema belongs to. Some models do
% Module - Name of the module the schema belongs to
% Group - Name of the group the schema belongs to. Some modules do
% not have groups, and then this is a blank string.

arguments
Expand All @@ -32,12 +32,13 @@
% Convert data to table and convert columndata to string
manifest = struct2table(data);
manifest.name = string(manifest.name);
manifest.model = string(manifest.model);
manifest.module = string(manifest.module);

isEmptyGroup = cellfun(@isempty, manifest.group(:));
[manifest.group(isEmptyGroup)] = deal({''});

manifest.group = string(manifest.group);

% Rename variables
manifest.Properties.VariableNames = ["Name", "Model", "Group"];
manifest.Properties.VariableNames = ["Name", "Module", "Group"];
end
2 changes: 1 addition & 1 deletion code/internal/+openminds/selectOpenMindsVersion.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function selectOpenMindsVersion(versionNumber)
% selectOpenMindsVersion - Select and "import" a specific version of openMINDS model.
% selectOpenMindsVersion - Select and "import" a specific version of the openMINDS model.
%
% This function allows you to select a specific version of the openMINDS
% metadata model and load its components (classes for metadata types and mixed
Expand Down
Loading