From 9ea006d34766c5f7249e1fdb6e6e4387cb90c31a Mon Sep 17 00:00:00 2001 From: mdesalvo Date: Sun, 9 Feb 2025 11:55:37 +0100 Subject: [PATCH] Quality suggestions from Rider --- RDFSharp/Model/Serializers/RDFTurtle.cs | 2 +- .../Validation/Abstractions/RDFShapesGraph.cs | 4 ++-- .../Model/Validation/RDFValidationHelper.cs | 13 +++++------ .../Expressions/RDFComparisonExpression.cs | 2 +- .../Algebra/Modifiers/RDFGroupByModifier.cs | 22 +++++++++++-------- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/RDFSharp/Model/Serializers/RDFTurtle.cs b/RDFSharp/Model/Serializers/RDFTurtle.cs index c800b3f0..73d58aa9 100644 --- a/RDFSharp/Model/Serializers/RDFTurtle.cs +++ b/RDFSharp/Model/Serializers/RDFTurtle.cs @@ -1523,7 +1523,7 @@ orderby triple.Subject.ToString(), triple.Predicate.ToString() { subj = triple.Subject.ToString(), pred = triple.Predicate.ToString() - }); + }).ToList(); var lastGroupOfTriples = triplesGroupedBySubjectAndPredicate.LastOrDefault(); #endregion diff --git a/RDFSharp/Model/Validation/Abstractions/RDFShapesGraph.cs b/RDFSharp/Model/Validation/Abstractions/RDFShapesGraph.cs index a3907a6e..c81e2b93 100644 --- a/RDFSharp/Model/Validation/Abstractions/RDFShapesGraph.cs +++ b/RDFSharp/Model/Validation/Abstractions/RDFShapesGraph.cs @@ -16,6 +16,7 @@ limitations under the License. using System.Collections; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; namespace RDFSharp.Model @@ -131,8 +132,7 @@ public RDFGraph ToRDFGraph() { RDFGraph result = new RDFGraph(); - foreach (RDFShape shape in this) - result = result.UnionWith(shape.ToRDFGraph()); + result = this.Aggregate(result, (current, shape) => current.UnionWith(shape.ToRDFGraph())); result.SetContext(URI); return result; diff --git a/RDFSharp/Model/Validation/RDFValidationHelper.cs b/RDFSharp/Model/Validation/RDFValidationHelper.cs index 5ead04cb..71849be6 100644 --- a/RDFSharp/Model/Validation/RDFValidationHelper.cs +++ b/RDFSharp/Model/Validation/RDFValidationHelper.cs @@ -106,12 +106,10 @@ internal static List GetValueNodesOf(this RDFGraph dataGraph, //Compute property path on the given focus node DataTable pathResult = new RDFQueryEngine().ApplyPropertyPath( isAlternativePath ? propertyShape.AlternativePath : propertyShape.SequencePath, dataGraph); - foreach (DataRow pathResultRow in pathResult.Rows) - { - string prValue = pathResultRow["?END"]?.ToString(); - if (!string.IsNullOrEmpty(prValue)) - result.Add(RDFQueryUtilities.ParseRDFPatternMember(prValue)); - } + result.AddRange(from DataRow pathResultRow + in pathResult.Rows + select pathResultRow["?END"]?.ToString() into prValue where !string.IsNullOrEmpty(prValue) + select RDFQueryUtilities.ParseRDFPatternMember(prValue)); //Recontextualize property path to the initial configuration if (isAlternativePath) @@ -152,8 +150,7 @@ internal static List GetInstancesOfClass(this RDFGraph dataGra #endregion //rdf:type - foreach (RDFTriple triple in dataGraph[null, RDFVocabulary.RDF.TYPE, className, null]) - result.Add(triple.Subject); + result.AddRange(dataGraph[null, RDFVocabulary.RDF.TYPE, className, null].Select(triple => triple.Subject)); //rdfs:subClassOf foreach (RDFTriple triple in dataGraph[null, RDFVocabulary.RDFS.SUB_CLASS_OF, className, null]) diff --git a/RDFSharp/Query/Mirella/Algebra/Expressions/RDFComparisonExpression.cs b/RDFSharp/Query/Mirella/Algebra/Expressions/RDFComparisonExpression.cs index 685698e3..f387a86a 100644 --- a/RDFSharp/Query/Mirella/Algebra/Expressions/RDFComparisonExpression.cs +++ b/RDFSharp/Query/Mirella/Algebra/Expressions/RDFComparisonExpression.cs @@ -151,7 +151,7 @@ internal override RDFPatternMember ApplyExpression(DataRow row) { #region Evaluate Arguments //Evaluate left argument (Expression VS Variable) - RDFPatternMember leftArgumentPMember = null; + RDFPatternMember leftArgumentPMember; if (LeftArgument is RDFExpression leftArgumentExpression) leftArgumentPMember = leftArgumentExpression.ApplyExpression(row); else diff --git a/RDFSharp/Query/Mirella/Algebra/Modifiers/RDFGroupByModifier.cs b/RDFSharp/Query/Mirella/Algebra/Modifiers/RDFGroupByModifier.cs index ee8254e0..ae13e1fb 100644 --- a/RDFSharp/Query/Mirella/Algebra/Modifiers/RDFGroupByModifier.cs +++ b/RDFSharp/Query/Mirella/Algebra/Modifiers/RDFGroupByModifier.cs @@ -117,26 +117,29 @@ internal override DataTable ApplyModifier(DataTable table) private void ConsistencyChecks(DataTable table) { //Every partition variable must be found in the working table as a column - IEnumerable unavailablePartitionVariables = PartitionVariables.Where(pv => !table.Columns.Contains(pv.ToString())) - .Select(pv => pv.ToString()); + List unavailablePartitionVariables = PartitionVariables.Where(pv => !table.Columns.Contains(pv.ToString())) + .Select(pv => pv.ToString()) + .ToList(); if (unavailablePartitionVariables.Any()) throw new RDFQueryException($"Cannot apply GroupBy modifier because the working table does not contain the following columns needed for partitioning: {string.Join(",", unavailablePartitionVariables.Distinct())}"); //Every aggregator variable must be found in the working table as a column - IEnumerable unavailableAggregatorVariables = Aggregators.Where(ag => !table.Columns.Contains(ag.AggregatorVariable.ToString())) - .Select(ag => ag.AggregatorVariable.ToString()); + List unavailableAggregatorVariables = Aggregators.Where(ag => !table.Columns.Contains(ag.AggregatorVariable.ToString())) + .Select(ag => ag.AggregatorVariable.ToString()) + .ToList(); if (unavailableAggregatorVariables.Any()) throw new RDFQueryException($"Cannot apply GroupBy modifier because the working table does not contain the following columns needed for aggregation: {string.Join(",", unavailableAggregatorVariables.Distinct())}"); //There should NOT be intersection between partition variables (GroupBy) and projection variables (Aggregators) - IEnumerable commonPartitionProjectionVariables = PartitionVariables.Where(pv => Aggregators.Any(ag => (!(ag is RDFPartitionAggregator)) && pv.Equals(ag.ProjectionVariable))) - .Select(pav => pav.ToString()); + List commonPartitionProjectionVariables = PartitionVariables.Where(pv => Aggregators.Any(ag => (!(ag is RDFPartitionAggregator)) && pv.Equals(ag.ProjectionVariable))) + .Select(pav => pav.ToString()) + .ToList(); if (commonPartitionProjectionVariables.Any()) throw new RDFQueryException($"Cannot apply GroupBy modifier because the following variables have been specified both for partitioning (in GroupBy) and projection (in Aggregator): {string.Join(",", commonPartitionProjectionVariables.Distinct())}"); } /// - /// Executes partition algorythm + /// Executes partition algorithm /// private void ExecutePartitionAlgorythm(DataTable table) { @@ -170,8 +173,9 @@ private DataTable ExecuteFilterAlgorythm(DataTable resultTable) { DataTable filteredTable = resultTable.Clone(); IEnumerator rowsEnum = resultTable.Rows.GetEnumerator(); - IEnumerable havingFilters = Aggregators.Where(ag => ag.HavingClause.Item1) - .Select(ag => new RDFComparisonFilter(ag.HavingClause.Item2, ag.ProjectionVariable, ag.HavingClause.Item3)); + List havingFilters = Aggregators.Where(ag => ag.HavingClause.Item1) + .Select(ag => new RDFComparisonFilter(ag.HavingClause.Item2, ag.ProjectionVariable, ag.HavingClause.Item3)) + .ToList(); #region ExecuteFilters while (rowsEnum.MoveNext()) {