Skip to content

Commit 7f8d909

Browse files
committed
Also dddxfxixiasdflkjthed export.
1 parent 0e921fd commit 7f8d909

23 files changed

+121
-114
lines changed

src/engine/sparqlExpressions/LiteralExpression.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ class LiteralExpression : public SparqlExpression {
5050
}
5151
auto id = context->_qec.getIndex().getId(s);
5252
IdOrString result =
53-
id.has_value()
54-
? IdOrString{id.value()}
55-
: IdOrString{std::string{s.toInternalRepresentation()}};
53+
id.has_value() ? IdOrString{id.value()}
54+
: IdOrString{std::string{s.toStringRepresentation()}};
5655
auto ptrForCache = std::make_unique<IdOrString>(result);
5756
ptrForCache.reset(std::atomic_exchange_explicit(
5857
&cachedResult_, ptrForCache.release(), std::memory_order_relaxed));
@@ -104,9 +103,9 @@ class LiteralExpression : public SparqlExpression {
104103
} else if constexpr (std::is_same_v<T, ValueId>) {
105104
return absl::StrCat("#valueId ", _value.getBits(), "#");
106105
} else if constexpr (std::is_same_v<T, TripleComponent::Literal>) {
107-
return absl::StrCat("#literal: ", _value.toInternalRepresentation());
106+
return absl::StrCat("#literal: ", _value.toStringRepresentation());
108107
} else if constexpr (std::is_same_v<T, TripleComponent::Iri>) {
109-
return absl::StrCat("#iri: ", _value.toInternalRepresentation());
108+
return absl::StrCat("#iri: ", _value.toStringRepresentation());
110109
} else if constexpr (std::is_same_v<T, VectorWithMemoryLimit<ValueId>>) {
111110
// We should never cache this, as objects of this type of expression are
112111
// used exactly *once* in the HashMap optimization of the GROUP BY

src/index/IndexBuilderTypes.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ auto getIdMapLambdas(
240240
// This is not necessary for the actual QLever code, but certain unit tests
241241
// currently fail without it.
242242
itemArray[j]->getId(TripleComponent{
243-
ad_utility::triple_component::Iri::iriref(LANGUAGE_PREDICATE)});
243+
ad_utility::triple_component::Iri::fromIriref(LANGUAGE_PREDICATE)});
244244
}
245245
using OptionalIds = std::array<std::optional<std::array<Id, 3>>, 3>;
246246

@@ -278,8 +278,9 @@ auto getIdMapLambdas(
278278
// extra triple <object> ql:language-tag <@language>
279279
res[2].emplace(std::array<Id, 3>{
280280
spoIds[2],
281-
map.getId(TripleComponent{
282-
ad_utility::triple_component::Iri::iriref(LANGUAGE_PREDICATE)}),
281+
map.getId(
282+
TripleComponent{ad_utility::triple_component::Iri::fromIriref(
283+
LANGUAGE_PREDICATE)}),
283284
langTagId});
284285
}
285286
return res;

src/index/IndexImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ std::optional<string> IndexImpl::idToOptionalString(WordVocabIndex id) const {
12951295
std::optional<Id> IndexImpl::getIdImpl(const auto& element) const {
12961296
VocabIndex vocabIndex;
12971297
auto success =
1298-
getVocab().getId(element.toInternalRepresentation(), &vocabIndex);
1298+
getVocab().getId(element.toStringRepresentation(), &vocabIndex);
12991299
if (!success) {
13001300
return std::nullopt;
13011301
}

src/parser/Iri.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ NormalizedStringView Iri::getContent() const {
2525
}
2626

2727
// __________________________________________
28-
Iri Iri::iriref(std::string_view stringWithBrackets) {
28+
Iri Iri::fromIriref(std::string_view stringWithBrackets) {
2929
auto first = stringWithBrackets.find('<');
3030
AD_CORRECTNESS_CHECK(first != std::string_view::npos);
3131
return Iri{
@@ -35,19 +35,19 @@ Iri Iri::iriref(std::string_view stringWithBrackets) {
3535
}
3636

3737
// __________________________________________
38-
Iri Iri::prefixed(const Iri& prefix, std::string_view suffix) {
38+
Iri Iri::fromPrefixAndSuffix(const Iri& prefix, std::string_view suffix) {
3939
auto suffixNormalized = RdfEscaping::unescapePrefixedIri(suffix);
4040
return Iri{prefix, asNormalizedStringViewUnsafe(suffixNormalized)};
4141
}
4242

4343
// __________________________________________
44-
Iri Iri::fromInternalRepresentation(std::string_view s) {
44+
Iri Iri::fromStringRepresentation(std::string_view s) {
4545
AD_CORRECTNESS_CHECK(s.starts_with("<") || s.starts_with("@"));
4646
return Iri{NormalizedString{asNormalizedStringViewUnsafe(s)}};
4747
}
4848

4949
// __________________________________________
50-
std::string_view Iri::toInternalRepresentation() const {
50+
std::string_view Iri::toStringRepresentation() const {
5151
return asStringViewUnsafe(iri_);
5252
}
5353

src/parser/Iri.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ class Iri {
3636
asStringViewUnsafe(NormalizedStringView(iri.iri_)));
3737
}
3838
bool operator==(const Iri&) const = default;
39-
static Iri fromInternalRepresentation(std::string_view s);
39+
static Iri fromStringRepresentation(std::string_view s);
4040

41-
std::string_view toInternalRepresentation() const;
41+
std::string_view toStringRepresentation() const;
4242

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

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

4949
// Return the string value of the iri object without any leading or trailing
5050
// angled brackets.

src/parser/Literal.cpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99

1010
#include "parser/LiteralOrIri.h"
1111

12+
static constexpr NormalizedChar quote{'"'};
13+
static constexpr NormalizedChar at{'@'};
14+
static constexpr NormalizedChar hat{'^'};
15+
1216
namespace ad_utility::triple_component {
1317
// __________________________________________
1418
Literal::Literal(NormalizedString content, size_t beginOfSuffix)
1519
: content_{std::move(content)}, beginOfSuffix_{beginOfSuffix} {
16-
NormalizedChar quote{'"'};
17-
NormalizedChar at{'@'};
18-
NormalizedChar hat{'^'};
1920
AD_CORRECTNESS_CHECK(content_.starts_with(quote));
2021
AD_CORRECTNESS_CHECK(beginOfSuffix_ >= 2);
2122
AD_CORRECTNESS_CHECK(content_[beginOfSuffix_ - 1] == quote);
@@ -25,14 +26,10 @@ Literal::Literal(NormalizedString content, size_t beginOfSuffix)
2526
}
2627

2728
// __________________________________________
28-
bool Literal::hasLanguageTag() const {
29-
return getSuffix().starts_with(NormalizedChar{'@'});
30-
}
29+
bool Literal::hasLanguageTag() const { return getSuffix().starts_with(at); }
3130

3231
// __________________________________________
33-
bool Literal::hasDatatype() const {
34-
return getSuffix().starts_with(NormalizedChar{'^'});
35-
}
32+
bool Literal::hasDatatype() const { return getSuffix().starts_with(hat); }
3633

3734
// __________________________________________
3835
NormalizedStringView Literal::getContent() const {
@@ -60,9 +57,9 @@ NormalizedStringView Literal::getLanguageTag() const {
6057
}
6158

6259
// __________________________________________
63-
Literal Literal::literalWithQuotes(
60+
Literal Literal::fromEscapedRdfLiteral(
6461
std::string_view rdfContentWithQuotes,
65-
std::optional<std::variant<Iri, string>> descriptor) {
62+
std::optional<std::variant<Iri, std::string>> descriptor) {
6663
NormalizedString content =
6764
RdfEscaping::normalizeLiteralWithQuotes(rdfContentWithQuotes);
6865

@@ -107,30 +104,30 @@ Literal Literal::literalWithNormalizedContent(
107104

108105
// __________________________________________
109106
void Literal::addLanguageTag(std::string_view languageTag) {
110-
content_.push_back(NormalizedChar{'@'});
107+
content_.push_back(at);
111108
content_.append(RdfEscaping::normalizeLanguageTag(languageTag));
112109
}
113110

114111
// __________________________________________
115112
void Literal::addDatatype(const Iri& datatype) {
116113
content_.append(asNormalizedStringViewUnsafe("^^"));
117114
content_.append(
118-
asNormalizedStringViewUnsafe(datatype.toInternalRepresentation()));
115+
asNormalizedStringViewUnsafe(datatype.toStringRepresentation()));
119116
}
120117

121118
// __________________________________________
122-
std::string_view Literal::toInternalRepresentation() const {
119+
std::string_view Literal::toStringRepresentation() const {
123120
return asStringViewUnsafe(content_);
124121
}
125122

126123
// __________________________________________
127-
Literal Literal::fromInternalRepresentation(std::string_view input) {
124+
Literal Literal::fromStringRepresentation(std::string_view internal) {
128125
// TODO<joka921> This is a little dangerous as there might be quotes in the
129126
// IRI which might lead to unexpected results here.
130-
AD_CORRECTNESS_CHECK(input.starts_with('"'));
131-
auto endIdx = input.rfind('"');
127+
AD_CORRECTNESS_CHECK(internal.starts_with('"'));
128+
auto endIdx = internal.rfind('"');
132129
AD_CORRECTNESS_CHECK(endIdx > 0);
133-
return Literal{NormalizedString{asNormalizedStringViewUnsafe(input)},
130+
return Literal{NormalizedString{asNormalizedStringViewUnsafe(internal)},
134131
endIdx + 1};
135132
}
136133

src/parser/Literal.h

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,28 @@ namespace ad_utility::triple_component {
1111
// A class to hold literal values.
1212
class Literal {
1313
private:
14-
// Store the string value of the literal without the surrounding quotation
15-
// marks or trailing descriptor.
16-
// "Hello World"@en -> Hello World
14+
// Store the normalized version of the literal, including possible datatypes
15+
// and descriptors.
16+
// For example `"Hello World"@en` or `"With"Quote"^^<someDatatype>` (note
17+
// that the quote in the middle is unescaped because this is the normalized
18+
// form that QLever stores.
1719
NormalizedString content_;
20+
// The position after the closing `"`, so either the size of the string, or
21+
// the position of the `@` or `^^` for literals with language tags or
22+
// datatypes.
1823
std::size_t beginOfSuffix_;
1924

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

23-
// Similar to `literalWithQuotes`, except the rdfContent is expected to
28+
// Similar to `fromEscapedRdfLiteral`, except the rdfContent is expected to
2429
// already be normalized
2530
static Literal literalWithNormalizedContent(
2631
NormalizedString normalizedRdfContent,
2732
std::optional<std::variant<Iri, std::string>> descriptor = std::nullopt);
2833

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

42-
std::string_view toInternalRepresentation() const;
49+
std::string_view toStringRepresentation() const;
4350

44-
static Literal fromInternalRepresentation(std::string_view internal);
51+
static Literal fromStringRepresentation(std::string_view internal);
4552

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

6471
// For documentation, see documentation of function
65-
// LiteralORIri::literalWithQuotes
66-
static Literal literalWithQuotes(
72+
// LiteralORIri::fromEscapedRdfLiteral
73+
static Literal fromEscapedRdfLiteral(
6774
std::string_view rdfContentWithQuotes,
6875
std::optional<std::variant<Iri, std::string>> descriptor = std::nullopt);
6976

src/parser/LiteralOrIri.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,21 @@ NormalizedStringView LiteralOrIri::getContent() const {
8282

8383
// __________________________________________
8484
LiteralOrIri LiteralOrIri::iriref(const std::string& stringWithBrackets) {
85-
return LiteralOrIri{Iri::iriref(stringWithBrackets)};
85+
return LiteralOrIri{Iri::fromIriref(stringWithBrackets)};
8686
}
8787

8888
// __________________________________________
8989
LiteralOrIri LiteralOrIri::prefixedIri(const Iri& prefix,
9090
std::string_view suffix) {
91-
return LiteralOrIri{Iri::prefixed(prefix, suffix)};
91+
return LiteralOrIri{Iri::fromPrefixAndSuffix(prefix, suffix)};
9292
}
9393

9494
// __________________________________________
9595
LiteralOrIri LiteralOrIri::literalWithQuotes(
9696
std::string_view rdfContentWithQuotes,
9797
std::optional<std::variant<Iri, string>> descriptor) {
98-
return LiteralOrIri(
99-
Literal::literalWithQuotes(rdfContentWithQuotes, std::move(descriptor)));
98+
return LiteralOrIri(Literal::fromEscapedRdfLiteral(rdfContentWithQuotes,
99+
std::move(descriptor)));
100100
}
101101

102102
// __________________________________________

src/parser/LiteralOrIri.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ class LiteralOrIri {
3939

4040
std::string toInternalRepresentation() const {
4141
auto impl = [](const auto& val) {
42-
return absl::StrCat(val.toInternalRepresentation());
42+
return absl::StrCat(val.toStringRepresentation());
4343
};
4444
return std::visit(impl, data_);
4545
}
4646

4747
static LiteralOrIri fromInternalRepresentation(std::string_view internal) {
4848
char tag = internal.front();
4949
if (tag == iriPrefixChar) {
50-
return LiteralOrIri{Iri::fromInternalRepresentation(internal)};
50+
return LiteralOrIri{Iri::fromStringRepresentation(internal)};
5151
} else {
5252
AD_CORRECTNESS_CHECK(tag == literalPrefixChar);
53-
return LiteralOrIri{Literal::fromInternalRepresentation(internal)};
53+
return LiteralOrIri{Literal::fromStringRepresentation(internal)};
5454
}
5555
}
5656
template <typename H>
@@ -109,8 +109,8 @@ class LiteralOrIri {
109109
std::string_view rdfContentWithQuotes,
110110
std::optional<std::variant<Iri, std::string>> descriptor = std::nullopt);
111111

112-
// Similar to `literalWithQuotes`, except the rdfContent is expected to NOT BE
113-
// surrounded by quotation marks.
112+
// Similar to `fromEscapedRdfLiteral`, except the rdfContent is expected to
113+
// NOT BE surrounded by quotation marks.
114114
static LiteralOrIri literalWithoutQuotes(
115115
std::string_view rdfContentWithoutQuotes,
116116
std::optional<std::variant<Iri, std::string>> descriptor = std::nullopt);

src/parser/ParsedQuery.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class SparqlTriple : public SparqlTripleBase<PropertyPath> {
113113
TripleComponent p =
114114
isVariable(p_._iri)
115115
? TripleComponent{Variable{p_._iri}}
116-
: TripleComponent(TripleComponent::Iri::iriref(p_._iri));
116+
: TripleComponent(TripleComponent::Iri::fromIriref(p_._iri));
117117
return {s_, p, o_, additionalScanColumns_};
118118
}
119119
};

0 commit comments

Comments
 (0)