Skip to content

Commit c637600

Browse files
committed
Prefer usage of selectors instead of accessors whenever possible
1 parent ab8c030 commit c637600

File tree

2 files changed

+93
-93
lines changed

2 files changed

+93
-93
lines changed

RDFSharp/Model/RDFModelUtilities.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -212,34 +212,34 @@ public static List<RDFDatatype> ExtractDatatypeDefinitions(this RDFGraph graph)
212212
return new List<RDFDatatype>();
213213

214214
List<RDFDatatype> datatypes = new List<RDFDatatype>();
215-
foreach (RDFTriple datatypeTriple in graph[p: RDFVocabulary.RDF.TYPE, o: RDFVocabulary.RDFS.DATATYPE])
215+
foreach (RDFTriple datatypeTriple in graph.SelectTriples(p: RDFVocabulary.RDF.TYPE, o: RDFVocabulary.RDFS.DATATYPE))
216216
{
217217
RDFResource datatypeIRI = (RDFResource)datatypeTriple.Subject;
218218

219219
//Try detect a faceted datatype
220-
if (graph[s: datatypeIRI, p: RDFVocabulary.OWL.WITH_RESTRICTIONS].FirstOrDefault()?.Object is RDFResource facetsRepresentative
221-
&& graph[s: datatypeIRI, p: RDFVocabulary.OWL.ON_DATATYPE].FirstOrDefault()?.Object is RDFResource onDatatype)
220+
if (graph.SelectTriples(s: datatypeIRI, p: RDFVocabulary.OWL.WITH_RESTRICTIONS).FirstOrDefault()?.Object is RDFResource facetsRepresentative
221+
&& graph.SelectTriples(s: datatypeIRI, p: RDFVocabulary.OWL.ON_DATATYPE).FirstOrDefault()?.Object is RDFResource onDatatype)
222222
{
223223
//Detect the target datatype (fallback to rdfs:Literal in case not found)
224224
RDFDatatype targetDatatype = RDFDatatypeRegister.GetDatatype(onDatatype.ToString())
225225
?? RDFDatatypeRegister.RDFSLiteral;
226226
RDFModelEnums.RDFDatatypes targetDatatypeEnum = targetDatatype.ToString().GetEnumFromDatatype();
227-
227+
228228
//Detect the constraining facets
229229
RDFCollection facetsCollection = DeserializeCollectionFromGraph(graph, facetsRepresentative, RDFModelEnums.RDFTripleFlavors.SPO);
230230
RDFResource[] facets = facetsCollection.Items.Cast<RDFResource>().ToArray();
231231
List<RDFFacet> targetFacets = new List<RDFFacet>(facets.Length);
232232
foreach (RDFResource facet in facets)
233233
{
234234
//xsd:length
235-
if (graph[s: facet, p: RDFVocabulary.XSD.LENGTH].FirstOrDefault()?.Object is RDFTypedLiteral facetLength
235+
if (graph.SelectTriples(s: facet, p: RDFVocabulary.XSD.LENGTH).FirstOrDefault()?.Object is RDFTypedLiteral facetLength
236236
&& facetLength.HasDecimalDatatype() && uint.TryParse(facetLength.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out uint facetLengthValue))
237237
{
238238
targetFacets.Add(new RDFLengthFacet(facetLengthValue));
239239
continue;
240240
}
241241
//xsd:maxExclusive
242-
if (graph[s: facet, p: RDFVocabulary.XSD.MAX_EXCLUSIVE].FirstOrDefault()?.Object is RDFTypedLiteral facetMaxExclusive
242+
if (graph.SelectTriples(s: facet, p: RDFVocabulary.XSD.MAX_EXCLUSIVE).FirstOrDefault()?.Object is RDFTypedLiteral facetMaxExclusive
243243
&& facetMaxExclusive.HasDecimalDatatype())
244244
{
245245
if (double.TryParse(facetMaxExclusive.Value, NumberStyles.Integer | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out double facetMaxExclusiveValue))
@@ -249,7 +249,7 @@ public static List<RDFDatatype> ExtractDatatypeDefinitions(this RDFGraph graph)
249249
}
250250
}
251251
//xsd:maxInclusive
252-
if (graph[s: facet, p: RDFVocabulary.XSD.MAX_INCLUSIVE].FirstOrDefault()?.Object is RDFTypedLiteral facetMaxInclusive
252+
if (graph.SelectTriples(s: facet, p: RDFVocabulary.XSD.MAX_INCLUSIVE).FirstOrDefault()?.Object is RDFTypedLiteral facetMaxInclusive
253253
&& facetMaxInclusive.HasDecimalDatatype())
254254
{
255255
if (double.TryParse(facetMaxInclusive.Value, NumberStyles.Integer | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out double facetMaxInclusiveValue))
@@ -259,14 +259,14 @@ public static List<RDFDatatype> ExtractDatatypeDefinitions(this RDFGraph graph)
259259
}
260260
}
261261
//xsd:maxLength
262-
if (graph[s: facet, p: RDFVocabulary.XSD.MAX_LENGTH].FirstOrDefault()?.Object is RDFTypedLiteral facetMaxLength
262+
if (graph.SelectTriples(s: facet, p: RDFVocabulary.XSD.MAX_LENGTH).FirstOrDefault()?.Object is RDFTypedLiteral facetMaxLength
263263
&& facetMaxLength.HasDecimalDatatype() && uint.TryParse(facetMaxLength.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out uint facetMaxLengthValue))
264264
{
265265
targetFacets.Add(new RDFMaxLengthFacet(facetMaxLengthValue));
266266
continue;
267267
}
268268
//xsd:minExclusive
269-
if (graph[s: facet, p: RDFVocabulary.XSD.MIN_EXCLUSIVE].FirstOrDefault()?.Object is RDFTypedLiteral facetMinExclusive
269+
if (graph.SelectTriples(s: facet, p: RDFVocabulary.XSD.MIN_EXCLUSIVE).FirstOrDefault()?.Object is RDFTypedLiteral facetMinExclusive
270270
&& facetMinExclusive.HasDecimalDatatype())
271271
{
272272
if (double.TryParse(facetMinExclusive.Value, NumberStyles.Integer | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out double facetMinExclusiveValue))
@@ -276,7 +276,7 @@ public static List<RDFDatatype> ExtractDatatypeDefinitions(this RDFGraph graph)
276276
}
277277
}
278278
//xsd:minInclusive
279-
if (graph[s: facet, p: RDFVocabulary.XSD.MIN_INCLUSIVE].FirstOrDefault()?.Object is RDFTypedLiteral facetMinInclusive
279+
if (graph.SelectTriples(s: facet, p: RDFVocabulary.XSD.MIN_INCLUSIVE).FirstOrDefault()?.Object is RDFTypedLiteral facetMinInclusive
280280
&& facetMinInclusive.HasDecimalDatatype())
281281
{
282282
if (double.TryParse(facetMinInclusive.Value, NumberStyles.Integer | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out double facetMinInclusiveValue))
@@ -286,14 +286,14 @@ public static List<RDFDatatype> ExtractDatatypeDefinitions(this RDFGraph graph)
286286
}
287287
}
288288
//xsd:minLength
289-
if (graph[s: facet, p: RDFVocabulary.XSD.MIN_LENGTH].FirstOrDefault()?.Object is RDFTypedLiteral facetMinLength
289+
if (graph.SelectTriples(s: facet, p: RDFVocabulary.XSD.MIN_LENGTH).FirstOrDefault()?.Object is RDFTypedLiteral facetMinLength
290290
&& facetMinLength.HasDecimalDatatype() && uint.TryParse(facetMinLength.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out uint facetMinLengthValue))
291291
{
292292
targetFacets.Add(new RDFMinLengthFacet(facetMinLengthValue));
293293
continue;
294294
}
295295
//xsd:pattern
296-
if (graph[s: facet, p: RDFVocabulary.XSD.PATTERN].FirstOrDefault()?.Object is RDFTypedLiteral facetPattern
296+
if (graph.SelectTriples(s: facet, p: RDFVocabulary.XSD.PATTERN).FirstOrDefault()?.Object is RDFTypedLiteral facetPattern
297297
&& facetPattern.HasStringDatatype())
298298
{
299299
targetFacets.Add(new RDFPatternFacet(facetPattern.Value));
@@ -305,7 +305,7 @@ public static List<RDFDatatype> ExtractDatatypeDefinitions(this RDFGraph graph)
305305
}
306306

307307
//Try detect an alias datatype
308-
else if (graph[s: datatypeIRI, p: RDFVocabulary.OWL.EQUIVALENT_CLASS].FirstOrDefault()?.Object is RDFResource equivalentDatatype)
308+
else if (graph.SelectTriples(s: datatypeIRI, p: RDFVocabulary.OWL.EQUIVALENT_CLASS).FirstOrDefault()?.Object is RDFResource equivalentDatatype)
309309
{
310310
//Detect the target datatype (fallback to rdfs:Literal in case not found)
311311
RDFDatatype targetDatatype = RDFDatatypeRegister.GetDatatype(equivalentDatatype.ToString())
@@ -337,7 +337,7 @@ internal static RDFCollection DeserializeCollectionFromGraph(RDFGraph graph, RDF
337337
while (!nilFound)
338338
{
339339
#region rdf:first
340-
RDFTriple first = rdfFirst[s: itemRest].FirstOrDefault();
340+
RDFTriple first = rdfFirst.SelectTriples(s: itemRest).FirstOrDefault();
341341
if (first != null)
342342
{
343343
if (first.Object is RDFResource firstObjRes)
@@ -361,7 +361,7 @@ internal static RDFCollection DeserializeCollectionFromGraph(RDFGraph graph, RDF
361361
//Ensure considering exit signal from bad-formed rdf:first
362362
if (!nilFound)
363363
{
364-
RDFTriple rest = rdfRest[s: itemRest].FirstOrDefault();
364+
RDFTriple rest = rdfRest.SelectTriples(s: itemRest).FirstOrDefault();
365365
if (rest != null)
366366
{
367367
if (rest.Object.Equals(RDFVocabulary.RDF.NIL))
@@ -392,7 +392,7 @@ internal static RDFCollection DeserializeCollectionFromGraph(RDFGraph graph, RDF
392392
/// Detects the flavor (SPO/SPL) of the collection represented by the given resource within the given graph
393393
/// </summary>
394394
internal static RDFModelEnums.RDFTripleFlavors DetectCollectionFlavorFromGraph(RDFGraph graph, RDFResource collRepresentative)
395-
=> graph[s: collRepresentative, p: RDFVocabulary.RDF.FIRST].FirstOrDefault()?.TripleFlavor ?? RDFModelEnums.RDFTripleFlavors.SPO;
395+
=> graph.SelectTriples(s: collRepresentative, p: RDFVocabulary.RDF.FIRST).FirstOrDefault()?.TripleFlavor ?? RDFModelEnums.RDFTripleFlavors.SPO;
396396
#endregion
397397

398398
#region Namespaces

0 commit comments

Comments
 (0)