Skip to content

Commit

Permalink
Quality suggestions from Rider
Browse files Browse the repository at this point in the history
  • Loading branch information
mdesalvo committed Feb 9, 2025
1 parent 777fe4c commit 9ea006d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion RDFSharp/Model/Serializers/RDFTurtle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions RDFSharp/Model/Validation/Abstractions/RDFShapesGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 5 additions & 8 deletions RDFSharp/Model/Validation/RDFValidationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,10 @@ internal static List<RDFPatternMember> 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)
Expand Down Expand Up @@ -152,8 +150,7 @@ internal static List<RDFPatternMember> 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])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 13 additions & 9 deletions RDFSharp/Query/Mirella/Algebra/Modifiers/RDFGroupByModifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> unavailablePartitionVariables = PartitionVariables.Where(pv => !table.Columns.Contains(pv.ToString()))
.Select(pv => pv.ToString());
List<string> 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<string> unavailableAggregatorVariables = Aggregators.Where(ag => !table.Columns.Contains(ag.AggregatorVariable.ToString()))
.Select(ag => ag.AggregatorVariable.ToString());
List<string> 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<string> commonPartitionProjectionVariables = PartitionVariables.Where(pv => Aggregators.Any(ag => (!(ag is RDFPartitionAggregator)) && pv.Equals(ag.ProjectionVariable)))
.Select(pav => pav.ToString());
List<string> 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())}");
}

/// <summary>
/// Executes partition algorythm
/// Executes partition algorithm
/// </summary>
private void ExecutePartitionAlgorythm(DataTable table)
{
Expand Down Expand Up @@ -170,8 +173,9 @@ private DataTable ExecuteFilterAlgorythm(DataTable resultTable)
{
DataTable filteredTable = resultTable.Clone();
IEnumerator rowsEnum = resultTable.Rows.GetEnumerator();
IEnumerable<RDFComparisonFilter> havingFilters = Aggregators.Where(ag => ag.HavingClause.Item1)
.Select(ag => new RDFComparisonFilter(ag.HavingClause.Item2, ag.ProjectionVariable, ag.HavingClause.Item3));
List<RDFComparisonFilter> 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())
{
Expand Down

0 comments on commit 9ea006d

Please sign in to comment.