diff --git a/SaveTranscriptions.m b/SaveTranscriptions.m index 9c35e810f2d8b0c654f530a81184220e83847e5b..d4b6bbd3e6357805a5a31c0a88c8868e70bd0d85 100644 --- a/SaveTranscriptions.m +++ b/SaveTranscriptions.m @@ -3,7 +3,7 @@ % Prepare work space clc -checkVersion() +% checkVersion() % Check for miscelaneous transcriptions in the work space miscLS = who('-regexp', '^ls(([0-9]*$)|($))'); @@ -109,6 +109,16 @@ function lss = TransferLabels(ls, lss) % Clear lss labels resetLabelValues(lss) +% Update lss labels to match ls +subLabelList = split(strtrim(extract(labelDefinitionsHierarchy(lss), regexpPattern('(?<=Sublabels:).*')))); +lsSubLabelList = split(strtrim(extract(labelDefinitionsHierarchy(ls), regexpPattern('(?<=Sublabels:).*')))); +isNewLabel = ~contains(lsSubLabelList, subLabelList); + +if any(isNewLabel) + curLabelDef = getLabelDefinitions(ls); + addLabelDefinitions(lss, curLabelDef.Sublabels(isNewLabel), curLabelDef.Name) +end + % Move ls labels to lss nTrials = height(ls.Labels); for iTrial = 1:nTrials @@ -122,10 +132,22 @@ for iTrial = 1:nTrials setLabelValue(lss, iTrial, 'Words', curROI, curVal) % Set sublabel Values - subLabelList = split(strtrim(extract(labelDefinitionsHierarchy(lss), regexpPattern('(?<=Sublabels:).*')))); - for curLabel = subLabelList' - setLabelValue(lss, iTrial, ["Words", string(curLabel)], ls.Labels.Words{1}.Sublabels.(curLabel{1}), 'LabelRowIndex', 1) + curSpans = ls.Labels.Words{iTrial}; + nSpans = height(curSpans); + for iSpan = 1:nSpans + for curLabel = lsSubLabelList' + labelValues = ls.Labels.Words{iTrial}.Sublabels.(curLabel{1}); + + if isa(labelValues, 'cell') + labelValue = labelValues{iSpan}; + else + labelValue = labelValues(iSpan); + end + + setLabelValue(lss, iTrial, ["Words", string(curLabel)], labelValue, "LabelRowIndex", iSpan) + end end + end end