Forge
csharpdeeb25a2
1namespace CasaField.Core;
2
3public static class CasaCanonical
4{
5 public const int FieldMinVotes = 1;
6 public const int RepairMinVotes = 2;
7}
8
9public sealed record DecodedGrid(
10 IReadOnlyList<string> ConceptIds,
11 IReadOnlyList<string> Edges,
12 IReadOnlyList<string> PresentTokens,
13 int MinVotes);
14
15public static class GridDecoder
16{
17 public static DecodedGrid Decode(IReadOnlyList<IReadOnlyList<string>> cells, int minVotes)
18 {
19 var vote = new Dictionary<string, int>(StringComparer.Ordinal);
20 foreach (var cell in cells)
21 {
22 foreach (var token in cell)
23 {
24 vote[token] = vote.GetValueOrDefault(token) + 1;
25 }
26 }
27
28 var present = vote
29 .Where(kv => kv.Value >= minVotes)
30 .Select(kv => kv.Key)
31 .OrderBy(t => t, StringComparer.Ordinal)
32 .ToList();
33
34 var concepts = present
35 .Where(t => t.StartsWith("C:", StringComparison.Ordinal))
36 .Select(t => t[2..])
37 .OrderBy(t => t, StringComparer.OrdinalIgnoreCase)
38 .ToList();
39
40 var edges = present
41 .Where(t => t.StartsWith("E:", StringComparison.Ordinal))
42 .Select(t => t[2..])
43 .ToList();
44
45 return new DecodedGrid(concepts, edges, present, minVotes);
46 }
47}
48
View only · write via MCP/CIDE