Skip to content

Commit

Permalink
#67 FIX added logics for handling disjoint Exists/NotExists filter
Browse files Browse the repository at this point in the history
  • Loading branch information
mdesalvo committed Aug 18, 2019
1 parent f473af5 commit 3b4e352
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 45 deletions.
103 changes: 59 additions & 44 deletions RDFSharp/Query/Mirella/Algebra/Filters/RDFExistsFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,65 +91,80 @@ internal override Boolean ApplyFilter(DataRow row, Boolean applyNegation)
if (patternResultsEnumerable?.Any() ?? false)
{

#region Evaluation
#region Disjoint Evaluation
//In case of disjointess between the query and the filter's pattern, all solutions are compatible
Boolean disjointSubject = this.Pattern.Subject is RDFVariable ?
!row.Table.Columns.Contains(this.Pattern.Subject.ToString()) : true;
Boolean disjointPredicate = this.Pattern.Predicate is RDFVariable ?
!row.Table.Columns.Contains(this.Pattern.Predicate.ToString()) : true;
Boolean disjointObject = this.Pattern.Object is RDFVariable ?
!row.Table.Columns.Contains(this.Pattern.Object.ToString()) : true;
if (disjointSubject && disjointPredicate && disjointObject)
keepRow = true;
#endregion

#region Subject
Boolean subjectCompared = false;
if (this.Pattern.Subject is RDFVariable
&& this.PatternResults.Columns.Contains(this.Pattern.Subject.ToString())
&& row.Table.Columns.Contains(this.Pattern.Subject.ToString()))
#region Non-Disjoint Evaluation
else
{

//Get subject filter's value for the given row
RDFPatternMember rowMember = RDFQueryUtilities.ParseRDFPatternMember(row[this.Pattern.Subject.ToString()].ToString());
#region Subject
Boolean subjectCompared = false;
if (this.Pattern.Subject is RDFVariable
&& this.PatternResults.Columns.Contains(this.Pattern.Subject.ToString())
&& row.Table.Columns.Contains(this.Pattern.Subject.ToString()))
{

//Apply subject filter on the pattern resultset
patternResultsEnumerable = patternResultsEnumerable.Where(x => RDFQueryUtilities.ParseRDFPatternMember(x.Field<String>(this.Pattern.Subject.ToString())).Equals(rowMember));
subjectCompared = true;
//Get subject filter's value for the given row
RDFPatternMember rowMember = RDFQueryUtilities.ParseRDFPatternMember(row[this.Pattern.Subject.ToString()].ToString());

}
#endregion
//Apply subject filter on the pattern resultset
patternResultsEnumerable = patternResultsEnumerable.Where(x => RDFQueryUtilities.ParseRDFPatternMember(x.Field<String>(this.Pattern.Subject.ToString())).Equals(rowMember));
subjectCompared = true;

#region Predicate
Boolean predicateCompared = false;
if (this.Pattern.Predicate is RDFVariable
&& this.PatternResults.Columns.Contains(this.Pattern.Predicate.ToString())
&& row.Table.Columns.Contains(this.Pattern.Predicate.ToString()))
{
}
#endregion

//Get predicate filter's value for the given row
RDFPatternMember rowMember = RDFQueryUtilities.ParseRDFPatternMember(row[this.Pattern.Predicate.ToString()].ToString());
#region Predicate
Boolean predicateCompared = false;
if (this.Pattern.Predicate is RDFVariable
&& this.PatternResults.Columns.Contains(this.Pattern.Predicate.ToString())
&& row.Table.Columns.Contains(this.Pattern.Predicate.ToString()))
{

//Apply predicate filter on the pattern resultset
patternResultsEnumerable = patternResultsEnumerable.Where(x => RDFQueryUtilities.ParseRDFPatternMember(x.Field<String>(this.Pattern.Predicate.ToString())).Equals(rowMember));
predicateCompared = true;
//Get predicate filter's value for the given row
RDFPatternMember rowMember = RDFQueryUtilities.ParseRDFPatternMember(row[this.Pattern.Predicate.ToString()].ToString());

}
#endregion
//Apply predicate filter on the pattern resultset
patternResultsEnumerable = patternResultsEnumerable.Where(x => RDFQueryUtilities.ParseRDFPatternMember(x.Field<String>(this.Pattern.Predicate.ToString())).Equals(rowMember));
predicateCompared = true;

#region Object
Boolean objectCompared = false;
if (this.Pattern.Object is RDFVariable
&& this.PatternResults.Columns.Contains(this.Pattern.Object.ToString())
&& row.Table.Columns.Contains(this.Pattern.Object.ToString()))
{
}
#endregion

//Get object filter's value for the given row
RDFPatternMember rowMember = RDFQueryUtilities.ParseRDFPatternMember(row[this.Pattern.Object.ToString()].ToString());
#region Object
Boolean objectCompared = false;
if (this.Pattern.Object is RDFVariable
&& this.PatternResults.Columns.Contains(this.Pattern.Object.ToString())
&& row.Table.Columns.Contains(this.Pattern.Object.ToString()))
{

//Apply object filter on the pattern resultset
patternResultsEnumerable = patternResultsEnumerable.Where(x => RDFQueryUtilities.ParseRDFPatternMember(x.Field<String>(this.Pattern.Object.ToString())).Equals(rowMember));
objectCompared = true;
//Get object filter's value for the given row
RDFPatternMember rowMember = RDFQueryUtilities.ParseRDFPatternMember(row[this.Pattern.Object.ToString()].ToString());

}
#endregion
//Apply object filter on the pattern resultset
patternResultsEnumerable = patternResultsEnumerable.Where(x => RDFQueryUtilities.ParseRDFPatternMember(x.Field<String>(this.Pattern.Object.ToString())).Equals(rowMember));
objectCompared = true;

#endregion
}
#endregion

#region Decision
//Verify filter's response on the pattern resultset
if ((subjectCompared || predicateCompared || objectCompared) && patternResultsEnumerable.ToList().Any())
keepRow = true;
#region Decision
//Verify filter's response on the pattern resultset
if ((subjectCompared || predicateCompared || objectCompared) && patternResultsEnumerable.ToList().Any())
keepRow = true;
#endregion

}
#endregion

}
Expand Down
2 changes: 1 addition & 1 deletion RDFSharp/RDFSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<AssemblyTitle>RDFSharp</AssemblyTitle>
<AssemblyName>RDFSharp</AssemblyName>
<AssemblyVersion>$(Version)</AssemblyVersion>
<Version>2.6.0.0</Version>
<Version>2.6.1.0</Version>
<Authors>Marco De Salvo</Authors>
<Copyright>Marco De Salvo</Copyright>
<Description>Start playing with RDF!</Description>
Expand Down

0 comments on commit 3b4e352

Please sign in to comment.