Browse Source

Added string utility functions to find similar strings.

tempestpy_adaptions
Tim Quatmann 6 years ago
parent
commit
01800f1590
  1. 11
      src/storm/utility/string.cpp
  2. 12
      src/storm/utility/string.h

11
src/storm/utility/string.cpp

@ -6,7 +6,7 @@ namespace storm {
namespace utility {
namespace string {
SimilarStrings::SimilarStrings(std::string reference, double similarityFactor, bool caseSensitive) : reference(reference), similarityFactor(similarityFactor), caseSensitive(caseSensitive), cmp([](std::pair<uint64_t, std::string> const& lhs, std::pair<uint64_t, std::string> const& rhs) { return lhs.first > rhs.first; }), distances(cmp) {
SimilarStrings::SimilarStrings(std::string reference, double similarityFactor, bool caseSensitive) : reference(reference), similarityFactor(similarityFactor), caseSensitive(caseSensitive) {
// intentionally left empty.
}
@ -20,11 +20,9 @@ namespace storm {
}
std::vector<std::string> SimilarStrings::toList() const {
auto distancesCopy = distances;
std::vector<std::string> result;
while (!distancesCopy.empty()) {
result.push_back(distancesCopy.top().second);
distancesCopy.pop();
for (auto const& dist : distances) {
result.push_back(dist.second);
}
return result;
}
@ -37,11 +35,10 @@ namespace storm {
} else if (size == 1) {
return "Did you mean " + result + "?";
} else {
return "Did you mean any of [" + result + "]?";
return "Did you mean any of [ " + result + " ]?";
}
}
uint64_t levenshteinDistance(std::string const& lhs, std::string const& rhs, bool caseSensitive) {
std::vector<std::vector<uint64_t>> d(lhs.size() + 1, std::vector<uint64_t>(rhs.size() + 1, 0ull));
for (uint64_t row = 1; row < d.size(); ++row) {

12
src/storm/utility/string.h

@ -1,8 +1,7 @@
#pragma once
#include <string>
#include <functional>
#include <queue>
#include <set>
namespace storm {
namespace utility {
@ -40,8 +39,13 @@ namespace storm {
std::string reference;
double similarityFactor;
bool caseSensitive;
std::function<bool (std::pair<uint64_t, std::string> const&, std::pair<uint64_t, std::string> const&)> cmp;
std::priority_queue<std::pair<uint64_t, std::string>, std::vector<std::pair<uint64_t, std::string>>, decltype(cmp)> distances;
struct comp {
bool operator() (std::pair<uint64_t, std::string> const& lhs, std::pair<uint64_t, std::string> const& rhs) const {
return lhs.first < rhs.first ? true : (lhs.first == rhs.first && lhs.second < rhs.second);
}
};
std::set<std::pair<uint64_t, std::string>, comp> distances;
};
/*!

Loading…
Cancel
Save