diff --git a/src/engine/sparqlExpressions/LiteralExpression.h b/src/engine/sparqlExpressions/LiteralExpression.h index d866617089..729a240dc0 100644 --- a/src/engine/sparqlExpressions/LiteralExpression.h +++ b/src/engine/sparqlExpressions/LiteralExpression.h @@ -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(result); ptrForCache.reset(std::atomic_exchange_explicit( &cachedResult_, ptrForCache.release(), std::memory_order_relaxed)); @@ -104,9 +103,9 @@ class LiteralExpression : public SparqlExpression { } else if constexpr (std::is_same_v) { return absl::StrCat("#valueId ", _value.getBits(), "#"); } else if constexpr (std::is_same_v) { - return absl::StrCat("#literal: ", _value.toInternalRepresentation()); + return absl::StrCat("#literal: ", _value.toStringRepresentation()); } else if constexpr (std::is_same_v) { - return absl::StrCat("#iri: ", _value.toInternalRepresentation()); + return absl::StrCat("#iri: ", _value.toStringRepresentation()); } else if constexpr (std::is_same_v>) { // We should never cache this, as objects of this type of expression are // used exactly *once* in the HashMap optimization of the GROUP BY diff --git a/src/index/IndexBuilderTypes.h b/src/index/IndexBuilderTypes.h index 237433896f..bdbbde28bc 100644 --- a/src/index/IndexBuilderTypes.h +++ b/src/index/IndexBuilderTypes.h @@ -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>, 3>; @@ -278,8 +278,9 @@ auto getIdMapLambdas( // extra triple ql:language-tag <@language> res[2].emplace(std::array{ 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; diff --git a/src/index/IndexImpl.cpp b/src/index/IndexImpl.cpp index bd3fe73f1a..db8633f9bf 100644 --- a/src/index/IndexImpl.cpp +++ b/src/index/IndexImpl.cpp @@ -1295,7 +1295,7 @@ std::optional IndexImpl::idToOptionalString(WordVocabIndex id) const { std::optional 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; } diff --git a/src/parser/Iri.cpp b/src/parser/Iri.cpp index 4ab518cd04..ad09efd46d 100644 --- a/src/parser/Iri.cpp +++ b/src/parser/Iri.cpp @@ -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{ @@ -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_); } diff --git a/src/parser/Iri.h b/src/parser/Iri.h index 43f1130257..606a440623 100644 --- a/src/parser/Iri.h +++ b/src/parser/Iri.h @@ -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. diff --git a/src/parser/Literal.cpp b/src/parser/Literal.cpp index d3208d5133..482abe551c 100644 --- a/src/parser/Literal.cpp +++ b/src/parser/Literal.cpp @@ -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); @@ -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 { @@ -60,9 +57,9 @@ NormalizedStringView Literal::getLanguageTag() const { } // __________________________________________ -Literal Literal::literalWithQuotes( +Literal Literal::fromEscapedRdfLiteral( std::string_view rdfContentWithQuotes, - std::optional> descriptor) { + std::optional> descriptor) { NormalizedString content = RdfEscaping::normalizeLiteralWithQuotes(rdfContentWithQuotes); @@ -107,7 +104,7 @@ Literal Literal::literalWithNormalizedContent( // __________________________________________ void Literal::addLanguageTag(std::string_view languageTag) { - content_.push_back(NormalizedChar{'@'}); + content_.push_back(at); content_.append(RdfEscaping::normalizeLanguageTag(languageTag)); } @@ -115,22 +112,22 @@ void Literal::addLanguageTag(std::string_view 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 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}; } diff --git a/src/parser/Literal.h b/src/parser/Literal.h index 0d088df26c..659ab56f64 100644 --- a/src/parser/Literal.h +++ b/src/parser/Literal.h @@ -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"^^` (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> descriptor = std::nullopt); + // Internal helper function. Return either the empty string (for a plain + // literal), `@langtag` or `^^`. NormalizedStringView getSuffix() const { NormalizedStringView result = content_; result.remove_prefix(beginOfSuffix_); @@ -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; @@ -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> descriptor = std::nullopt); diff --git a/src/parser/LiteralOrIri.cpp b/src/parser/LiteralOrIri.cpp index 64d68fbde3..3fb41d3eb2 100644 --- a/src/parser/LiteralOrIri.cpp +++ b/src/parser/LiteralOrIri.cpp @@ -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> descriptor) { - return LiteralOrIri( - Literal::literalWithQuotes(rdfContentWithQuotes, std::move(descriptor))); + return LiteralOrIri(Literal::fromEscapedRdfLiteral(rdfContentWithQuotes, + std::move(descriptor))); } // __________________________________________ diff --git a/src/parser/LiteralOrIri.h b/src/parser/LiteralOrIri.h index 24d4a409c9..7d883b6c74 100644 --- a/src/parser/LiteralOrIri.h +++ b/src/parser/LiteralOrIri.h @@ -39,7 +39,7 @@ 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_); } @@ -47,10 +47,10 @@ class LiteralOrIri { 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 @@ -109,8 +109,8 @@ class LiteralOrIri { std::string_view rdfContentWithQuotes, std::optional> 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> descriptor = std::nullopt); diff --git a/src/parser/ParsedQuery.h b/src/parser/ParsedQuery.h index 4b4425b07f..d0ff26d53f 100644 --- a/src/parser/ParsedQuery.h +++ b/src/parser/ParsedQuery.h @@ -113,7 +113,7 @@ class SparqlTriple : public SparqlTripleBase { 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_}; } }; diff --git a/src/parser/TripleComponent.cpp b/src/parser/TripleComponent.cpp index 2caa38111b..8a9d2e127e 100644 --- a/src/parser/TripleComponent.cpp +++ b/src/parser/TripleComponent.cpp @@ -17,9 +17,9 @@ std::ostream& operator<<(std::ostream& stream, const TripleComponent& obj) { } else if constexpr (std::is_same_v) { stream << "UNDEF"; } else if constexpr (std::is_same_v) { - stream << value.toInternalRepresentation(); + stream << value.toStringRepresentation(); } else if constexpr (std::is_same_v) { - stream << value.toInternalRepresentation(); + stream << value.toStringRepresentation(); } else if constexpr (std::is_same_v) { stream << "DATE: " << value.toStringAndType().first; } else if constexpr (std::is_same_v) { @@ -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( diff --git a/src/parser/TripleComponent.h b/src/parser/TripleComponent.h index cfa4d47d11..239683752c 100644 --- a/src/parser/TripleComponent.h +++ b/src/parser/TripleComponent.h @@ -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)) { @@ -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()}; } } }(); diff --git a/src/parser/TurtleParser.cpp b/src/parser/TurtleParser.cpp index 41c4b9fe90..f202fcd87e 100644 --- a/src/parser/TurtleParser.cpp +++ b/src/parser/TurtleParser.cpp @@ -150,7 +150,7 @@ bool TurtleParser::predicateSpecialA() { if (auto [success, word] = tok_.template getNextToken(); success) { (void)word; - activePredicate_ = TripleComponent::Iri::iriref( + activePredicate_ = TripleComponent::Iri::fromIriref( ""); return true; } else { @@ -240,10 +240,10 @@ bool TurtleParser::collection() { triples_.resize(triples_.size() - objects.size()); // TODO Move such functionality into a general util. auto makeIri = [](std::string_view suffix) { - return TripleComponent::Iri::iriref( + return TripleComponent::Iri::fromIriref( absl::StrCat("<", RDF_PREFIX, suffix, ">")); }; - static const auto nil = makeIri("nil"); + static const auto nil = TripleComponent{makeIri("nil")}; static const auto first = makeIri("first"); static const auto rest = makeIri("rest"); @@ -251,7 +251,7 @@ bool TurtleParser::collection() { lastParseResult_ = nil; } else { // Create a new blank node for each collection element. - std::vector blankNodes; + std::vector blankNodes; blankNodes.reserve(objects.size()); for (size_t i = 0; i < objects.size(); ++i) { blankNodes.push_back(createAnonNode()); @@ -264,11 +264,8 @@ bool TurtleParser::collection() { // Add the triples for the linked list structure. for (size_t i = 0; i < blankNodes.size(); ++i) { triples_.push_back({blankNodes[i], first, objects[i]}); - if (i + 1 < blankNodes.size()) { - triples_.push_back({blankNodes[i], rest, blankNodes[i + 1]}); - } else { - triples_.push_back({blankNodes[i], rest, nil}); - } + triples_.push_back({blankNodes[i], rest, + i + 1 < blankNodes.size() ? blankNodes[i + 1] : nil}); } } check(skip()); @@ -513,7 +510,7 @@ bool TurtleParser::stringParse() { raise("Unterminated string literal"); } // also include the quotation marks in the word - lastParseResult_ = TripleComponent::Literal::literalWithQuotes( + lastParseResult_ = TripleComponent::Literal::fromEscapedRdfLiteral( view.substr(0, endPos + startPos)); tok_.remove_prefix(endPos + startPos); return true; @@ -540,7 +537,7 @@ bool TurtleParser::prefixedName() { } parseTerminal(); } - lastParseResult_ = TripleComponent::Iri::prefixed( + lastParseResult_ = TripleComponent::Iri::fromPrefixAndSuffix( expandPrefix(activePrefix_), lastParseResult_.getString()); return true; } @@ -641,7 +638,7 @@ bool TurtleParser::iriref() { } else { tok_.remove_prefix(endPos + 1); lastParseResult_ = - TripleComponent::Iri::iriref(view.substr(0, endPos + 1)); + TripleComponent::Iri::fromIriref(view.substr(0, endPos + 1)); return true; } } else { @@ -652,7 +649,7 @@ bool TurtleParser::iriref() { return false; } lastParseResult_ = - TripleComponent::Iri::iriref(lastParseResult_.getString()); + TripleComponent::Iri::fromIriref(lastParseResult_.getString()); return true; } } diff --git a/src/parser/TurtleParser.h b/src/parser/TurtleParser.h index 04e5e37563..75c1e9fa6f 100644 --- a/src/parser/TurtleParser.h +++ b/src/parser/TurtleParser.h @@ -180,8 +180,8 @@ class TurtleParser : public TurtleParserBase { void clear() { lastParseResult_ = ""; - activeSubject_ = TripleComponent::Iri::iriref("<>"); - activePredicate_ = TripleComponent::Iri::iriref("<>"); + activeSubject_ = TripleComponent::Iri::fromIriref("<>"); + activePredicate_ = TripleComponent::Iri::fromIriref("<>"); activePrefix_.clear(); prefixMap_.clear(); diff --git a/src/parser/sparqlParser/SparqlQleverVisitor.cpp b/src/parser/sparqlParser/SparqlQleverVisitor.cpp index 1ffe7b3567..af49ffc27f 100644 --- a/src/parser/sparqlParser/SparqlQleverVisitor.cpp +++ b/src/parser/sparqlParser/SparqlQleverVisitor.cpp @@ -122,7 +122,7 @@ ExpressionPtr Visitor::processIriFunctionCall( } } reportNotSupported(ctx, - "Function \""s + iri.toInternalRepresentation() + "\" is"); + "Function \""s + iri.toStringRepresentation() + "\" is"); } void Visitor::addVisibleVariable(Variable var) { @@ -618,7 +618,7 @@ RdfEscaping::NormalizedRDFString Visitor::visit(Parser::StringContext* ctx) { TripleComponent::Iri Visitor::visit(Parser::IriContext* ctx) { string langtag = ctx->PREFIX_LANGTAG() ? ctx->PREFIX_LANGTAG()->getText() : ""; - return TripleComponent::Iri::iriref( + return TripleComponent::Iri::fromIriref( langtag + visitAlternative(ctx->iriref(), ctx->prefixedName())); } @@ -1281,7 +1281,7 @@ PropertyPath Visitor::visit(Parser::PathPrimaryContext* ctx) { // `special a` case can be merged into a `visitAlternative(...)`. if (ctx->iri()) { return PropertyPath::fromIri( - std::string{visit(ctx->iri()).toInternalRepresentation()}); + std::string{visit(ctx->iri()).toStringRepresentation()}); } else if (ctx->path()) { return visit(ctx->path()); } else if (ctx->pathNegatedPropertySet()) { @@ -1433,7 +1433,7 @@ GraphTerm Visitor::visit(Parser::VarOrIriContext* ctx) { // the parser and from the `TripleComponent`, then this becomes much // simpler. return GraphTerm{ - Iri{std::string{visit(ctx->iri()).toInternalRepresentation()}}}; + Iri{std::string{visit(ctx->iri()).toStringRepresentation()}}}; } } @@ -1443,7 +1443,7 @@ GraphTerm Visitor::visit(Parser::GraphTermContext* ctx) { return visit(ctx->blankNode()); } else if (ctx->iri()) { // TODO Unify. - return Iri{std::string{visit(ctx->iri()).toInternalRepresentation()}}; + return Iri{std::string{visit(ctx->iri()).toStringRepresentation()}}; } else if (ctx->NIL()) { return Iri{""}; } else { @@ -1970,7 +1970,7 @@ std::string Visitor::visit(Parser::RdfLiteralContext* ctx) { ret += ctx->LANGTAG()->getText(); } else if (ctx->iri()) { // TODO Also unify the two Literal classes... - ret += ("^^" + std::string{visit(ctx->iri()).toInternalRepresentation()}); + ret += ("^^" + std::string{visit(ctx->iri()).toStringRepresentation()}); } return ret; } diff --git a/src/util/Conversions.cpp b/src/util/Conversions.cpp index b6eb862569..1d56040aac 100644 --- a/src/util/Conversions.cpp +++ b/src/util/Conversions.cpp @@ -23,7 +23,7 @@ namespace ad_utility { // _________________________________________________________ triple_component::Iri convertLangtagToEntityUri(const string& tag) { - return triple_component::Iri::iriref(makeInternalIri("@", tag)); + return triple_component::Iri::fromIriref(makeInternalIri("@", tag)); } // _________________________________________________________ @@ -35,7 +35,7 @@ std::string convertToLanguageTaggedPredicate(const string& pred, // _________________________________________________________ triple_component::Iri convertToLanguageTaggedPredicate( const triple_component::Iri& pred, const std::string& langtag) { - return triple_component::Iri::iriref(absl::StrCat( + return triple_component::Iri::fromIriref(absl::StrCat( "@", langtag, "@<", asStringViewUnsafe(pred.getContent()), ">")); } diff --git a/test/JoinTest.cpp b/test/JoinTest.cpp index 1145372ab0..3e1c564023 100644 --- a/test/JoinTest.cpp +++ b/test/JoinTest.cpp @@ -34,7 +34,9 @@ using ad_utility::testing::makeAllocator; namespace { using Vars = std::vector>; -auto iri = [](std::string_view s) { return TripleComponent::Iri::iriref(s); }; +auto iri = [](std::string_view s) { + return TripleComponent::Iri::fromIriref(s); +}; /* * A structure containing all information needed for a normal join test. A diff --git a/test/QueryPlannerTestHelpers.h b/test/QueryPlannerTestHelpers.h index f1105a255c..9ae9ce2fd1 100644 --- a/test/QueryPlannerTestHelpers.h +++ b/test/QueryPlannerTestHelpers.h @@ -172,7 +172,7 @@ inline auto IndexScanFromStrings = if (s.starts_with("?")) { return ::Variable{std::string{s}}; } else if (s.starts_with('<')) { - return TripleComponent::Iri::iriref(s); + return TripleComponent::Iri::fromIriref(s); } return s; }; diff --git a/test/SparqlAntlrParserTest.cpp b/test/SparqlAntlrParserTest.cpp index a772f76a4e..e4dd63d8a6 100644 --- a/test/SparqlAntlrParserTest.cpp +++ b/test/SparqlAntlrParserTest.cpp @@ -470,7 +470,7 @@ TEST(SparqlParser, VarOrTermGraphTerm) { } TEST(SparqlParser, Iri) { - auto iri = &TripleComponent::Iri::iriref; + auto iri = &TripleComponent::Iri::fromIriref; auto expectIri = ExpectCompleteParse<&Parser::iri>{}; expectIri("rdfs:label", iri(""), {{"rdfs", ""}}); diff --git a/test/SparqlExpressionTest.cpp b/test/SparqlExpressionTest.cpp index b239a5b901..c5c2bd5334 100644 --- a/test/SparqlExpressionTest.cpp +++ b/test/SparqlExpressionTest.cpp @@ -883,8 +883,8 @@ TEST(SparqlExpression, ReplaceExpression) { // ______________________________________________________________________________ TEST(SparqlExpression, literalExpression) { TestContext ctx; - StringLiteralExpression expr{ - TripleComponent::Literal::literalWithQuotes("\"notInTheVocabulary\"")}; + StringLiteralExpression expr{TripleComponent::Literal::fromEscapedRdfLiteral( + "\"notInTheVocabulary\"")}; // Evaluate multiple times to test the caching behavior. for (size_t i = 0; i < 15; ++i) { ASSERT_EQ((ExpressionResult{IdOrString{"\"notInTheVocabulary\""}}), @@ -892,7 +892,7 @@ TEST(SparqlExpression, literalExpression) { } // A similar test with a constant entry that is part of the vocabulary and can // therefore be converted to an ID. - IriExpression iriExpr{TripleComponent::Iri::iriref("")}; + IriExpression iriExpr{TripleComponent::Iri::fromIriref("")}; Id idOfX = ctx.x; for (size_t i = 0; i < 15; ++i) { ASSERT_EQ((ExpressionResult{IdOrString{idOfX}}), diff --git a/test/TurtleParserTest.cpp b/test/TurtleParserTest.cpp index 385593ec3d..388ce304d1 100644 --- a/test/TurtleParserTest.cpp +++ b/test/TurtleParserTest.cpp @@ -19,7 +19,9 @@ using CtreParser = TurtleStringParser; namespace { auto lit = ad_utility::testing::tripleComponentLiteral; -auto iri = [](std::string_view s) { return TripleComponent::Iri::iriref(s); }; +auto iri = [](std::string_view s) { + return TripleComponent::Iri::fromIriref(s); +}; } // namespace // TODO: Use the following abstractions and the alias `Parser` in all @@ -67,7 +69,7 @@ auto checkParseResult = // Formatted output of TurtleTriples in case of test failures. std::ostream& operator<<(std::ostream& os, const TurtleTriple& tr) { - os << "( " << tr.subject_ << " " << tr.predicate_.toInternalRepresentation() + os << "( " << tr.subject_ << " " << tr.predicate_.toStringRepresentation() << " " << tr.object_ << ")"; return os; } diff --git a/test/parser/LiteralOrIriTest.cpp b/test/parser/LiteralOrIriTest.cpp index 6631bd4893..5afcc5e8d5 100644 --- a/test/parser/LiteralOrIriTest.cpp +++ b/test/parser/LiteralOrIriTest.cpp @@ -14,7 +14,7 @@ using namespace ad_utility::triple_component; TEST(IriTest, IriCreation) { - Iri iri = Iri::iriref(""); + Iri iri = Iri::fromIriref(""); EXPECT_THAT("http://www.wikidata.org/entity/Q3138", asStringViewUnsafe(iri.getContent())); @@ -32,7 +32,8 @@ TEST(LiteralTest, LiteralTest) { TEST(LiteralTest, LiteralTestWithDatatype) { Literal literal = Literal::literalWithoutQuotes( - "Hello World", Iri::iriref("")); + "Hello World", + Iri::fromIriref("")); EXPECT_FALSE(literal.hasLanguageTag()); EXPECT_TRUE(literal.hasDatatype()); @@ -69,7 +70,7 @@ TEST(LiteralOrIri, LiteralOrIriWithIri) { TEST(LiteralOrIri, LiteralOrIriWithPrefixedIri) { LiteralOrIri iri = LiteralOrIri::prefixedIri( - Iri::iriref(""), "Q3138"); + Iri::fromIriref(""), "Q3138"); EXPECT_TRUE(iri.isIri()); EXPECT_THAT("http://www.wikidata.org/entity/Q3138", @@ -110,7 +111,8 @@ TEST(LiteralOrIri, LiteralOrIriWithLiteralWithQuotes) { TEST(LiteralOrIri, LiteralOrIriWithLiteralAndDatatype) { LiteralOrIri literal = LiteralOrIri::literalWithoutQuotes( - "Hello World", Iri::iriref("")); + "Hello World", + Iri::fromIriref("")); EXPECT_FALSE(literal.isIri()); EXPECT_THROW(literal.getIriContent(), ad_utility::Exception); @@ -126,7 +128,7 @@ TEST(LiteralOrIri, LiteralOrIriWithLiteralAndDatatype) { TEST(LiteralOrIri, LiteralOrIriWithLiteralWithQuotesAndDatatype) { LiteralOrIri literal = LiteralOrIri::literalWithQuotes( "\"Hello World\"", - Iri::iriref("")); + Iri::fromIriref("")); EXPECT_FALSE(literal.isIri()); EXPECT_THROW(literal.getIriContent(), ad_utility::Exception); @@ -172,7 +174,7 @@ TEST(LiteralOrIri, GetContent) { LiteralOrIri literalWithLanguageTag = LiteralOrIri::literalWithoutQuotes("Hello World", "@de"); LiteralOrIri literalWithDatatype = LiteralOrIri::literalWithoutQuotes( - "ABC", Iri::iriref("")); + "ABC", Iri::fromIriref("")); EXPECT_THAT("https://example.org/books/book1", asStringViewUnsafe(iri.getContent())); diff --git a/test/util/TripleComponentTestHelpers.h b/test/util/TripleComponentTestHelpers.h index acdbad75b2..5c108fe8bc 100644 --- a/test/util/TripleComponentTestHelpers.h +++ b/test/util/TripleComponentTestHelpers.h @@ -12,24 +12,24 @@ namespace ad_utility::testing { // `TripleComponent`. The contents of the literal are obtained by normalizing // `literal` (which must be enclosed in double quotes) and the optional // `langtagOrDatatype` (which must start with `@` or `^^`). -constexpr auto tripleComponentLiteral = [](const std::string& literal, - std::string_view langtagOrDatatype = - "") { - if (langtagOrDatatype.starts_with("@")) { - return TripleComponent::Literal::literalWithQuotes( - literal, std::string(langtagOrDatatype)); - } else if (langtagOrDatatype.starts_with("^^")) { - auto iri = - ad_utility::triple_component::Iri::iriref(langtagOrDatatype.substr(2)); - return TripleComponent::Literal::literalWithQuotes(literal, std::move(iri)); - } else { - AD_CONTRACT_CHECK(langtagOrDatatype.empty()); - return TripleComponent::Literal::literalWithQuotes(literal); - } -}; +constexpr auto tripleComponentLiteral = + [](const std::string& literal, std::string_view langtagOrDatatype = "") { + if (langtagOrDatatype.starts_with("@")) { + return TripleComponent::Literal::fromEscapedRdfLiteral( + literal, std::string(langtagOrDatatype)); + } else if (langtagOrDatatype.starts_with("^^")) { + auto iri = ad_utility::triple_component::Iri::fromIriref( + langtagOrDatatype.substr(2)); + return TripleComponent::Literal::fromEscapedRdfLiteral(literal, + std::move(iri)); + } else { + AD_CONTRACT_CHECK(langtagOrDatatype.empty()); + return TripleComponent::Literal::fromEscapedRdfLiteral(literal); + } + }; // Create a `TripleComponent` that stores an `Iri` from the given `` constexpr auto iri = [](std::string_view s) { - return TripleComponent::Iri::iriref(s); + return TripleComponent::Iri::fromIriref(s); }; } // namespace ad_utility::testing