Skip to main content

module analysis::typepal::StringSimilarity

rascal-0.41.2
org.rascalmpl.typepal-0.15.5

Usage

import analysis::typepal::StringSimilarity;

Dependencies

import List;
import IO;
import Location;
import Set;
import String;
import analysis::typepal::ConfigurableScopeGraph;

function min

Tryadic minimum function on integers

int min(int a, int b, int c)

function lev

Calculate the Levenshtein distance of 2 strings

int lev(str a, str b)

alias WordSim

WordSim represents one word from the vocabulary and its similariy to the original word

tuple[str word, int sim]

function similarWords

Compute list of words from vocabulary, that are similar to give word w with at most maxDistance edits

list[str] similarWords(str w, set[str] vocabulary, int maxDistance)

function similarNames

Find in TModel tm, names similar to Use u. Max edit distance comes from TypePal Configuration.

list[str] similarNames(Use u, TModel tm)

Tests

test levCommutative

test bool levCommutative(str a, str b) = lev(a, b) == lev(b, a);

test levLeftAdditive

test bool levLeftAdditive(str a, str b, str c) = lev(a, b) == lev(c + a, c + b);

test lev1

test bool lev1() = lev("kitten", "sitting") == 3;

test lev2

test bool lev2() = lev("kelm", "hello") == 3;

test lev3

test bool lev3() = lev("hello", "hella") == 1;

test lev4

test bool lev4() = lev("hello", "") == 5;

test lev5

test bool lev5() = lev("", "hello") == 5;

test lev6

test bool lev6() = lev("aap", "noot") == 4;

test lev7

test bool lev7() = lev("page", "pope") == 2;

test lev8

test bool lev8() = lev("december", "january") == 8;

test lev9

test bool lev9() = lev("march", "may") == 3;