Browse Source

Added string utility functions to find similar strings.

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

9
src/storm/utility/string.cpp

@ -6,7 +6,7 @@ namespace storm {
namespace utility { namespace utility {
namespace string { 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. // intentionally left empty.
} }
@ -20,11 +20,9 @@ namespace storm {
} }
std::vector<std::string> SimilarStrings::toList() const { std::vector<std::string> SimilarStrings::toList() const {
auto distancesCopy = distances;
std::vector<std::string> result; 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; return result;
} }
@ -41,7 +39,6 @@ namespace storm {
} }
} }
uint64_t levenshteinDistance(std::string const& lhs, std::string const& rhs, bool caseSensitive) { 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)); 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) { for (uint64_t row = 1; row < d.size(); ++row) {

12
src/storm/utility/string.h

@ -1,8 +1,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include <functional>
#include <queue>
#include <set>
namespace storm { namespace storm {
namespace utility { namespace utility {
@ -40,8 +39,13 @@ namespace storm {
std::string reference; std::string reference;
double similarityFactor; double similarityFactor;
bool caseSensitive; 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