Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit 325928b

Browse files
committed
Added interactive rune replacer.
1 parent de6df61 commit 325928b

File tree

13 files changed

+332
-79
lines changed

13 files changed

+332
-79
lines changed

LiberPrimusAnalysisTool.Application/Commands/TextUtilies/IndexWordDirectory.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ await Parallel.ForEachAsync(lines, async (line, cancellationToken) =>
7272
var runeText = await _mediator.Send(new TransposeLatinToRune.Command(runeglishText),
7373
cancellationToken);
7474
word.RuneWordText = runeText;
75+
76+
var gemSum = await _mediator.Send(new CalculateGematriaSum.Command(runeText), cancellationToken);
77+
word.GemSum = Convert.ToInt64(gemSum);
78+
79+
word.DictionaryWordLength = word.DictionaryWordText.Length;
80+
word.RuneglishWordLength = word.RuneglishWordText.Length;
81+
word.RuneWordLength = word.RuneWordText.Length;
7582

7683
await using (var context = new LiberContext())
7784
{
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using LiberPrimusAnalysisTool.Entity.Text;
2+
using LiberPrimusAnalysisTool.Utility.Character;
3+
using MediatR;
4+
5+
namespace LiberPrimusAnalysisTool.Application.Queries.Text;
6+
7+
public class GetRunes
8+
{
9+
public class Query: IRequest<RuneDetail[]>
10+
{
11+
12+
}
13+
14+
public class Handler: IRequestHandler<Query, RuneDetail[]>
15+
{
16+
private readonly ICharacterRepo _characterRepo;
17+
18+
public Handler(ICharacterRepo characterRepo)
19+
{
20+
_characterRepo = characterRepo;
21+
}
22+
23+
public Task<RuneDetail[]> Handle(Query request, CancellationToken cancellationToken)
24+
{
25+
List<RuneDetail> runeDetails = new();
26+
var runes = _characterRepo.GetGematriaRunes();
27+
28+
foreach (var rune in runes)
29+
{
30+
runeDetails.Add(new RuneDetail
31+
(
32+
rune,
33+
_characterRepo.GetCharFromRune(rune),
34+
_characterRepo.GetValueFromRune(rune)
35+
));
36+
}
37+
38+
runeDetails = runeDetails.OrderBy(x => x.Value).ToList();
39+
40+
return Task.FromResult(runeDetails.ToArray());
41+
}
42+
}
43+
}

LiberPrimusAnalysisTool.Application/Queries/Text/GetWordsFromInts.cs

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,29 @@
11
using LiberPrimusAnalysisTool.Application.Commands.TextUtilies;
22
using LiberPrimusAnalysisTool.Database;
3+
using LiberPrimusAnalysisTool.Entity.Text;
34
using MediatR;
45

56
namespace LiberPrimusAnalysisTool.Application.Queries.Text;
67

78
public class GetWordsFromInts
89
{
9-
public class Command : IRequest<IEnumerable<string>>
10+
public class Command : IRequest<IEnumerable<DictionaryWord>>
1011
{
1112
public string Ints { get; set; }
12-
13-
public string Catalog { get; set; }
14-
15-
public Command(string ints, string catalog)
13+
14+
public Command(string ints)
1615
{
1716
Ints = ints;
18-
Catalog = catalog;
1917
}
2018
}
21-
22-
public class Handler: IRequestHandler<Command, IEnumerable<string>>
19+
20+
public class Handler : IRequestHandler<Command, IEnumerable<DictionaryWord>>
2321
{
24-
private readonly MediatR.IMediator _mediator;
25-
26-
public Handler(MediatR.IMediator mediator)
27-
{
28-
_mediator = mediator;
29-
}
30-
31-
public async Task<IEnumerable<string>> Handle(Command request, CancellationToken cancellationToken)
22+
public async Task<IEnumerable<DictionaryWord>> Handle(Command request, CancellationToken cancellationToken)
3223
{
3324
List<ulong> ints = new();
34-
List<string> words = new();
35-
25+
List<DictionaryWord> words = new();
26+
3627
if (request.Ints.Contains(","))
3728
{
3829
ints.AddRange(request.Ints.Split(",").Select(x => Convert.ToUInt64(x.Trim())));
@@ -48,29 +39,10 @@ public async Task<IEnumerable<string>> Handle(Command request, CancellationToken
4839
{
4940
using (var context = new LiberContext())
5041
{
51-
foreach (var word in context.DictionaryWords)
52-
{
53-
var gemSum = await _mediator.Send(new CalculateGematriaSum.Command(word.RuneWordText));
54-
55-
if (Convert.ToUInt64(gemSum) == value)
56-
{
57-
switch (request.Catalog)
58-
{
59-
case "Regular":
60-
words.Add(word.DictionaryWordText);
61-
break;
62-
case "Runeglish":
63-
words.Add(word.RuneglishWordText);
64-
break;
65-
case "Runes":
66-
words.Add(word.RuneWordText);
67-
break;
68-
}
69-
}
70-
}
71-
}
42+
words = context.DictionaryWords.Where(x => x.GemSum == (long)value).ToList();
43+
}
7244
}
73-
45+
7446
return words;
7547
}
7648
}
Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using LiberPrimusAnalysisTool.Application.Commands.TextUtilies;
22
using LiberPrimusAnalysisTool.Database;
3+
using LiberPrimusAnalysisTool.Entity.Text;
34
using MediatR;
45

56
namespace LiberPrimusAnalysisTool.Application.Queries.Text;
67

78
public class GetWordsFromLengths
89
{
9-
public class Command : IRequest<IEnumerable<string>>
10+
public class Command : IRequest<IEnumerable<DictionaryWord>>
1011
{
1112
public string Ints { get; set; }
1213

@@ -19,7 +20,7 @@ public Command(string ints, string catalog)
1920
}
2021
}
2122

22-
public class Handler : IRequestHandler<Command, IEnumerable<string>>
23+
public class Handler : IRequestHandler<Command, IEnumerable<DictionaryWord>>
2324
{
2425
private readonly MediatR.IMediator _mediator;
2526

@@ -28,10 +29,10 @@ public Handler(MediatR.IMediator mediator)
2829
_mediator = mediator;
2930
}
3031

31-
public async Task<IEnumerable<string>> Handle(Command request, CancellationToken cancellationToken)
32+
public async Task<IEnumerable<DictionaryWord>> Handle(Command request, CancellationToken cancellationToken)
3233
{
3334
List<int> ints = new();
34-
List<string> words = new();
35+
List<DictionaryWord> words = new();
3536

3637
if (request.Ints.Contains(","))
3738
{
@@ -48,34 +49,22 @@ public async Task<IEnumerable<string>> Handle(Command request, CancellationToken
4849
{
4950
using (var context = new LiberContext())
5051
{
51-
foreach (var word in context.DictionaryWords)
52+
switch (request.Catalog)
5253
{
53-
switch (request.Catalog)
54-
{
55-
case "Regular":
56-
if (word.DictionaryWordText.Length == value)
57-
{
58-
words.Add(word.DictionaryWordText);
59-
}
60-
break;
61-
case "Runeglish":
62-
if (word.RuneglishWordText.Length == value)
63-
{
64-
words.Add(word.RuneglishWordText);
65-
}
66-
break;
67-
case "Runes":
68-
if (word.RuneWordText.Length == value)
69-
{
70-
words.Add(word.RuneWordText);
71-
}
72-
break;
73-
}
54+
case "Regular":
55+
words = context.DictionaryWords.Where(x => x.DictionaryWordLength == value).ToList();
56+
break;
57+
case "Runeglish":
58+
words = context.DictionaryWords.Where(x => x.RuneglishWordLength == value).ToList();
59+
break;
60+
case "Runes":
61+
words = context.DictionaryWords.Where(x => x.RuneWordLength == value).ToList();
62+
break;
7463
}
7564
}
7665
}
7766

78-
return words;
67+
return words.OrderBy(x => x.DictionaryWordText).ToList();
7968
}
8069
}
8170
}

LiberPrimusAnalysisTool.Entity/Text/DictionaryWord.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,25 @@ public class DictionaryWord
2121
[Required]
2222
[Column("DICT_RUNE")]
2323
public string RuneWordText { get; set; }
24+
25+
[Required]
26+
[Column("GEM_SUM")]
27+
public long GemSum { get; set; }
28+
29+
[Required]
30+
[Column("DICT_WORD_LENGTH")]
31+
public int DictionaryWordLength { get; set; }
32+
33+
[Required]
34+
[Column("DICT_RUNEGLISH_LENGTH")]
35+
public int RuneglishWordLength { get; set; }
36+
37+
[Required]
38+
[Column("DICT_RUNE_LENGTH")]
39+
public int RuneWordLength { get; set; }
40+
41+
public override string ToString()
42+
{
43+
return $"{DictionaryWordText} - {RuneglishWordText} - {RuneWordText} - {GemSum}";
44+
}
2445
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace LiberPrimusAnalysisTool.Entity.Text;
2+
3+
public class RuneDetail
4+
{
5+
public RuneDetail(string rune, string latin, int value)
6+
{
7+
Rune = rune;
8+
Latin = latin;
9+
Value = value;
10+
}
11+
12+
public string Rune { get; set; }
13+
14+
public string Latin { get; set; }
15+
16+
public int Value { get; set; }
17+
18+
public override string ToString()
19+
{
20+
return $"{Rune} {Latin} {Value}";
21+
}
22+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace LiberPrimusAnalysisTool.Entity.Text;
2+
3+
public class RuneDetailMapping
4+
{
5+
public RuneDetailMapping(RuneDetail fromRune, RuneDetail toRune)
6+
{
7+
FromRune = fromRune;
8+
ToRune = toRune;
9+
}
10+
11+
public RuneDetail FromRune { get; set; }
12+
13+
public RuneDetail ToRune { get; set; }
14+
15+
public override string ToString()
16+
{
17+
return $"{FromRune} -> {ToRune}";
18+
}
19+
}

LiberPrimusUi/ViewModels/GetWordsForValueViewModel.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,12 @@ public partial class GetWordsForValueViewModel: ViewModelBase
1515
public GetWordsForValueViewModel(IMediator mediator)
1616
{
1717
_mediator = mediator;
18-
19-
Catalogs.Add("Regular");
20-
Catalogs.Add("Runeglish");
21-
Catalogs.Add("Runes");
2218
}
2319

2420
[ObservableProperty] private string _textToTranspose = "";
2521

2622
[ObservableProperty] private string _response = "";
2723

28-
public ObservableCollection<string> Catalogs { get; set; } = new ObservableCollection<string>();
29-
30-
[ObservableProperty] private string _selectedCatalog;
31-
3224
[RelayCommand]
3325
public async void CalculateText()
3426
{
@@ -37,7 +29,7 @@ public async void CalculateText()
3729

3830
foreach (var textValue in TextToTranspose.Split(",", StringSplitOptions.RemoveEmptyEntries))
3931
{
40-
var tresponse = await _mediator.Send(new GetWordsFromInts.Command(textValue.Trim(), SelectedCatalog));
32+
var tresponse = await _mediator.Send(new GetWordsFromInts.Command(textValue.Trim()));
4133

4234
if (tresponse.Count() == 0)
4335
{

LiberPrimusUi/ViewModels/MainWindowViewModel.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public MainWindowViewModel(ICharacterRepo characterRepo, IPermutator permutator,
4646
new ListItemTemplate(typeof(SkipAndTakeViewModel), "Wrench", "Skip and Take"),
4747
new ListItemTemplate(typeof(DictionaryCheckTextFilesViewModel), "Wrench", "Dictionary Check Text Files"),
4848
new ListItemTemplate(typeof(CalculateClockAngleViewModel), "Wrench", "Clock Angle Calculator"),
49+
new ListItemTemplate(typeof(RuneInteractiveSubstitutionViewModel), "Wrench", "Interactive Rune Substitution"),
4950

5051
// Text analysis
5152
new ListItemTemplate(typeof(LetterFrequencyAnalysisViewModel), "Analysis", "Letter Frequency Analysis"),
@@ -279,6 +280,12 @@ partial void OnSelectedListItemChanged(ListItemTemplate? value)
279280
_windows.Add(new Tuple<string, object>(value.Label, new GetWordsForLengthViewModel(_mediator)));
280281
CurrentPage = _windows.FirstOrDefault(w => w.Item1 == value.Label)?.Item2 as GetWordsForLengthViewModel;
281282
break;
283+
284+
case Type t when t == typeof(RuneInteractiveSubstitutionViewModel):
285+
if (!_windows.Any(w => w.Item1 == value.Label))
286+
_windows.Add(new Tuple<string, object>(value.Label, new RuneInteractiveSubstitutionViewModel(_mediator)));
287+
CurrentPage = _windows.FirstOrDefault(w => w.Item1 == value.Label)?.Item2 as RuneInteractiveSubstitutionViewModel;
288+
break;
282289
}
283290

284291
TitleBar = $"Liber Primus Analysis Tool - {value.Label}";

0 commit comments

Comments
 (0)