Skip to content

omnia-salud/delta

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Delta

A simple, fast library to detect similarities between strings (and even arbitrary objects).

Build Status License

How to use it?

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);

How to get it

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>

How does it work?

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).

Does it only compute differences between strings?

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);

Need help?

send me an email or ask me via twitter

About

simple edit distance between objects

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages