-
Notifications
You must be signed in to change notification settings - Fork 87
/
Result.cs
291 lines (250 loc) · 8.42 KB
/
Result.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/*
// <copyright>
// dotNetRDF is free and open source software licensed under the MIT License
// -------------------------------------------------------------------------
//
// Copyright (c) 2009-2021 dotNetRDF Project (http://dotnetrdf.org/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is furnished
// to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
*/
namespace VDS.RDF.Shacl.Validation
{
using System.Diagnostics;
using System.Linq;
using VDS.RDF;
/// <summary>
/// Represents a SHACL validation result.
/// </summary>
public class Result : WrapperNode
{
[DebuggerStepThrough]
private Result(INode node)
: base(node)
{
}
/// <summary>
/// Gets or sets the severity of the result.
/// </summary>
public INode Severity
{
get
{
return Vocabulary.ResultSeverity.ObjectsOf(this).SingleOrDefault();
}
set
{
foreach (var severity in Vocabulary.ResultSeverity.ObjectsOf(this).ToList())
{
Graph.Retract(this, Vocabulary.ResultSeverity, severity);
}
if (value is null)
{
return;
}
Graph.Assert(this, Vocabulary.ResultSeverity, value);
}
}
/// <summary>
/// Gets or sets the focus node that has caused thes result.
/// </summary>
public INode FocusNode
{
get
{
return Vocabulary.FocusNode.ObjectsOf(this).SingleOrDefault();
}
set
{
foreach (var focusNode in Vocabulary.FocusNode.ObjectsOf(this).ToList())
{
Graph.Retract(this, Vocabulary.FocusNode, focusNode);
}
if (value is null)
{
return;
}
Graph.Assert(this, Vocabulary.FocusNode, value);
}
}
/// <summary>
/// Gets or sets the value that has caused the result.
/// </summary>
public INode ResultValue
{
get
{
return Vocabulary.Value.ObjectsOf(this).SingleOrDefault();
}
set
{
foreach (var valueNode in Vocabulary.Value.ObjectsOf(this).ToList())
{
Graph.Retract(this, Vocabulary.Value, valueNode);
}
if (value is null)
{
return;
}
Graph.Assert(this, Vocabulary.Value, value);
}
}
/// <summary>
/// Gets or sets the shape that the given focus node was validated against.
/// </summary>
public INode SourceShape
{
get
{
return Vocabulary.SourceShape.ObjectsOf(this).SingleOrDefault();
}
set
{
foreach (var sourceShape in Vocabulary.SourceShape.ObjectsOf(this).ToList())
{
Graph.Retract(this, Vocabulary.SourceShape, sourceShape);
}
if (value is null)
{
return;
}
Graph.Assert(this, Vocabulary.SourceShape, value);
}
}
// TODO: Spec says this is a collection
/// <summary>
/// Gets or sets additional textual details about the result.
/// </summary>
public ILiteralNode Message
{
get
{
return (ILiteralNode)Vocabulary.ResultMessage.ObjectsOf(this).SingleOrDefault();
}
set
{
foreach (var sourceShape in Vocabulary.ResultMessage.ObjectsOf(this).ToList())
{
Graph.Retract(this, Vocabulary.ResultMessage, sourceShape);
}
if (value is null)
{
return;
}
Graph.Assert(this, Vocabulary.ResultMessage, value);
}
}
/// <summary>
/// Gets or sets the IRI of the constraint component that has caused the result.
/// </summary>
public INode SourceConstraintComponent
{
get
{
return Vocabulary.SourceConstraintComponent.ObjectsOf(this).SingleOrDefault();
}
set
{
foreach (var sourceConstraintComponent in Vocabulary.SourceConstraintComponent.ObjectsOf(this).ToList())
{
Graph.Retract(this, Vocabulary.SourceConstraintComponent, sourceConstraintComponent);
}
if (value is null)
{
return;
}
Graph.Assert(this, Vocabulary.SourceConstraintComponent, value);
}
}
/// <summary>
/// Gets or sets the optional path of the property shape that has caused the result.
/// </summary>
public Path ResultPath
{
get
{
return Vocabulary.ResultPath.ObjectsOf(this).Select(Path.Parse).SingleOrDefault();
}
set
{
foreach (var sourceConstraintComponent in Vocabulary.ResultPath.ObjectsOf(this).ToList())
{
Graph.Retract(this, Vocabulary.ResultPath, sourceConstraintComponent);
}
if (value is null)
{
return;
}
Graph.Assert(this, Vocabulary.ResultPath, value);
}
}
/// <summary>
/// Gets or sets the optional SPARQL-based constraint the has caused the result.
/// </summary>
public INode SourceConstraint
{
get
{
return Vocabulary.SourceConstraint.ObjectsOf(this).SingleOrDefault();
}
set
{
foreach (var sourceConstraint in Vocabulary.SourceConstraint.ObjectsOf(this).ToList())
{
Graph.Retract(this, Vocabulary.SourceConstraint, sourceConstraint);
}
if (value is null)
{
return;
}
Graph.Assert(this, Vocabulary.SourceConstraint, value);
}
}
private INode Type
{
get
{
return Vocabulary.RdfType.ObjectsOf(this).SingleOrDefault();
}
set
{
foreach (var type in Vocabulary.RdfType.ObjectsOf(this).ToList())
{
Graph.Retract(this, Vocabulary.RdfType, type);
}
if (value is null)
{
return;
}
Graph.Assert(this, Vocabulary.RdfType, value);
}
}
internal static Result Create(IGraph g)
{
var report = new Result(g.CreateBlankNode())
{
Type = Vocabulary.ValidationResult,
};
return report;
}
internal static Result Parse(INode node)
{
return new Result(node);
}
}
}