Approximate string comparison and pattern matching in Java
aburkov edited this page Jun 30, 2015
·
6 revisions
Pages 19
- Home
- Approximate string comparison and pattern matching in Java
- Easy and intuitive MySQL interface for Java
- Easy CSV file input and output in Java
- English POS tagger for Java
- Golang like concurrency in Java
- How to deploy a Java web service using xpresso
- Join and split strings in Java like in Python
- JSON input output in Java
- MapReduce in Java for multi core
- Memoize methods of Java objects
- Open a file in Java in one short line of code
- Python like Generators in Java
- Python like list comprehensions in Java
- Python like slicable and iterable string type in Java
- Python like unidecode in Java
- Tokenize English text in Java
- Transliterate strings in Java
- Tuples in Java
- Show 4 more pages…
Clone this wiki locally
With xpresso you can perform an approximate string comparison and pattern matching in Java using the Python's FuzzyWuzzy algorithm.
Approximate string comparison:
x.print(x.String("Hello World").similarity("Hello Wold!"))
Console: 91
The output similarity value is the same as that of the fuzz.ratio function of FuzzyWuzzy.
By the way, xpresso has all string comparison methods of FuzzyWuzzy:
import com.wantedtech.common.xpresso.strings.FuzzyWuzzy;
x.assertTrue(FuzzyWuzzy.ratio("this is a test", "this is a test!") == 97);
x.assertTrue(FuzzyWuzzy.partial_ratio("this is a test", "this is a test!") == 100);
x.assertTrue(FuzzyWuzzy.ratio("fuzzy wuzzy was a bear", "wuzzy fuzzy was a bear") == 91);
x.assertTrue(FuzzyWuzzy.token_sort_ratio("fuzzy wuzzy was a bear", "wuzzy fuzzy was a bear", null) == 100);
x.assertTrue(FuzzyWuzzy.token_sort_ratio("fuzzy was a bear", "fuzzy fuzzy was a bear", null) == 84);
x.assertTrue(FuzzyWuzzy.token_set_ratio("fuzzy was a bear", "fuzzy fuzzy was a bear", null) == 100);
x.assertTrue(FuzzyWuzzy.extract("new york jets", choices, null, null, 2).equals(x.list(x.tuple2("New York Jets", 100), x.tuple2("New York Giants", 79))));
x.assertTrue(FuzzyWuzzy.extractOne("cowboys", choices, null, null, null).equals(x.tuple2("Dallas Cowboys", 90)));
Approximate pattern matching:
x.print(x.String("You are cooding in Java.").search("coding"));
Console: 8
Get similar strings:
list<String> lookAlikes = x.String("apple").lookAlikes(x.list("ape", "apples", "peach", "puppy"),50);
x.print(lookAlikes);
Console: [ape, apples]