本文整理汇总了C#中ReadOnlyList.GroupBy方法的典型用法代码示例。如果您正苦于以下问题:C# ReadOnlyList.GroupBy方法的具体用法?C# ReadOnlyList.GroupBy怎么用?C# ReadOnlyList.GroupBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReadOnlyList
的用法示例。
在下文中一共展示了ReadOnlyList.GroupBy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SegmentMappingsTableViewModel
public SegmentMappingsTableViewModel(IProjectService projectService, SegmentMappingsTableSegmentPairViewModel.Factory segmentPairFactory, SegmentMappingViewModel.Factory mappingFactory,
IEnumerable<SegmentMappingViewModel> mappings, SoundType soundType, int threshold)
{
_threshold = threshold;
_soundType = soundType;
FeatureSymbol segmentType;
switch (_soundType)
{
case SoundType.Consonant:
segmentType = CogFeatureSystem.ConsonantType;
break;
case SoundType.Vowel:
segmentType = CogFeatureSystem.VowelType;
break;
default:
throw new InvalidEnumArgumentException();
}
var segmentComparer = new SegmentComparer();
var categoryComparer = new SegmentCategoryComparer();
_segments = new ReadOnlyList<SegmentMappingsTableSegmentViewModel>(projectService.Project.Varieties.SelectMany(v => v.SegmentFrequencyDistribution.ObservedSamples)
.Where(s => s.Type == segmentType).Distinct().OrderBy(s => s.Category(), categoryComparer).ThenBy(s => s, segmentComparer)
.Select(s => new SegmentMappingsTableSegmentViewModel(s, _soundType)).Concat(new SegmentMappingsTableSegmentViewModel(null, _soundType)).ToArray());
_categories = new ReadOnlyList<SegmentCategoryViewModel>(_segments.GroupBy(s => s.DomainSegment == null ? string.Empty : s.DomainSegment.Category())
.OrderBy(g => g.Key, categoryComparer).Select(g => new SegmentCategoryViewModel(g.Key, g)).ToArray());
var mappingLookup = new Dictionary<UnorderedTuple<string, string>, HashSet<UnorderedTuple<string, string>>>();
foreach (SegmentMappingViewModel mapping in mappings)
{
string seg1, seg2;
FeatureSymbol leftEnv1, rightEnv1, leftEnv2, rightEnv2;
if (ListSegmentMappings.Normalize(projectService.Project.Segmenter, mapping.Segment1, out seg1, out leftEnv1, out rightEnv1)
&& ListSegmentMappings.Normalize(projectService.Project.Segmenter, mapping.Segment2, out seg2, out leftEnv2, out rightEnv2))
{
UnorderedTuple<string, string> key = UnorderedTuple.Create(seg1, seg2);
HashSet<UnorderedTuple<string, string>> m = mappingLookup.GetValue(key, () => new HashSet<UnorderedTuple<string, string>>());
m.Add(UnorderedTuple.Create(mapping.Segment1, mapping.Segment2));
}
}
IWordAligner aligner = projectService.Project.WordAligners[ComponentIdentifiers.PrimaryWordAligner];
foreach (SegmentMappingsTableSegmentViewModel segment1 in _segments)
{
bool isEnabled = true;
foreach (SegmentMappingsTableSegmentViewModel segment2 in _segments)
{
if (EqualityComparer<Segment>.Default.Equals(segment1.DomainSegment, segment2.DomainSegment))
isEnabled = false;
int delta = segment1.DomainSegment == null || segment2.DomainSegment == null ? -1
: aligner.Delta(segment1.DomainSegment.FeatureStruct, segment2.DomainSegment.FeatureStruct);
SegmentMappingsTableSegmentPairViewModel segmentPair = segmentPairFactory(segment1, segment2, delta, isEnabled);
segmentPair.MeetsThreshold = delta != -1 && delta <= _threshold;
HashSet<UnorderedTuple<string, string>> pairMappings;
if (mappingLookup.TryGetValue(UnorderedTuple.Create(segment1.StrRep, segment2.StrRep), out pairMappings))
segmentPair.Mappings.Mappings.AddRange(pairMappings.Select(m => mappingFactory(m.Item1, m.Item2)));
segment1.SegmentPairs.Add(segmentPair);
}
}
}