Skip to content

Commit d7867a5

Browse files
committed
Update
+ Added KWS JSON format to the extractor
1 parent 258c1fe commit d7867a5

File tree

3 files changed

+319
-189
lines changed

3 files changed

+319
-189
lines changed

src/wan24-I8NKws/KwsCatalog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public KwsCatalog() { }
4848
/// <summary>
4949
/// Keywords
5050
/// </summary>
51-
public HashSet<KwsKeyword> Keywords { get; } = [];
51+
public HashSet<KwsKeyword> Keywords { get; init; } = [];
5252

5353
/// <summary>
5454
/// Validate the catalog

src/wan24-I8NKws/KwsKeyword.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.ComponentModel.DataAnnotations;
22
using System.Text.Json.Serialization;
3+
using wan24.Core;
34

45
namespace wan24.I8NKws
56
{
@@ -8,6 +9,11 @@ namespace wan24.I8NKws
89
/// </summary>
910
public sealed record class KwsKeyword
1011
{
12+
/// <summary>
13+
/// ID literal
14+
/// </summary>
15+
private string? _IdLiteral = null;
16+
1117
/// <summary>
1218
/// Constructor
1319
/// </summary>
@@ -29,6 +35,11 @@ public KwsKeyword(in string id)
2935
[MinLength(1)]
3036
public string ID { get; private set; } = null!;
3137

38+
/// <summary>
39+
/// ID literal
40+
/// </summary>
41+
public string IdLiteral => _IdLiteral ??= ID.ToLiteral();
42+
3243
/// <summary>
3344
/// Previous IDs (extended when the ID is being updated; last entry was the latest ID)
3445
/// </summary>
@@ -78,15 +89,20 @@ public KwsKeyword(in string id)
7889
/// <summary>
7990
/// Translations
8091
/// </summary>
81-
public List<string> Translations { get; } = [];
92+
public List<string> Translations { get; init; } = [];
8293

8394
/// <summary>
8495
/// Source references
8596
/// </summary>
86-
public HashSet<string> SourceReferences { get; } = [];
97+
public HashSet<KwsSourceReference> SourceReferences { get; init; } = [];
8798

8899
/// <summary>
89-
/// Update the ID
100+
/// Previous source references (if fuzzy logicwas used to update the ID)
101+
/// </summary>
102+
public HashSet<KwsSourceReference> PreviousSourceReferences { get; init; } = [];
103+
104+
/// <summary>
105+
/// Update the ID (source references will be moved to <see cref="PreviousSourceReferences"/>)
90106
/// </summary>
91107
/// <param name="newId">New ID</param>
92108
public void UpdateId(in string newId)
@@ -98,6 +114,9 @@ public void UpdateId(in string newId)
98114
ID = newId;
99115
PreviousIds.Remove(oldId);
100116
PreviousIds.Add(oldId);
117+
PreviousSourceReferences.Clear();
118+
PreviousSourceReferences.AddRange(SourceReferences);
119+
SourceReferences.Clear();
101120
}
102121

103122
/// <summary>
@@ -107,16 +126,20 @@ public void UpdateId(in string newId)
107126
public void UndoIdUpdate(string? id = null)
108127
{
109128
if (Obsolete || PreviousIds.Count == 0) throw new InvalidOperationException();
110-
if (id is null)
129+
bool lastId = id is null;
130+
if (lastId)
111131
{
112132
id = PreviousIds.Last();
113133
}
114-
else if (!PreviousIds.Contains(id))
134+
else if (!PreviousIds.Contains(id!))
115135
{
116136
throw new ArgumentException("Unknown previous ID", nameof(id));
117137
}
118-
ID = id;
138+
ID = id!;
119139
PreviousIds = [.. PreviousIds.SkipWhile(pid => pid != id).Skip(1)];
140+
SourceReferences.Clear();
141+
SourceReferences.AddRange(PreviousSourceReferences);
142+
PreviousSourceReferences.Clear();
120143
}
121144
}
122145
}

0 commit comments

Comments
 (0)