Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Oct 17, 2024
1 parent 4cee121 commit 483ccba
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 55 deletions.
10 changes: 5 additions & 5 deletions JL.Core/Dicts/JMdict/JmdictEntry.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace JL.Core.Dicts.JMdict;

internal ref struct JmdictEntry()
internal readonly ref struct JmdictEntry(int id, List<KanjiElement> kanjiElements, List<ReadingElement> readingElements, List<Sense> senseList)
{
public int Id { get; set; } = 0;
public List<KanjiElement> KanjiElements { get; } = [];
public List<ReadingElement> ReadingElements { get; } = [];
public List<Sense> SenseList { get; } = [];
public int Id { get; } = id;
public List<KanjiElement> KanjiElements { get; } = kanjiElements;
public List<ReadingElement> ReadingElements { get; } = readingElements;
public List<Sense> SenseList { get; } = senseList;
}
72 changes: 44 additions & 28 deletions JL.Core/Dicts/JMdict/JmdictLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ public static async Task Load(Dict dict)

private static JmdictEntry ReadEntry(XmlTextReader xmlReader)
{
JmdictEntry entry = new();
int id = 0;
List<KanjiElement> kanjiElements = [];
List<ReadingElement> readingElements = [];
List<Sense> senseList = [];

_ = xmlReader.Read();

Expand All @@ -93,19 +96,19 @@ private static JmdictEntry ReadEntry(XmlTextReader xmlReader)
switch (xmlReader.Name)
{
case "ent_seq":
entry.Id = xmlReader.ReadElementContentAsInt();
id = xmlReader.ReadElementContentAsInt();
break;

case "k_ele":
entry.KanjiElements.Add(ReadKanjiElement(xmlReader));
kanjiElements.Add(ReadKanjiElement(xmlReader));
break;

case "r_ele":
entry.ReadingElements.Add(ReadReadingElement(xmlReader));
readingElements.Add(ReadReadingElement(xmlReader));
break;

case "sense":
entry.SenseList.Add(ReadSense(xmlReader));
senseList.Add(ReadSense(xmlReader));
break;

default:
Expand All @@ -119,12 +122,13 @@ private static JmdictEntry ReadEntry(XmlTextReader xmlReader)
}
}

return entry;
return new JmdictEntry(id, kanjiElements, readingElements, senseList);
}

private static KanjiElement ReadKanjiElement(XmlTextReader xmlReader)
{
KanjiElement kanjiElement = new();
string keb = "";
List<string> keInfList = [];

_ = xmlReader.Read();

Expand All @@ -140,11 +144,11 @@ private static KanjiElement ReadKanjiElement(XmlTextReader xmlReader)
switch (xmlReader.Name)
{
case "keb":
kanjiElement.Keb = xmlReader.ReadElementContentAsString().GetPooledString();
keb = xmlReader.ReadElementContentAsString().GetPooledString();
break;

case "ke_inf":
kanjiElement.KeInfList.Add(ReadEntity(xmlReader));
keInfList.Add(ReadEntity(xmlReader));
break;

//case "ke_pri":
Expand All @@ -163,12 +167,14 @@ private static KanjiElement ReadKanjiElement(XmlTextReader xmlReader)
}
}

return kanjiElement;
return new KanjiElement(keb, keInfList);
}

private static ReadingElement ReadReadingElement(XmlTextReader xmlReader)
{
ReadingElement readingElement = new();
string reb = "";
List<string> reRestrList = [];
List<string> reInfList = [];

_ = xmlReader.Read();

Expand All @@ -184,15 +190,15 @@ private static ReadingElement ReadReadingElement(XmlTextReader xmlReader)
switch (xmlReader.Name)
{
case "reb":
readingElement.Reb = xmlReader.ReadElementContentAsString().GetPooledString();
reb = xmlReader.ReadElementContentAsString().GetPooledString();
break;

case "re_restr":
readingElement.ReRestrList.Add(xmlReader.ReadElementContentAsString().GetPooledString());
reRestrList.Add(xmlReader.ReadElementContentAsString().GetPooledString());
break;

case "re_inf":
readingElement.ReInfList.Add(ReadEntity(xmlReader));
reInfList.Add(ReadEntity(xmlReader));
break;

//case "re_pri":
Expand All @@ -211,12 +217,22 @@ private static ReadingElement ReadReadingElement(XmlTextReader xmlReader)
}
}

return readingElement;
return new ReadingElement(reb, reRestrList, reInfList);
}

private static Sense ReadSense(XmlTextReader xmlReader)
{
Sense sense = new();
string? sInf = null;
List<string> stagKList = [];
List<string> stagRList = [];
List<string> posList = [];
List<string> fieldList = [];
List<string> miscList = [];
List<string> dialList = [];
List<string> glossList = [];
List<string> xRefList = [];
List<string> antList = [];
List<LoanwordSource> lSourceList = [];

_ = xmlReader.Read();

Expand All @@ -232,31 +248,31 @@ private static Sense ReadSense(XmlTextReader xmlReader)
switch (xmlReader.Name)
{
case "stagk":
sense.StagKList.Add(xmlReader.ReadElementContentAsString().GetPooledString());
stagKList.Add(xmlReader.ReadElementContentAsString().GetPooledString());
break;

case "stagr":
sense.StagRList.Add(xmlReader.ReadElementContentAsString().GetPooledString());
stagRList.Add(xmlReader.ReadElementContentAsString().GetPooledString());
break;

case "pos":
sense.PosList.Add(ReadEntity(xmlReader));
posList.Add(ReadEntity(xmlReader));
break;

case "field":
sense.FieldList.Add(ReadEntity(xmlReader));
fieldList.Add(ReadEntity(xmlReader));
break;

case "misc":
sense.MiscList.Add(ReadEntity(xmlReader));
miscList.Add(ReadEntity(xmlReader));
break;

case "s_inf":
sense.SInf = xmlReader.ReadElementContentAsString();
sInf = xmlReader.ReadElementContentAsString();
break;

case "dial":
sense.DialList.Add(ReadEntity(xmlReader));
dialList.Add(ReadEntity(xmlReader));
break;

case "gloss":
Expand All @@ -274,15 +290,15 @@ private static Sense ReadSense(XmlTextReader xmlReader)

gloss += xmlReader.ReadElementContentAsString();

sense.GlossList.Add(gloss);
glossList.Add(gloss);
break;

case "xref":
sense.XRefList.Add(xmlReader.ReadElementContentAsString().GetPooledString());
xRefList.Add(xmlReader.ReadElementContentAsString().GetPooledString());
break;

case "ant":
sense.AntList.Add(xmlReader.ReadElementContentAsString().GetPooledString());
antList.Add(xmlReader.ReadElementContentAsString().GetPooledString());
break;

case "lsource":
Expand Down Expand Up @@ -320,7 +336,7 @@ private static Sense ReadSense(XmlTextReader xmlReader)
string? originalWord = xmlReader.ReadElementContentAsString();
originalWord = originalWord.Length > 0 ? originalWord : null;

sense.LSourceList.Add(new LoanwordSource(lang.GetPooledString(), isPart, isWasei, originalWord));
lSourceList.Add(new LoanwordSource(lang.GetPooledString(), isPart, isWasei, originalWord));
break;

default:
Expand All @@ -335,7 +351,7 @@ private static Sense ReadSense(XmlTextReader xmlReader)
}
}

return sense;
return new Sense(sInf, stagKList, stagRList, posList, fieldList, miscList, dialList, glossList, xRefList, antList, lSourceList);
}

private static string ReadEntity(XmlTextReader xmlReader)
Expand Down
8 changes: 4 additions & 4 deletions JL.Core/Dicts/JMdict/KanjiElement.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace JL.Core.Dicts.JMdict;

internal sealed class KanjiElement
internal sealed class KanjiElement(string keb, List<string> keInfList)
{
public string Keb { get; set; } = ""; //e.g. 娘
public List<string> KeInfList { get; } = []; //e.g. Ateji.
// public List<string> KePriList { get; } = [] // e.g. gai1
public string Keb { get; } = keb; // e.g. 娘
public List<string> KeInfList { get; } = keInfList; // e.g. Ateji.
// public List<string> KePriList { get; } // e.g. gai1
}
12 changes: 6 additions & 6 deletions JL.Core/Dicts/JMdict/ReadingElement.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace JL.Core.Dicts.JMdict;

internal sealed class ReadingElement
internal sealed class ReadingElement(string reb, List<string> reRestrList, List<string> reInfList)
{
public string Reb { get; set; } = ""; // Reading in kana. e.g. むすめ
public List<string> ReRestrList { get; } = []; // ReRestrList = Keb. The reading is only valid for this specific keb.
public List<string> ReInfList { get; } = []; // e.g. gikun
// public bool ReNokanji { get; set; } // = False; // Is kana insufficient to notate the right spelling?
// public List<string> RePriList { get; } = [] // e.g. ichi1
public string Reb { get; } = reb; // Reading in kana. e.g. むすめ
public List<string> ReRestrList { get; } = reRestrList; // ReRestrList = Keb. The reading is only valid for this specific keb.
public List<string> ReInfList { get; } = reInfList; // e.g. gikun
// public bool ReNokanji { get; } // Is kana insufficient to notate the right spelling?
// public List<string> RePriList { get; } // e.g. ichi1
}
35 changes: 23 additions & 12 deletions JL.Core/Dicts/JMdict/Sense.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
namespace JL.Core.Dicts.JMdict;

internal sealed class Sense
internal sealed class Sense(
string? sInf,
List<string> stagKList,
List<string> stagRList,
List<string> posList,
List<string> fieldList,
List<string> miscList,
List<string> dialList,
List<string> glossList,
List<string> xRefList,
List<string> antList,
List<LoanwordSource> lSourceList)
{
public List<string> StagKList { get; } = []; // Meaning only valid for these kebs.
public List<string> StagRList { get; } = []; // Meaning only valid for these rebs.
public List<string> PosList { get; } = []; // e.g. "noun"
public List<string> FieldList { get; } = []; // e.g. "martial arts"
public List<string> MiscList { get; } = []; // e.g. "abbr"
public string? SInf { get; set; } // = null; // e.g. "often derog"
public List<string> DialList { get; } = []; // e.g. ksb
public List<string> GlossList { get; } = []; // English meaning
public List<string> XRefList { get; } = []; // Related terms
public List<string> AntList { get; } = []; // Antonyms
public List<LoanwordSource> LSourceList { get; } = [];
public List<string> StagKList { get; } = stagKList; // Meaning only valid for these kebs.
public List<string> StagRList { get; } = stagRList; // Meaning only valid for these rebs.
public List<string> PosList { get; } = posList; // e.g. "noun"
public List<string> FieldList { get; } = fieldList; // e.g. "martial arts"
public List<string> MiscList { get; } = miscList; // e.g. "abbr"
public string? SInf { get; set; } = sInf; // e.g. "often derog"
public List<string> DialList { get; } = dialList; // e.g. ksb
public List<string> GlossList { get; } = glossList; // English meaning
public List<string> XRefList { get; } = xRefList; // Related terms
public List<string> AntList { get; } = antList; // Antonyms
public List<LoanwordSource> LSourceList { get; } = lSourceList;
}

0 comments on commit 483ccba

Please sign in to comment.