com.github.liblevenshtein.transducer.Transducer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of liblevenshtein-lite Show documentation
Show all versions of liblevenshtein-lite Show documentation
A library for spelling-correction based on Levenshtein Automata.
package com.github.liblevenshtein.transducer;
import java.io.Serializable;
import java.util.Objects;
/**
* This wrapper around {@link LazyTransducerCollection}, which handles all the
* heavy lifting.
*
* @author Dylon Edwards
* @param Kind of nodes of the dictionary automaton.
* @param Kind of the spelling candidates returned from the
* dictionary.
* @since 2.1.0
*/
public class Transducer
implements ITransducer, Serializable {
private static final long serialVersionUID = 1L;
/**
* Attributes required for this transducer to search the dictionary.
*/
private TransducerAttributes attributes;
public Transducer(TransducerAttributes attributes) {
this.attributes = attributes;
}
public TransducerAttributes attributes() {
return attributes;
}
/**
* {@inheritDoc}
*/
@Override
public Iterable transduce(final String term) {
return transduce(term, attributes.maxDistance());
}
/**
* {@inheritDoc}
*/
@Override
public Iterable transduce(
final String term,
final int maxDistance) {
return new LazyTransducerCollection(
term, maxDistance, attributes);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Transducer, ?> that = (Transducer, ?>) o;
return Objects.equals(attributes, that.attributes);
}
@Override
public int hashCode() {
return Objects.hash(attributes);
}
}