Wrote the functions of VocabularyItem.cs
This commit is contained in:
parent
26c8e67c33
commit
bed0769995
2 changed files with 41 additions and 9 deletions
|
|
@ -88,7 +88,30 @@ public sealed class Trainer
|
||||||
/// <returns>A <see cref="VocabularyItem"/> for each (valid) word</returns>
|
/// <returns>A <see cref="VocabularyItem"/> for each (valid) word</returns>
|
||||||
private static VocabularyItem[] CreateVocabularyItems(string[][] wordsAndTranslations)
|
private static VocabularyItem[] CreateVocabularyItems(string[][] wordsAndTranslations)
|
||||||
{
|
{
|
||||||
// TODO
|
VocabularyItem[] vocabularyItemsTemp = new VocabularyItem[wordsAndTranslations.Length];
|
||||||
return [];
|
bool[] definedItems = new bool[wordsAndTranslations.Length];
|
||||||
|
int usedItems = 0;
|
||||||
|
for (var i = 0; i < wordsAndTranslations.Length; i++)
|
||||||
|
{
|
||||||
|
if (wordsAndTranslations[i].Length == 2)
|
||||||
|
{
|
||||||
|
usedItems++;
|
||||||
|
definedItems[i] = true;
|
||||||
|
vocabularyItemsTemp[i] = new VocabularyItem(wordsAndTranslations[i][WordIdx], wordsAndTranslations[i][TranslationIdx]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VocabularyItem[] vocabularyItems = new VocabularyItem[usedItems];
|
||||||
|
int j = 0;
|
||||||
|
for (int i = 0; i < wordsAndTranslations.Length; i++)
|
||||||
|
{
|
||||||
|
if (definedItems[i])
|
||||||
|
{
|
||||||
|
vocabularyItems[j] = vocabularyItemsTemp[i];
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return vocabularyItems;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -10,7 +10,7 @@ public sealed class VocabularyItem
|
||||||
public readonly string NativeWord;
|
public readonly string NativeWord;
|
||||||
public readonly string Translation;
|
public readonly string Translation;
|
||||||
|
|
||||||
VocabularyItem(string nativeWord, string translation)
|
public VocabularyItem(string nativeWord, string translation)
|
||||||
{
|
{
|
||||||
NativeWord = nativeWord;
|
NativeWord = nativeWord;
|
||||||
Translation = translation;
|
Translation = translation;
|
||||||
|
|
@ -41,7 +41,18 @@ public sealed class VocabularyItem
|
||||||
/// <returns>0 if equal; less than 0 if this item is smaller; greater than 0 otherwise</returns>
|
/// <returns>0 if equal; less than 0 if this item is smaller; greater than 0 otherwise</returns>
|
||||||
public int CompareTo(VocabularyItem other)
|
public int CompareTo(VocabularyItem other)
|
||||||
{
|
{
|
||||||
return -1;
|
if (_countCorrect == other._countCorrect)
|
||||||
|
{
|
||||||
|
return CompareStrings(NativeWord, other.NativeWord);
|
||||||
|
}
|
||||||
|
else if (_countCorrect < other._countCorrect)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -50,7 +61,7 @@ public sealed class VocabularyItem
|
||||||
/// <returns>A string containing the word, its translation and the training statistics</returns>
|
/// <returns>A string containing the word, its translation and the training statistics</returns>
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return string.Empty;
|
return $"{NativeWord,-10} {Translation,-10} {_countAsked,-5} {_countCorrect,-7}";;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -60,8 +71,6 @@ public sealed class VocabularyItem
|
||||||
/// <param name="b">Second string</param>
|
/// <param name="b">Second string</param>
|
||||||
/// <returns>Less than 0 if a precedes b in the sorting order; greater than 0 if b precedes a; 0 otherwise</returns>
|
/// <returns>Less than 0 if a precedes b in the sorting order; greater than 0 if b precedes a; 0 otherwise</returns>
|
||||||
|
|
||||||
private static int CompareStrings(string a, string b)
|
private static int CompareStrings(string a, string b) => string.Compare(a, b, StringComparison.OrdinalIgnoreCase);
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue