Browse Source

utility/string.h: Added method to check whether a string is considered similar.

tempestpy_adaptions
TimQu 6 years ago
parent
commit
e8cd922552
  1. 8
      src/storm/utility/string.cpp
  2. 6
      src/storm/utility/string.h

8
src/storm/utility/string.cpp

@ -9,9 +9,13 @@ namespace storm {
// intentionally left empty.
}
bool SimilarStrings::add(std::string const& string) {
bool SimilarStrings::isSimilar(std::string const& string) const {
double distance = levenshteinDistance(reference, string, caseSensitive);
if (distance <= static_cast<double>(std::max(reference.size(), string.size())) * (1.0 - similarityFactor)) {
return distance <= static_cast<double>(std::max(reference.size(), string.size())) * (1.0 - similarityFactor);
}
bool SimilarStrings::add(std::string const& string) {
if (isSimilar(string)) {
distances.emplace(storm::utility::string::levenshteinDistance(reference, string, caseSensitive), string);
return true;
}

6
src/storm/utility/string.h

@ -18,6 +18,11 @@ namespace storm {
*/
SimilarStrings(std::string reference, double similarityFactor = 0.6, bool caseSensitive = true);
/*!
* @return true, if the given string is considered similar.
*/
bool isSimilar(std::string const& string) const;
/*!
* Adds the given string to the set of similar strings (if it is similar)
* @return true, if the given string is considered similar.
@ -26,7 +31,6 @@ namespace storm {
/*!
* Gets a list of all added strings that are similar to the reference string.
* Erases all strings gathered so far.
*/
std::vector<std::string> toList() const;

Loading…
Cancel
Save