com.github.liblevenshtein.transducer.factory.CandidateFactory 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.factory;
import com.github.liblevenshtein.transducer.Candidate;
import java.io.Serializable;
/**
* Builds spelling candidates of the requested type, optionally including the
* distance of the candidate from the query term.
* @author Dylon Edwards
* @param Kind of spelling candidate built by this factory.
* @since 2.1.2
*/
public abstract class CandidateFactory implements Serializable {
private static final long serialVersionUID = 1L;
/**
* Builds a new spelling candidate from the dictionary term and its
* Levenshtein distance from the query term.
* @param term Candidate term from the dictionary.
* @param distance Levenshtein distance of the dictionary term from the query
* term.
* @return A new spelling candidate, optionally with the distance included.
*/
public abstract CandidateType build(String term, int distance);
/**
* Builds instances of {@link Candidate}, with the dictionary term and its
* Levenshtein distance from the query term.
* @author Dylon Edwards
* @since 2.1.2
*/
public static class WithDistance extends CandidateFactory {
private static final long serialVersionUID = 1L;
/**
* {@inheritDoc}
*/
@Override
public Candidate build(final String term, final int distance) {
return new Candidate(term, distance);
}
}
/**
* Does not include the Levenshtein distance, but returns the dictionary term
* alone.
* @author Dylon Edwards
* @since 2.1.2
*/
public static class WithoutDistance extends CandidateFactory {
private static final long serialVersionUID = 1L;
/**
* {@inheritDoc}
*/
@Override
public String build(final String term, final int distance) {
return term;
}
}
}