Skip to content

A parameterizable Damerau Levenshtein aligner in Java.

License

Notifications You must be signed in to change notification settings

manzurola/aligner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Aligner 🤖

maven

A Java library for aligning two generic lists using the Damerau Levenshtein algorithm.

Inspired by Errant by Chris Bryant and diff_match_patch by Neil Fraser.

Prerequisits

Before you begin, ensure you have met the following requirements:

  • You have Java 11 installed.

Installing Aligner

Add this to the dependencies section in your pom.xml:

<dependency>
  <groupId>io.github.manzurola</groupId>
  <artifactId>aligner</artifactId>
  <version>0.3.0</version>
</dependency>

Using Aligner

To use Aligner in code, follow these steps:

// Prepare source and target lists to be aligned
List<Integer> source = List.of(1, 3, 3);
List<Integer> target = List.of(1, 2, 3);

// Create a new aligner via one of the available static factory methods
Aligner<String> aligner = Aligner.damerauLevenshtein();

// Align source and target
Alignment<String> alignment = aligner.align(source,target);

// Get the cost and distance of the alignment
double cost = alignment.cost();
double distance = alignment.distance();
System.out.printf("Cost: %s, distance: %s%n", cost, distance);

// Inspect individual edits
for (Edit<Integer> edit : alignment.edits()) {
    Operation op = edit.operation();
    Segment<Integer> s = edit.source();
    Segment<Integer> t = edit.target();
    System.out.printf("Operation: %s, source: %s, target: %s%n", op, s, t);
}

You can also customise an Aligner with your own metrics:

// The equality operation is used to determine whether two elements are equal
Equalizer<Integer> equalizer = Integer::equals;

// The comparator is used to sort and compare two candidate lists for transposition
Comparator<Integer> comparator = Integer::compareTo;

// This cost function disables substitution for elements with values (3,2) by returning a Double.MAX_VALUE
// when matched
SubstituteCost<Integer> substituteCost = (s, t) -> s == 3 && t == 2 ? Double.MAX_VALUE : 1.0;

// A custom damerau levenshtein aligner
Aligner<Integer> aligner = Aligner.damerauLevenshtein(equalizer, comparator, substituteCost);

Contributions

To contribute to Aligner, follow these steps:

  1. Fork this repository.
  2. Create a branch: git checkout -b <branch_name>.
  3. Make your changes and commit them: git commit -m '<commit_message>'
  4. Push to the original branch: git push origin <project_name>/<location>
  5. Create the pull request.

Alternatively see the GitHub documentation on creating a pull request.

Contributors

Thanks to the following people who have contributed to this project:

Contact

If you want to contact me you can reach me at [email protected].

License

This project uses the following license: MIT.