-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
So far, our class `TripleComponent` stored a parsed literal as a `std::string`. The class already had own types for `Variable`, `UNDEF`, and double or integer values. Now it also has an own type `Literal` (which is is implemented using a new class `NormalizedRDFString`). It remains to also add own types for IRIs and blank nodes.
- Loading branch information
Showing
26 changed files
with
558 additions
and
320 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
// Copyright 2021, University of Freiburg, Chair of Algorithms and Data | ||
// Structures. Author: Johannes Kalmbach <[email protected]> | ||
|
||
// | ||
// Created by johannes on 29.09.21. | ||
// | ||
// Copyright 2021, University of Freiburg, | ||
// Chair of Algorithms and Data Structures. | ||
// Author: Johannes Kalmbach <[email protected]> | ||
|
||
#ifndef QLEVER_LITERALEXPRESSION_H | ||
#define QLEVER_LITERALEXPRESSION_H | ||
|
@@ -20,23 +17,28 @@ template <typename T> | |
class LiteralExpression : public SparqlExpression { | ||
public: | ||
// _________________________________________________________________________ | ||
LiteralExpression(T _value) : _value{std::move(_value)} {} | ||
explicit LiteralExpression(T _value) : _value{std::move(_value)} {} | ||
|
||
// A simple getter for the stored value. | ||
const T& value() const { return _value; } | ||
|
||
// Evaluating just returns the constant/literal value. | ||
ExpressionResult evaluate( | ||
[[maybe_unused]] EvaluationContext* context) const override { | ||
if constexpr (std::is_same_v<string, T>) { | ||
// Common code for the `Literal` and `std::string` case. | ||
auto getIdOrString = [&context](const std::string& s) -> ExpressionResult { | ||
Id id; | ||
bool idWasFound = context->_qec.getIndex().getId(_value, &id); | ||
bool idWasFound = context->_qec.getIndex().getId(s, &id); | ||
if (!idWasFound) { | ||
// no vocabulary entry found, just use it as a string constant. | ||
// TODO<joka921>:: emit a warning. | ||
return _value; | ||
return s; | ||
} | ||
return id; | ||
}; | ||
if constexpr (std::is_same_v<TripleComponent::Literal, T>) { | ||
return getIdOrString(_value.rawContent()); | ||
} else if constexpr (std::is_same_v<string, T>) { | ||
return getIdOrString(_value); | ||
} else if constexpr (std::is_same_v<Variable, T>) { | ||
// If a variable is grouped, then we know that it always has the same | ||
// value and can treat it as a constant. This is not possible however when | ||
|
@@ -91,6 +93,8 @@ class LiteralExpression : public SparqlExpression { | |
return _value; | ||
} else if constexpr (std::is_same_v<T, ValueId>) { | ||
return absl::StrCat("#valueId ", _value.getBits(), "#"); | ||
} else if constexpr (std::is_same_v<T, TripleComponent::Literal>) { | ||
return absl::StrCat("#literal: ", _value.rawContent()); | ||
} else { | ||
return {std::to_string(_value)}; | ||
} | ||
|
@@ -120,7 +124,9 @@ using BoolExpression = detail::LiteralExpression<bool>; | |
using IntExpression = detail::LiteralExpression<int64_t>; | ||
using DoubleExpression = detail::LiteralExpression<double>; | ||
using VariableExpression = detail::LiteralExpression<::Variable>; | ||
using StringOrIriExpression = detail::LiteralExpression<string>; | ||
using IriExpression = detail::LiteralExpression<string>; | ||
using StringLiteralExpression = | ||
detail::LiteralExpression<TripleComponent::Literal>; | ||
using IdExpression = detail::LiteralExpression<ValueId>; | ||
} // namespace sparqlExpression | ||
|
||
|
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
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
Oops, something went wrong.