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
Better descriptor for transitive path #384
Conversation
The previous descriptor was very cryptic. The reason (probably) was that neither the subject, nor the predicate, not the object, are directly known by TransitivePath, but need to be obtained via a bit of acrobatics. See the code for details.
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.
This is very valuable,
There are 1.5 places where you can save some code which already lies inside the STL.
src/engine/TransitivePath.cpp
Outdated
auto optional = getIndex().idToOptionalString(_leftValue); | ||
if (optional) { | ||
os << optional.value(); | ||
} else { | ||
os << "#" << _leftValue; | ||
} |
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.
os << getIndex().idToOptionalString(_leftValue).value_or("#" + std::to_string(_leftValue))
https://en.cppreference.com/w/cpp/utility/optional/value_or
(If you want to, you can make two lines from this, I am sorry, I did not directly tell you this possibility:)
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.
Perfect, thanks!
if (scanOperation != nullptr) { | ||
os << " " << scanOperation->getPredicate() << " "; | ||
} else { | ||
os << " <???> "; |
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.
os << " " << scanOperation ? scanOperation->getPredicate() : "<???>" << " "
(only as a possibility, what you wrote is more explicit).
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 wrote something like that first, but found it harder to read since it spanned two lines and also the ? : has to be put into parantheses. So I would stick with the current version
src/engine/TransitivePath.cpp
Outdated
if (optional) { | ||
os << optional.value(); | ||
} else { | ||
os << "#" << _rightValue; | ||
} |
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.
again use value_or
(see above)
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.
Made the change for this one and the above and tested it and it works fine.
Implemented suggestion from Johannes to the original PR.
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.
Thank you very much, this is much more readable in the RuntimeInfo as well as in the code.
The previous descriptor was very cryptic. The reason (probably) was that
neither the subject, nor the predicate, not the object, are directly
known by TransitivePath, but need to be obtained via a bit of
acrobatics. See the code for details.