A simple, fast library to detect similarities between strings (and even arbitrary objects).
Just create a Delta
object using the builder interface and then pass in two strings to get the edit distance:
Delta delta = new DeltaBuilder().build();
int distance = delta.distance("saturday", "sunday");
assert(distance == 3);
You can pull it from maven once you add our repository:
<repositories>
<repository>
<id>omnia-delta-repo</id>
<url>https://raw.github.com/omnia-salud/delta/repository/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
Then just add the dependency:
<dependency>
<groupId>org.omnia</groupId>
<artifactId>delta</artifactId>
<version>1.0.0</version>
</dependency>
Delta uses a fast java implementation of the Levenshtein distance algorithm. It's versatile since you can configure the costs of insertions and editions at your will (for example, considering editions twice as expensive than insertions).
No, you can calculate differences between any object that implements Diffable
:
// given the following definition of a Person.
public class Person implements Diffable
{
private final String name;
private final String lastName;
private final String birthday;
public Person(String name, String lastName, String birthday)
{
this.name = name;
this.lastName = lastName;
this.birthday = birthday;
}
@Override
public String diffString()
{
return this.name + this.lastName + this.birthday;
}
}
// you can then do
Person self = new Person("Pablo", "Fernandez", "17/01/1985");
Person impostor = new Person("Pablo", "Fernandes", "27/01/1985");
int distance = delta.distance(self, impostor);
assert(distance == 2);