Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Jan 4, 2025
1 parent 0e2affa commit 2d0f17d
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 62 deletions.
2 changes: 1 addition & 1 deletion JL.Core/Dicts/EPWING/Nazeka/EpwingNazekaDBManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace JL.Core.Dicts.EPWING.Nazeka;

internal static class EpwingNazekaDBManager
{
public const int Version = 3;
public const int Version = 4;

private const string SingleTermQuery =
"""
Expand Down
2 changes: 1 addition & 1 deletion JL.Core/Dicts/JMdict/JmdictDBManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace JL.Core.Dicts.JMdict;

internal static class JmdictDBManager
{
public const int Version = 2;
public const int Version = 3;

public static void CreateDB(string dbName)
{
Expand Down
46 changes: 28 additions & 18 deletions JL.Core/Dicts/JMdict/JmdictRecordBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics;
using JL.Core.Utilities;

namespace JL.Core.Dicts.JMdict;
Expand Down Expand Up @@ -117,16 +118,16 @@ public static void AddToDictionary(JmdictEntry entry, IDictionary<string, IList<
allSpellingsWithoutSearchOnlyForms.RemoveAt(index),
allKanjiOrthographyInfoWithoutSearchOnlyForms.RemoveAt(index),
readingList.TrimListToArray(),
readingsOrthographyInfoList.TrimListOfNullableArraysToArrayOfArrays(),
spellingRestrictionList.TrimListOfNullableArraysToArrayOfArrays(),
readingRestrictionList.TrimListOfNullableArraysToArrayOfArrays(),
fieldList.TrimListOfNullableArraysToArrayOfArrays(),
miscList.TrimListOfNullableArraysToArrayOfArrays(),
readingsOrthographyInfoList.TrimListWithNullableElementsToArray(),
spellingRestrictionList.TrimListWithNullableElementsToArray(),
readingRestrictionList.TrimListWithNullableElementsToArray(),
fieldList.TrimListWithNullableElementsToArray(),
miscList.TrimListWithNullableElementsToArray(),
definitionInfoList.TrimListWithNullableElementsToArray(),
dialectList.TrimListOfNullableArraysToArrayOfArrays(),
loanwordSourceList.TrimListOfNullableArraysToArrayOfArrays(),
relatedTermList.TrimListOfNullableArraysToArrayOfArrays(),
antonymList.TrimListOfNullableArraysToArrayOfArrays());
dialectList.TrimListWithNullableElementsToArray(),
loanwordSourceList.TrimListWithNullableElementsToArray(),
relatedTermList.TrimListWithNullableElementsToArray(),
antonymList.TrimListWithNullableElementsToArray());

recordDictionary.Add(key, record);

Expand Down Expand Up @@ -223,10 +224,19 @@ public static void AddToDictionary(JmdictEntry entry, IDictionary<string, IList<
{
Sense sense = entry.SenseList[j];

if (sense.StagKList.Count is not 0 && sense.StagRList.Count is not 0
&& !sense.StagRList.Contains(readingElement.Reb)
&& !sense.StagKList.Contains(primarySpelling)
&& alternativeSpellings is not null && sense.StagKList.Intersect(alternativeSpellings).Any())
{
Debug.WriteLine("This should not happen.");
}

if ((sense.StagKList.Count is 0 && sense.StagRList.Count is 0)
|| sense.StagRList.Contains(readingElement.Reb)
|| sense.StagKList.Contains(primarySpelling)
|| (alternativeSpellings is not null && sense.StagKList.Intersect(alternativeSpellings).Any()))
// || (alternativeSpellings is not null && sense.StagKList.Intersect(alternativeSpellings).Any())
)
{
definitionList.Add(sense.GlossList.ToArray());
wordClassList.Add(sense.PosList.ToArray());
Expand All @@ -251,15 +261,15 @@ public static void AddToDictionary(JmdictEntry entry, IDictionary<string, IList<
alternativeSpellingsOrthographyInfo,
readings,
readingsOrthographyInfo,
spellingRestrictionList.TrimListOfNullableArraysToArrayOfArrays(),
readingRestrictionList.TrimListOfNullableArraysToArrayOfArrays(),
fieldList.TrimListOfNullableArraysToArrayOfArrays(),
miscList.TrimListOfNullableArraysToArrayOfArrays(),
spellingRestrictionList.TrimListWithNullableElementsToArray(),
readingRestrictionList.TrimListWithNullableElementsToArray(),
fieldList.TrimListWithNullableElementsToArray(),
miscList.TrimListWithNullableElementsToArray(),
definitionInfoList.TrimListWithNullableElementsToArray(),
dialectList.TrimListOfNullableArraysToArrayOfArrays(),
loanwordSourceList.TrimListOfNullableArraysToArrayOfArrays(),
relatedTermList.TrimListOfNullableArraysToArrayOfArrays(),
antonymList.TrimListOfNullableArraysToArrayOfArrays());
dialectList.TrimListWithNullableElementsToArray(),
loanwordSourceList.TrimListWithNullableElementsToArray(),
relatedTermList.TrimListWithNullableElementsToArray(),
antonymList.TrimListWithNullableElementsToArray());

// record.Priorities = kanjiElement.KePriList

Expand Down
2 changes: 1 addition & 1 deletion JL.Core/Dicts/JMnedict/JmnedictDBManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace JL.Core.Dicts.JMnedict;

internal static class JmnedictDBManager
{
public const int Version = 1;
public const int Version = 2;

public static void CreateDB(string dbName)
{
Expand Down
88 changes: 47 additions & 41 deletions JL.Core/Utilities/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ internal static void AddRange<T>(this ConcurrentBag<T> source, IEnumerable<T> it
return null;
}

bool allElementsAreNull = true;
for (int i = 0; i < source.Length; i++)
{
if (i != index && source[i] is not null)
{
allElementsAreNull = false;
break;
}
}

if (allElementsAreNull)
{
return null;
}

T[] destination = new T[source.Length - 1];
if (index > 0)
{
Expand All @@ -108,6 +123,21 @@ internal static void AddRange<T>(this ConcurrentBag<T> source, IEnumerable<T> it
return null;
}

bool allElementsAreNull = true;
for (int i = 0; i < list.Count; i++)
{
if (i != index && list[i] is not null)
{
allElementsAreNull = false;
break;
}
}

if (allElementsAreNull)
{
return null;
}

T[] array = new T[list.Count - 1];

int arrayIndex = 0;
Expand All @@ -124,55 +154,31 @@ internal static void AddRange<T>(this ConcurrentBag<T> source, IEnumerable<T> it
return array;
}

//internal static T?[]? RemoveAtToArrayNullable<T>(this List<T?> list, int index) where T : class
//{
// ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(index, list.Count);

// if (list.Count is 1 || list.All(static l => l is null))
// {
// return null;
// }

// T?[] array = new T?[list.Count - 1];

// bool hasNonNullElement = false;
// int arrayIndex = 0;
// int listCount = list.Count;
// for (int i = 0; i < listCount; i++)
// {
// if (i != index)
// {
// T? element = list[i];
// array[arrayIndex] = element;
// ++arrayIndex;

// if (element is not null)
// {
// hasNonNullElement = true;
// }
// }
// }

// return hasNonNullElement ? array : null;
//}

internal static T[]? TrimListToArray<T>(this List<T> list)
internal static T[]? TrimListToArray<T>(this List<T> list) where T : notnull
{
return list.Count is 0
? null
: list.ToArray();
}

internal static T[]?[]? TrimListOfNullableArraysToArrayOfArrays<T>(this List<T[]?> list)
{
return list.Count is 0 || list.All(static array => array is null)
? null
: list.ToArray();
}

internal static T?[]? TrimListWithNullableElementsToArray<T>(this List<T?> list) where T : class
{
return list.Count is 0 || list.All(static element => element is null)
if (list.Count is 0)
{
return null;
}

bool allElementsAreNull = true;
for (int i = 0; i < list.Count; i++)
{
if (list[i] is not null)
{
allElementsAreNull = false;
break;
}
}

return allElementsAreNull
? null
: list.ToArray();
}
Expand Down

0 comments on commit 2d0f17d

Please sign in to comment.