-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correct Datatypes for StringExpressions #1615
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some initial comments on the parts of the code written so far.
switch (id.getDatatype()) { | ||
case Undefined: | ||
return std::nullopt; | ||
case Double: | ||
// We use the immediately invoked lambda here because putting this block | ||
// in braces confuses the test coverage tool. | ||
return [id]() -> std::optional<LiteralOrIri> { | ||
// Format as integer if fractional part is zero, let C++ decide | ||
// otherwise. | ||
std::stringstream ss; | ||
double d = id.getDouble(); | ||
double dIntPart; | ||
if (std::modf(d, &dIntPart) == 0.0) { | ||
ss << std::fixed << std::setprecision(0) << id.getDouble(); | ||
} else { | ||
ss << d; | ||
} | ||
return LiteralOrIri::literalWithoutQuotes( | ||
std::move(ss).str(), | ||
TripleComponent::Iri::fromIrirefWithoutBrackets(XSD_DOUBLE_TYPE)); | ||
}(); | ||
case Bool: | ||
return id.getBool() ? LiteralOrIri::literalWithoutQuotes( | ||
"true", fromIri(XSD_BOOLEAN_TYPE)) | ||
: LiteralOrIri::literalWithoutQuotes( | ||
"false", fromIri(XSD_BOOLEAN_TYPE)); | ||
case Int: | ||
return LiteralOrIri::literalWithoutQuotes(std::to_string(id.getInt()), | ||
fromIri(XSD_INT_TYPE)); | ||
case Date: | ||
return LiteralOrIri::literalWithoutQuotes( | ||
id.getDate().toStringAndType().first, fromIri(XSD_DATE_TYPE)); | ||
case GeoPoint: | ||
return LiteralOrIri::literalWithoutQuotes( | ||
id.getGeoPoint().toStringAndType().first, fromIri(GEO_WKT_LITERAL)); | ||
case BlankNodeIndex: | ||
return LiteralOrIri::literalWithoutQuotes( | ||
absl::StrCat("_:bn", id.getBlankNodeIndex().get())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to share as much code as possible with the `idToStringAndTypeForEncodedValue (maybe just call this function, and then just construct the result by wrapping everything in the correct types).
}; | ||
switch (id.getDatatype()) { | ||
case WordVocabIndex: | ||
// TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can do exactly the same thing as the other function, and also use literalWithoutQuotest
.
@@ -287,6 +336,31 @@ ExportQueryExecutionTrees::idToStringAndType(const Index& index, Id id, | |||
return idToStringAndTypeForEncodedValue(id); | |||
} | |||
} | |||
|
|||
// _____________________________________________________________________________ | |||
std::optional<LiteralOrIri> ExportQueryExecutionTrees::idToLiteralOrIri( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe (for the performance) add the argument onlyReturnLiterals
that immediately returns nullopt
for everything that is not a literal).
auto optionalLiteralOrIriAndType = | ||
ExportQueryExecutionTrees::idToLiteralOrIri(context->_qec.getIndex(), id, | ||
context->_localVocab); | ||
if (optionalLiteralOrIriAndType.has_value()) { | ||
return std::move(optionalLiteralOrIriAndType.value()); | ||
} else { | ||
return std::nullopt; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto optionalLiteralOrIriAndType = | |
ExportQueryExecutionTrees::idToLiteralOrIri(context->_qec.getIndex(), id, | |
context->_localVocab); | |
if (optionalLiteralOrIriAndType.has_value()) { | |
return std::move(optionalLiteralOrIriAndType.value()); | |
} else { | |
return std::nullopt; | |
} | |
} | |
return optionalLiteralOrIriAndType = | |
ExportQueryExecutionTrees::idToLiteralOrIri(context->_qec.getIndex(), id, | |
context->_localVocab); | |
} |
// Same as the previous function, but only handles the datatypes for which the | ||
// value is encoded directly in the ID. For other datatypes an exception is | ||
// thrown. | ||
static std::optional<LiteralOrIri> idToLiteralOrIriForEncodedValue(Id id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider an overload/parameter with the following semantics:
Mode a) Only return Literals (no IRIs) with no datatype or datatype XSD:string, for all other cases (IRIs + literals with datatypes) return nullopt.
Mode b) remove all datatypes from literals if they are not xsd:string
, so for example 42
becomes "42" not "42^^xsd::integer
.
Conformance check passed ✅No test result changes. |
Quality Gate passedIssues Measures |
No description provided.