-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IsSomethingExpression now returns respective IsDatatypeExpression pre…
…filter
- Loading branch information
1 parent
1b97db3
commit a408822
Showing
3 changed files
with
99 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
// Chair of Algorithms and Data Structures. | ||
// Author: Hannah Bast <[email protected]> | ||
|
||
#include "engine/sparqlExpressions/LiteralExpression.h" | ||
#include "engine/sparqlExpressions/NaryExpressionImpl.h" | ||
#include "engine/sparqlExpressions/SparqlExpressionValueGetters.h" | ||
|
||
|
@@ -23,18 +24,59 @@ namespace detail { | |
// `SparqlExpression::Ptr` and returns a `unique_ptr` to a new instance of | ||
// `...Expression` (`std::move` the arguments into the constructor). The | ||
// function should be declared in `NaryExpression.h`. | ||
template <typename NaryOperation, prefilterExpressions::IsDatatype Datatype> | ||
requires(isOperation<NaryOperation>) | ||
class IsDatatypeExpressionImpl : public NaryExpression<NaryOperation> { | ||
public: | ||
using NaryExpression<NaryOperation>::NaryExpression; | ||
std::vector<PrefilterExprVariablePair> getPrefilterExpressionForMetadata( | ||
[[maybe_unused]] bool isNegated) const override { | ||
using namespace prefilterExpressions; | ||
std::vector<PrefilterExprVariablePair> prefilterVec; | ||
const SparqlExpression* childExpr = this->getNthChild(0).value_or(nullptr); | ||
if (!childExpr) { | ||
return prefilterVec; | ||
} | ||
// Pre-filtering is only applicable if `isDatatype()` references a | ||
// `VariableExpression` (e.g. `isLiteral(?x)`). | ||
const auto* variableExpr = | ||
dynamic_cast<const VariableExpression*>(childExpr); | ||
if (!variableExpr) { | ||
return prefilterVec; | ||
} | ||
|
||
prefilterVec.emplace_back( | ||
std::make_unique<IsDatatypeExpression<Datatype>>(), | ||
variableExpr->value()); | ||
return prefilterVec; | ||
} | ||
}; | ||
|
||
//______________________________________________________________________________ | ||
// Expressions for the builtin functions `isIRI`, `isBlank`, `isLiteral`, | ||
// `isNumeric`, and the custom function `isWktPoint`. Note that the value | ||
// getters already return the correct `Id`, hence `std::identity`. | ||
using isIriExpression = NARY<1, FV<std::identity, IsIriValueGetter>>; | ||
using isLiteralExpression = NARY<1, FV<std::identity, IsLiteralValueGetter>>; | ||
using isNumericExpression = NARY<1, FV<std::identity, IsNumericValueGetter>>; | ||
template <typename Getter, prefilterExpressions::IsDatatype Datatype> | ||
using IsDtypeExpression = | ||
IsDatatypeExpressionImpl<Operation<1, FV<std::identity, Getter>>, Datatype>; | ||
|
||
using isLiteralExpression = | ||
IsDtypeExpression<IsLiteralValueGetter, | ||
prefilterExpressions::IsDatatype::LITERAL>; | ||
using isNumericExpression = | ||
IsDtypeExpression<IsNumericValueGetter, | ||
prefilterExpressions::IsDatatype::NUMERIC>; | ||
using isBlankExpression = | ||
NARY<1, FV<std::identity, IsValueIdValueGetter<Datatype::BlankNodeIndex>>>; | ||
IsDtypeExpression<IsValueIdValueGetter<Datatype::BlankNodeIndex>, | ||
prefilterExpressions::IsDatatype::BLANK>; | ||
using isIriExpression = | ||
IsDtypeExpression<IsIriValueGetter, prefilterExpressions::IsDatatype::IRI>; | ||
|
||
// We currently don't support pre-filtering for `isGeoPointExpression`. | ||
using isGeoPointExpression = | ||
NARY<1, FV<std::identity, IsValueIdValueGetter<Datatype::GeoPoint>>>; | ||
|
||
//______________________________________________________________________________ | ||
// The expression for `bound` is slightly different as `IsValidValueGetter` | ||
// returns a `bool` and not an `Id`. | ||
inline auto boolToId = [](bool b) { return Id::makeFromBool(b); }; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters