1
1
using System . ComponentModel . DataAnnotations ;
2
2
using System . Text . Json . Serialization ;
3
+ using wan24 . Core ;
3
4
4
5
namespace wan24 . I8NKws
5
6
{
@@ -8,6 +9,11 @@ namespace wan24.I8NKws
8
9
/// </summary>
9
10
public sealed record class KwsKeyword
10
11
{
12
+ /// <summary>
13
+ /// ID literal
14
+ /// </summary>
15
+ private string ? _IdLiteral = null ;
16
+
11
17
/// <summary>
12
18
/// Constructor
13
19
/// </summary>
@@ -29,6 +35,11 @@ public KwsKeyword(in string id)
29
35
[ MinLength ( 1 ) ]
30
36
public string ID { get ; private set ; } = null ! ;
31
37
38
+ /// <summary>
39
+ /// ID literal
40
+ /// </summary>
41
+ public string IdLiteral => _IdLiteral ??= ID . ToLiteral ( ) ;
42
+
32
43
/// <summary>
33
44
/// Previous IDs (extended when the ID is being updated; last entry was the latest ID)
34
45
/// </summary>
@@ -78,15 +89,20 @@ public KwsKeyword(in string id)
78
89
/// <summary>
79
90
/// Translations
80
91
/// </summary>
81
- public List < string > Translations { get ; } = [ ] ;
92
+ public List < string > Translations { get ; init ; } = [ ] ;
82
93
83
94
/// <summary>
84
95
/// Source references
85
96
/// </summary>
86
- public HashSet < string > SourceReferences { get ; } = [ ] ;
97
+ public HashSet < KwsSourceReference > SourceReferences { get ; init ; } = [ ] ;
87
98
88
99
/// <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"/>)
90
106
/// </summary>
91
107
/// <param name="newId">New ID</param>
92
108
public void UpdateId ( in string newId )
@@ -98,6 +114,9 @@ public void UpdateId(in string newId)
98
114
ID = newId ;
99
115
PreviousIds . Remove ( oldId ) ;
100
116
PreviousIds . Add ( oldId ) ;
117
+ PreviousSourceReferences . Clear ( ) ;
118
+ PreviousSourceReferences . AddRange ( SourceReferences ) ;
119
+ SourceReferences . Clear ( ) ;
101
120
}
102
121
103
122
/// <summary>
@@ -107,16 +126,20 @@ public void UpdateId(in string newId)
107
126
public void UndoIdUpdate ( string ? id = null )
108
127
{
109
128
if ( Obsolete || PreviousIds . Count == 0 ) throw new InvalidOperationException ( ) ;
110
- if ( id is null )
129
+ bool lastId = id is null ;
130
+ if ( lastId )
111
131
{
112
132
id = PreviousIds . Last ( ) ;
113
133
}
114
- else if ( ! PreviousIds . Contains ( id ) )
134
+ else if ( ! PreviousIds . Contains ( id ! ) )
115
135
{
116
136
throw new ArgumentException ( "Unknown previous ID" , nameof ( id ) ) ;
117
137
}
118
- ID = id ;
138
+ ID = id ! ;
119
139
PreviousIds = [ .. PreviousIds . SkipWhile ( pid => pid != id ) . Skip ( 1 ) ] ;
140
+ SourceReferences . Clear ( ) ;
141
+ SourceReferences . AddRange ( PreviousSourceReferences ) ;
142
+ PreviousSourceReferences . Clear ( ) ;
120
143
}
121
144
}
122
145
}
0 commit comments