Skip to content

Commit

Permalink
Also dddxfxixiasdflkjthed export.
Browse files Browse the repository at this point in the history
  • Loading branch information
joka921 committed Mar 20, 2024
1 parent 0e921fd commit 7f8d909
Show file tree
Hide file tree
Showing 23 changed files with 121 additions and 114 deletions.
9 changes: 4 additions & 5 deletions src/engine/sparqlExpressions/LiteralExpression.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ class LiteralExpression : public SparqlExpression {
}
auto id = context->_qec.getIndex().getId(s);
IdOrString result =
id.has_value()
? IdOrString{id.value()}
: IdOrString{std::string{s.toInternalRepresentation()}};
id.has_value() ? IdOrString{id.value()}
: IdOrString{std::string{s.toStringRepresentation()}};
auto ptrForCache = std::make_unique<IdOrString>(result);
ptrForCache.reset(std::atomic_exchange_explicit(
&cachedResult_, ptrForCache.release(), std::memory_order_relaxed));
Expand Down Expand Up @@ -104,9 +103,9 @@ class LiteralExpression : public SparqlExpression {
} 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.toInternalRepresentation());
return absl::StrCat("#literal: ", _value.toStringRepresentation());
} else if constexpr (std::is_same_v<T, TripleComponent::Iri>) {
return absl::StrCat("#iri: ", _value.toInternalRepresentation());
return absl::StrCat("#iri: ", _value.toStringRepresentation());
} else if constexpr (std::is_same_v<T, VectorWithMemoryLimit<ValueId>>) {
// We should never cache this, as objects of this type of expression are
// used exactly *once* in the HashMap optimization of the GROUP BY
Expand Down
7 changes: 4 additions & 3 deletions src/index/IndexBuilderTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ auto getIdMapLambdas(
// This is not necessary for the actual QLever code, but certain unit tests
// currently fail without it.
itemArray[j]->getId(TripleComponent{
ad_utility::triple_component::Iri::iriref(LANGUAGE_PREDICATE)});
ad_utility::triple_component::Iri::fromIriref(LANGUAGE_PREDICATE)});
}
using OptionalIds = std::array<std::optional<std::array<Id, 3>>, 3>;

Expand Down Expand Up @@ -278,8 +278,9 @@ auto getIdMapLambdas(
// extra triple <object> ql:language-tag <@language>
res[2].emplace(std::array<Id, 3>{
spoIds[2],
map.getId(TripleComponent{
ad_utility::triple_component::Iri::iriref(LANGUAGE_PREDICATE)}),
map.getId(
TripleComponent{ad_utility::triple_component::Iri::fromIriref(
LANGUAGE_PREDICATE)}),
langTagId});
}
return res;
Expand Down
2 changes: 1 addition & 1 deletion src/index/IndexImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ std::optional<string> IndexImpl::idToOptionalString(WordVocabIndex id) const {
std::optional<Id> IndexImpl::getIdImpl(const auto& element) const {
VocabIndex vocabIndex;
auto success =
getVocab().getId(element.toInternalRepresentation(), &vocabIndex);
getVocab().getId(element.toStringRepresentation(), &vocabIndex);
if (!success) {
return std::nullopt;
}
Expand Down
8 changes: 4 additions & 4 deletions src/parser/Iri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ NormalizedStringView Iri::getContent() const {
}

// __________________________________________
Iri Iri::iriref(std::string_view stringWithBrackets) {
Iri Iri::fromIriref(std::string_view stringWithBrackets) {
auto first = stringWithBrackets.find('<');
AD_CORRECTNESS_CHECK(first != std::string_view::npos);
return Iri{
Expand All @@ -35,19 +35,19 @@ Iri Iri::iriref(std::string_view stringWithBrackets) {
}

// __________________________________________
Iri Iri::prefixed(const Iri& prefix, std::string_view suffix) {
Iri Iri::fromPrefixAndSuffix(const Iri& prefix, std::string_view suffix) {
auto suffixNormalized = RdfEscaping::unescapePrefixedIri(suffix);
return Iri{prefix, asNormalizedStringViewUnsafe(suffixNormalized)};
}

// __________________________________________
Iri Iri::fromInternalRepresentation(std::string_view s) {
Iri Iri::fromStringRepresentation(std::string_view s) {
AD_CORRECTNESS_CHECK(s.starts_with("<") || s.starts_with("@"));
return Iri{NormalizedString{asNormalizedStringViewUnsafe(s)}};
}

// __________________________________________
std::string_view Iri::toInternalRepresentation() const {
std::string_view Iri::toStringRepresentation() const {
return asStringViewUnsafe(iri_);
}

Expand Down
8 changes: 4 additions & 4 deletions src/parser/Iri.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ class Iri {
asStringViewUnsafe(NormalizedStringView(iri.iri_)));
}
bool operator==(const Iri&) const = default;
static Iri fromInternalRepresentation(std::string_view s);
static Iri fromStringRepresentation(std::string_view s);

std::string_view toInternalRepresentation() const;
std::string_view toStringRepresentation() const;

// Create a new iri given an iri with brackets
static Iri iriref(std::string_view stringWithBrackets);
static Iri fromIriref(std::string_view stringWithBrackets);

// Create a new iri given a prefix iri and its suffix
static Iri prefixed(const Iri& prefix, std::string_view suffix);
static Iri fromPrefixAndSuffix(const Iri& prefix, std::string_view suffix);

// Return the string value of the iri object without any leading or trailing
// angled brackets.
Expand Down
33 changes: 15 additions & 18 deletions src/parser/Literal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@

#include "parser/LiteralOrIri.h"

static constexpr NormalizedChar quote{'"'};
static constexpr NormalizedChar at{'@'};
static constexpr NormalizedChar hat{'^'};

namespace ad_utility::triple_component {
// __________________________________________
Literal::Literal(NormalizedString content, size_t beginOfSuffix)
: content_{std::move(content)}, beginOfSuffix_{beginOfSuffix} {
NormalizedChar quote{'"'};
NormalizedChar at{'@'};
NormalizedChar hat{'^'};
AD_CORRECTNESS_CHECK(content_.starts_with(quote));
AD_CORRECTNESS_CHECK(beginOfSuffix_ >= 2);
AD_CORRECTNESS_CHECK(content_[beginOfSuffix_ - 1] == quote);
Expand All @@ -25,14 +26,10 @@ Literal::Literal(NormalizedString content, size_t beginOfSuffix)
}

// __________________________________________
bool Literal::hasLanguageTag() const {
return getSuffix().starts_with(NormalizedChar{'@'});
}
bool Literal::hasLanguageTag() const { return getSuffix().starts_with(at); }

// __________________________________________
bool Literal::hasDatatype() const {
return getSuffix().starts_with(NormalizedChar{'^'});
}
bool Literal::hasDatatype() const { return getSuffix().starts_with(hat); }

// __________________________________________
NormalizedStringView Literal::getContent() const {
Expand Down Expand Up @@ -60,9 +57,9 @@ NormalizedStringView Literal::getLanguageTag() const {
}

// __________________________________________
Literal Literal::literalWithQuotes(
Literal Literal::fromEscapedRdfLiteral(
std::string_view rdfContentWithQuotes,
std::optional<std::variant<Iri, string>> descriptor) {
std::optional<std::variant<Iri, std::string>> descriptor) {
NormalizedString content =
RdfEscaping::normalizeLiteralWithQuotes(rdfContentWithQuotes);

Expand Down Expand Up @@ -107,30 +104,30 @@ Literal Literal::literalWithNormalizedContent(

// __________________________________________
void Literal::addLanguageTag(std::string_view languageTag) {
content_.push_back(NormalizedChar{'@'});
content_.push_back(at);
content_.append(RdfEscaping::normalizeLanguageTag(languageTag));
}

// __________________________________________
void Literal::addDatatype(const Iri& datatype) {
content_.append(asNormalizedStringViewUnsafe("^^"));
content_.append(
asNormalizedStringViewUnsafe(datatype.toInternalRepresentation()));
asNormalizedStringViewUnsafe(datatype.toStringRepresentation()));
}

// __________________________________________
std::string_view Literal::toInternalRepresentation() const {
std::string_view Literal::toStringRepresentation() const {
return asStringViewUnsafe(content_);
}

// __________________________________________
Literal Literal::fromInternalRepresentation(std::string_view input) {
Literal Literal::fromStringRepresentation(std::string_view internal) {
// TODO<joka921> This is a little dangerous as there might be quotes in the
// IRI which might lead to unexpected results here.
AD_CORRECTNESS_CHECK(input.starts_with('"'));
auto endIdx = input.rfind('"');
AD_CORRECTNESS_CHECK(internal.starts_with('"'));
auto endIdx = internal.rfind('"');
AD_CORRECTNESS_CHECK(endIdx > 0);
return Literal{NormalizedString{asNormalizedStringViewUnsafe(input)},
return Literal{NormalizedString{asNormalizedStringViewUnsafe(internal)},
endIdx + 1};
}

Expand Down
23 changes: 15 additions & 8 deletions src/parser/Literal.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,28 @@ namespace ad_utility::triple_component {
// A class to hold literal values.
class Literal {
private:
// Store the string value of the literal without the surrounding quotation
// marks or trailing descriptor.
// "Hello World"@en -> Hello World
// Store the normalized version of the literal, including possible datatypes
// and descriptors.
// For example `"Hello World"@en` or `"With"Quote"^^<someDatatype>` (note
// that the quote in the middle is unescaped because this is the normalized
// form that QLever stores.
NormalizedString content_;
// The position after the closing `"`, so either the size of the string, or
// the position of the `@` or `^^` for literals with language tags or
// datatypes.
std::size_t beginOfSuffix_;

// Create a new literal without any descriptor
explicit Literal(NormalizedString content, size_t beginOfSuffix_);

// Similar to `literalWithQuotes`, except the rdfContent is expected to
// Similar to `fromEscapedRdfLiteral`, except the rdfContent is expected to
// already be normalized
static Literal literalWithNormalizedContent(
NormalizedString normalizedRdfContent,
std::optional<std::variant<Iri, std::string>> descriptor = std::nullopt);

// Internal helper function. Return either the empty string (for a plain
// literal), `@langtag` or `^^<datatypeIri>`.
NormalizedStringView getSuffix() const {
NormalizedStringView result = content_;
result.remove_prefix(beginOfSuffix_);
Expand All @@ -39,9 +46,9 @@ class Literal {
}
bool operator==(const Literal&) const = default;

std::string_view toInternalRepresentation() const;
std::string_view toStringRepresentation() const;

static Literal fromInternalRepresentation(std::string_view internal);
static Literal fromStringRepresentation(std::string_view internal);

// Return true if the literal has an assigned language tag
bool hasLanguageTag() const;
Expand All @@ -62,8 +69,8 @@ class Literal {
NormalizedStringView getDatatype() const;

// For documentation, see documentation of function
// LiteralORIri::literalWithQuotes
static Literal literalWithQuotes(
// LiteralORIri::fromEscapedRdfLiteral
static Literal fromEscapedRdfLiteral(
std::string_view rdfContentWithQuotes,
std::optional<std::variant<Iri, std::string>> descriptor = std::nullopt);

Expand Down
8 changes: 4 additions & 4 deletions src/parser/LiteralOrIri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,21 @@ NormalizedStringView LiteralOrIri::getContent() const {

// __________________________________________
LiteralOrIri LiteralOrIri::iriref(const std::string& stringWithBrackets) {
return LiteralOrIri{Iri::iriref(stringWithBrackets)};
return LiteralOrIri{Iri::fromIriref(stringWithBrackets)};
}

// __________________________________________
LiteralOrIri LiteralOrIri::prefixedIri(const Iri& prefix,
std::string_view suffix) {
return LiteralOrIri{Iri::prefixed(prefix, suffix)};
return LiteralOrIri{Iri::fromPrefixAndSuffix(prefix, suffix)};
}

// __________________________________________
LiteralOrIri LiteralOrIri::literalWithQuotes(
std::string_view rdfContentWithQuotes,
std::optional<std::variant<Iri, string>> descriptor) {
return LiteralOrIri(
Literal::literalWithQuotes(rdfContentWithQuotes, std::move(descriptor)));
return LiteralOrIri(Literal::fromEscapedRdfLiteral(rdfContentWithQuotes,
std::move(descriptor)));
}

// __________________________________________
Expand Down
10 changes: 5 additions & 5 deletions src/parser/LiteralOrIri.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ class LiteralOrIri {

std::string toInternalRepresentation() const {
auto impl = [](const auto& val) {
return absl::StrCat(val.toInternalRepresentation());
return absl::StrCat(val.toStringRepresentation());
};
return std::visit(impl, data_);
}

static LiteralOrIri fromInternalRepresentation(std::string_view internal) {
char tag = internal.front();
if (tag == iriPrefixChar) {
return LiteralOrIri{Iri::fromInternalRepresentation(internal)};
return LiteralOrIri{Iri::fromStringRepresentation(internal)};
} else {
AD_CORRECTNESS_CHECK(tag == literalPrefixChar);
return LiteralOrIri{Literal::fromInternalRepresentation(internal)};
return LiteralOrIri{Literal::fromStringRepresentation(internal)};
}
}
template <typename H>
Expand Down Expand Up @@ -109,8 +109,8 @@ class LiteralOrIri {
std::string_view rdfContentWithQuotes,
std::optional<std::variant<Iri, std::string>> descriptor = std::nullopt);

// Similar to `literalWithQuotes`, except the rdfContent is expected to NOT BE
// surrounded by quotation marks.
// Similar to `fromEscapedRdfLiteral`, except the rdfContent is expected to
// NOT BE surrounded by quotation marks.
static LiteralOrIri literalWithoutQuotes(
std::string_view rdfContentWithoutQuotes,
std::optional<std::variant<Iri, std::string>> descriptor = std::nullopt);
Expand Down
2 changes: 1 addition & 1 deletion src/parser/ParsedQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class SparqlTriple : public SparqlTripleBase<PropertyPath> {
TripleComponent p =
isVariable(p_._iri)
? TripleComponent{Variable{p_._iri}}
: TripleComponent(TripleComponent::Iri::iriref(p_._iri));
: TripleComponent(TripleComponent::Iri::fromIriref(p_._iri));
return {s_, p, o_, additionalScanColumns_};
}
};
Expand Down
8 changes: 4 additions & 4 deletions src/parser/TripleComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ std::ostream& operator<<(std::ostream& stream, const TripleComponent& obj) {
} else if constexpr (std::is_same_v<T, TripleComponent::UNDEF>) {
stream << "UNDEF";
} else if constexpr (std::is_same_v<T, TripleComponent::Literal>) {
stream << value.toInternalRepresentation();
stream << value.toStringRepresentation();
} else if constexpr (std::is_same_v<T, TripleComponent::Iri>) {
stream << value.toInternalRepresentation();
stream << value.toStringRepresentation();
} else if constexpr (std::is_same_v<T, DateOrLargeYear>) {
stream << "DATE: " << value.toStringAndType().first;
} else if constexpr (std::is_same_v<T, bool>) {
Expand Down Expand Up @@ -72,9 +72,9 @@ std::string TripleComponent::toRdfLiteral() const {
} else if (isString()) {
return getString();
} else if (isLiteral()) {
return std::string{getLiteral().toInternalRepresentation()};
return std::string{getLiteral().toStringRepresentation()};
} else if (isIri()) {
return std::string{getIri().toInternalRepresentation()};
return std::string{getIri().toStringRepresentation()};
} else {
auto [value, type] =
ExportQueryExecutionTrees::idToStringAndTypeForEncodedValue(
Expand Down
8 changes: 4 additions & 4 deletions src/parser/TripleComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ class TripleComponent {
VocabIndex idx;
const std::string_view content = [&]() {
if (isLiteral()) {
return getLiteral().toInternalRepresentation();
return getLiteral().toStringRepresentation();
} else {
return getIri().toInternalRepresentation();
return getIri().toStringRepresentation();
}
}();
if (vocabulary.getId(content, &idx)) {
Expand Down Expand Up @@ -231,9 +231,9 @@ class TripleComponent {
return getString();
} else {
if (isLiteral()) {
return std::string{getLiteral().toInternalRepresentation()};
return std::string{getLiteral().toStringRepresentation()};
} else {
return std::string{getIri().toInternalRepresentation()};
return std::string{getIri().toStringRepresentation()};
}
}
}();
Expand Down
Loading

0 comments on commit 7f8d909

Please sign in to comment.