Download

Implementation of Levenshtein distance algorithm function in C++ with Unreal

Hi,

I am attempting to create a function in C++ that implements Levenshtein distance algorithim (determine the distance between two strings) where distance is the number of insertions, deletions and substitutions necessary to make the two strings equivalent. Unfortunately, my C++ skills in Unreal are not up to the task of implementing this. I am able to create basic functions in C++ and then implement them in blueprints–which is the goal of this project. However, I have been unable to do so with this task because of the complexity of the algorithim and my lack of knowing how to work with the unreal API.

Included below are a few different versions of the algorithim implemented in C++
https://rosettacode.org/wiki/Levenshtein_distance#C.2B.2B
https://gist.github.com/TheRayTracer/2644387
https://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance#C.2B.2B

Has anyone else implemented this, are there suggestions on how to modify these C++ templates so that they play nicely with the Unreal API.

Thanks,

Eric

Forgive my ignorance, but whats stopping you from just taking/using the code from one of your links? not seeing anything that wouldn’t work with UE4 as far as i can tell.

Hey Suicidal banana,

No the ignorance is on my part–that much is for sure. I have attempted that several times and I get a variety of errors when I try to compile. I also attempted to re-write the algorithim myself in C++ for unreal but I have difficulty even doing this from the very beginning. I suspect that this is because the example code uses libraries that don’t jive with C++. I might be wrong on that last point. At the very least I don’t know how to make them jive–that is my problem. Sorry for being a nube.

E

Unreal doesn’t use the standard library so you have to replace the standard library with unreal alternatives. UE4 Libraries You Should Know About - Unreal Engine

For example std::string could be changed to FString. FString | Unreal Engine Documentation

Then you would use the methods on FString such as Len for size and CreateIterator in the same way they use them on the std::string.

Yes, that is the difficulty approaching the unreal API from a novice perspective. But I actually figured out a workaround this afternoon and implemented the entire algorithm using blueprints. Works quite nice for my needs. If anyone is interested in the blueprint solution PM me.

Eric

What you can do is use FString::ToBlob to convert your FString to uint8] and then use regular C++ and refer to the post here

			
FString x("This is some long string");
uint8 buffer[10000];

for (int ii = 0; ii < 10000; ii++)
    buffer[ii] = 0;

FString::ToBlob(x, buffer, 10000);