public KanjiProperties( KanjiDict kanjiDict, Kradfile kradfile, Radkfile radkfile, RadicalRemapper remapper) { this.kradfile = kradfile; this.radkfile = radkfile; this.remapper = remapper; KanjiOrderings = new ObservableBatchCollection <KanjiOrdering> { KanjiOrdering.Create("Sort by stroke count", kanjiDict, x => x.StrokeCount), KanjiOrdering.Create("Sort by frequency", kanjiDict, x => x.FrequencyRating) }; }
public KanjiRadicalLookup(IEnumerable<Radkfile.Entry> entries, KanjiDict kanjiDict) { SortingCriteria = new ReadOnlyListWithSelector<IKanjiOrdering>(new IKanjiOrdering[] { KanjiOrdering.Create("Sort by stroke count", kanjiDict, x => x.StrokeCount), KanjiOrdering.Create("Sort by frequency", kanjiDict, x => x.FrequencyRating) }); SortingCriteria.SelectedIndex = 0; var entryList = entries.ToList(); radicalCount = entryList.Count; elementSize = DivideRoundUp(radicalCount, vectorBitCount); elementSize = elementSize == 0 ? 1 : elementSize; var kradMapping = entryList .ToDictionary(entry => entry.Radical.CodePoint, entry => entry.KanjiCodePoints.AsEnumerable()) .InvertMappingToSequence(); var kanjiCodePoints = entryList .SelectMany(entry => entry.KanjiCodePoints) .Distinct() .ToArray(); kanjiCount = kanjiCodePoints.Length; indexToKanji = SortingCriteria .Select(sortingCriterion => kanjiCodePoints .OrderBy(x => x, Comparer<int>.Create((l, r) => sortingCriterion.Compare( CodePoint.FromInt(l), CodePoint.FromInt(r)))) .ToArray()) .ToArray(); indexToRadical = entryList .Select(entry => entry.Radical.CodePoint) .ToArray(); radicalToIndex = indexToRadical .Indexed() .ToDictionary(p => p.element, p => p.index); var kanjiToIndex = indexToKanji .Select(a => a .Indexed() .ToDictionary(p => p.element, p => p.index)) .ToArray(); radkinfo = Enumerable.Range(0, SortingCriteria.Count) .Select(CreateRadkInfo) .ToArray(); Vector<ulong>[] CreateRadkInfo(int x) { var r = new Vector<ulong>[kanjiCount * elementSize]; foreach (var kanji in kanjiCodePoints) { var v = new Vector<ulong>[elementSize]; var kanjiIndex = kanjiToIndex[x][kanji]; var vec = AsScalarSpan(v); foreach (var radical in kradMapping[kanji]) { var radicalIndex = radicalToIndex[radical]; vec[radicalIndex / ulongBitCount] |= (ulong)(1UL << radicalIndex); } for (int i = 0; i < elementSize; ++i) { r[kanjiIndex * elementSize + i] = v[i]; } } return r; } }