querqy.lucene.contrib.rewrite.wordbreak.MorphologyProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of querqy-lucene Show documentation
Show all versions of querqy-lucene Show documentation
Querqy library for query rewriting for Lucene
The newest version!
package querqy.lucene.contrib.rewrite.wordbreak;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import static java.util.Collections.singletonList;
public class MorphologyProvider {
private static final Map> morphologies = new HashMap<>();
private static final String DEFAULT_KEY = "default";
public static final SuffixGroupMorphology DEFAULT = new SuffixGroupMorphology(weight -> new SuffixGroup(null, singletonList(new WordGeneratorAndWeight(NoopWordGenerator.INSTANCE, 1f))));
static {
morphologies.put(DEFAULT_KEY, Optional.of(DEFAULT));
morphologies.put("german", Optional.of(new SuffixGroupMorphology(GermanDecompoundingMorphology::createDecompoundingMorphemes, GermanDecompoundingMorphology::createCompoundingMorphemes)));
}
public Optional get(final String name) {
final String normName = name == null ? "" : name.toLowerCase();
if (!exists(normName)) {
throw new IllegalArgumentException(String.format("No such morphology %s", normName));
}
return morphologies.get(normName);
}
public boolean exists(final String name) {
final String normName = name == null ? "" : name.toLowerCase();
return morphologies.containsKey(normName);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy