autoStrings Strings_append (Collection me) { try { long index = 1, numberOfStrings = 0; for (long i = 1; i <= my size; i++) { Strings s = (Strings) my item[i]; numberOfStrings += s -> numberOfStrings; } autoStrings thee = Strings_createFixedLength (numberOfStrings); for (long i = 1; i <= my size; i++) { Strings s = (Strings) my item[i]; for (long j = 1; j <= s -> numberOfStrings; j++, index++) { if (s -> strings[j] == 0) { continue; } thy strings [index] = Melder_dup (s -> strings[j]); } } return thee; } catch (MelderError) { Melder_throw (me, U": not appended."); } }
autoStrings strings_to_Strings_link (char32 **strings, long n) { try { autoStrings me = Strings_createFixedLength (n); for (long i = 1; i <= n; i++) { my strings[i] = strings[i]; } return me; } catch (MelderError) { Melder_throw (U"Strings not linked."); } }
autoStrings strings_to_Strings (char32 **strings, long from, long to) { try { autoStrings thee = Strings_createFixedLength (to - from + 1); for (long i = from; i <= to; i++) { thy strings[i - from + 1] = Melder_dup (strings[i]); } return thee; } catch (MelderError) { Melder_throw (U"Strings not created."); } }
autoStrings StringsIndex_to_Strings (StringsIndex me) { try { autoStrings thee = Strings_createFixedLength (my numberOfElements); for (long i = 1; i <= thy numberOfStrings; i++) { SimpleString s = (SimpleString) my classes -> item[my classIndex[i]]; thy strings[i] = Melder_dup (s -> string); } return thee; } catch (MelderError) { Melder_throw (me, U": no Strings created."); } }
autoStrings Strings_and_Permutation_permuteStrings (Strings me, Permutation thee) { try { if (my numberOfStrings != thy numberOfElements) Melder_throw (U"Strings_and_Permutation_permuteStrings: " U"The number of strings and the number of elements in the Permutation must be equal."); autoStrings him = Strings_createFixedLength (my numberOfStrings); for (long i = 1; i <= thy numberOfElements; i++) { long index = thy p[i]; his strings[i] = Melder_dup (my strings[index]); } return him; } catch (MelderError) { Melder_throw (me, U": no permuted Strings created."); } }
Strings ClassificationTable_to_Strings_maximumProbability (ClassificationTable me) { try { autoStrings thee = Strings_createFixedLength (my numberOfRows); for (long i = 1; i <= my numberOfRows; i++) { double max = my data[i][1]; long col = 1; for (long j = 2; j <= my numberOfColumns; j++) { if (my data[i][j] > max) { max = my data[i][j]; col = j; } } if (my columnLabels[col] != 0) { Strings_replace (thee.peek(), i, my columnLabels[col]); } } return thee.transfer(); } catch (MelderError) { Melder_throw (me, U": strings cannot be created."); } }
autoStrings Strings_append (OrderedOf<structStrings>* me) { try { long index = 1, numberOfStrings = 0; for (long i = 1; i <= my size; i ++) { Strings s = my at [i]; numberOfStrings += s -> numberOfStrings; } autoStrings thee = Strings_createFixedLength (numberOfStrings); for (long i = 1; i <= my size; i ++) { Strings s = my at [i]; for (long j = 1; j <= s -> numberOfStrings; j ++, index ++) { thy strings [index] = Melder_dup (s -> strings [j]); } } return thee; } catch (MelderError) { Melder_throw (me, U": not appended."); } }