本文整理汇总了Java中org.apache.lucene.search.spell.StringDistance类的典型用法代码示例。如果您正苦于以下问题:Java StringDistance类的具体用法?Java StringDistance怎么用?Java StringDistance使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StringDistance类属于org.apache.lucene.search.spell包,在下文中一共展示了StringDistance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveDistance
import org.apache.lucene.search.spell.StringDistance; //导入依赖的package包/类
private static StringDistance resolveDistance(String distanceVal) {
distanceVal = distanceVal.toLowerCase(Locale.US);
if ("internal".equals(distanceVal)) {
return DirectSpellChecker.INTERNAL_LEVENSHTEIN;
} else if ("damerau_levenshtein".equals(distanceVal) || "damerauLevenshtein".equals(distanceVal)) {
return new LuceneLevenshteinDistance();
} else if ("levenstein".equals(distanceVal)) {
return new LevensteinDistance();
// TODO Jaro and Winkler are 2 people - so apply same naming logic
// as damerau_levenshtein
} else if ("jarowinkler".equals(distanceVal)) {
return new JaroWinklerDistance();
} else if ("ngram".equals(distanceVal)) {
return new NGramDistance();
} else {
throw new IllegalArgumentException("Illegal distance option " + distanceVal);
}
}
示例2: fallbackResolve
import org.apache.lucene.search.spell.StringDistance; //导入依赖的package包/类
/**
* Resolves terms that could not be resolved with the lucene approach. This
* brute-force function is significantly slower, but always works
*
* @param needles the URIs that produced errors in lucene
* @param possibles the set of all possible solutions
* @param hits populate this multimap with matches
* @param levy the string distance object to use to measure hits
* @param minDistance the minimum similarity measure
*/
private void fallbackResolve( Collection<URI> needles, Map<URI, String> possibles,
MultiMap<URI, Hit> hits, StringDistance levy, float minDistance ) {
log.debug( "falling back to resolve " + needles.size() + " items" );
for ( URI needle : needles ) {
String needlelabel = labels.get( needle );
for ( Map.Entry<URI, String> en : possibles.entrySet() ) {
URI match = en.getKey();
String matchlabel = en.getValue();
float distance = levy.getDistance( needlelabel, matchlabel );
if ( distance >= minDistance && !match.equals( needle ) ) {
hits.add( needle,
new Hit( match, matchlabel, uriToTypeLkp.get( match ), distance ) );
}
}
}
}
示例3: CheckConsistencyPanel
import org.apache.lucene.search.spell.StringDistance; //导入依赖的package包/类
public CheckConsistencyPanel() {
initComponents();
conceptList.setCellRenderer( crenderer );
relationList.setCellRenderer( rrenderer );
LabeledPairRenderer<StringDistance> arend = new LabeledPairRenderer<>();
algorithm.setRenderer( arend );
Map<StringDistance, String> dists = new LinkedHashMap<>();
dists.put( new LevensteinDistance(), "Levenstein" );
dists.put( new DoubleMetaphoneDistance(), "Double Metaphone" );
dists.put( new MetaphoneDistance(), "Metaphone" );
dists.put( new SoundexDistance(), "Soundex" );
arend.cache( dists );
for( StringDistance s : dists.keySet() ){
algorithm.addItem( s );
}
}
示例4: getStringDistance
import org.apache.lucene.search.spell.StringDistance; //导入依赖的package包/类
@Override
protected StringDistance getStringDistance() {
if (stringDistance == null) {
return super.getStringDistance();
}
return stringDistance;
}
示例5: testAlternateDistance
import org.apache.lucene.search.spell.StringDistance; //导入依赖的package包/类
@Test
public void testAlternateDistance() throws Exception {
TestSpellChecker checker = new TestSpellChecker();
NamedList spellchecker = new NamedList();
spellchecker.add("classname", IndexBasedSpellChecker.class.getName());
File indexDir = createTempDir();
spellchecker.add(AbstractLuceneSpellChecker.INDEX_DIR, indexDir.getAbsolutePath());
spellchecker.add(AbstractLuceneSpellChecker.FIELD, "title");
spellchecker.add(AbstractLuceneSpellChecker.SPELLCHECKER_ARG_NAME, spellchecker);
spellchecker.add(AbstractLuceneSpellChecker.STRING_DISTANCE, JaroWinklerDistance.class.getName());
SolrCore core = h.getCore();
String dictName = checker.init(spellchecker, core);
assertTrue(dictName + " is not equal to " + SolrSpellChecker.DEFAULT_DICTIONARY_NAME,
dictName.equals(SolrSpellChecker.DEFAULT_DICTIONARY_NAME) == true);
RefCounted<SolrIndexSearcher> holder = core.getSearcher();
SolrIndexSearcher searcher = holder.get();
try {
checker.build(core, searcher);
SpellChecker sc = checker.getSpellChecker();
assertTrue("sc is null and it shouldn't be", sc != null);
StringDistance sd = sc.getStringDistance();
assertTrue("sd is null and it shouldn't be", sd != null);
assertTrue("sd is not an instance of " + JaroWinklerDistance.class.getName(), sd instanceof JaroWinklerDistance);
} finally {
holder.decref();
}
}
示例6: testAlternateDistance
import org.apache.lucene.search.spell.StringDistance; //导入依赖的package包/类
@Test
public void testAlternateDistance() throws Exception {
TestSpellChecker checker = new TestSpellChecker();
NamedList spellchecker = new NamedList();
spellchecker.add("classname", IndexBasedSpellChecker.class.getName());
File indexDir = new File(TEMP_DIR, "spellingIdx" + new Date().getTime());
indexDir.mkdirs();
spellchecker.add(AbstractLuceneSpellChecker.INDEX_DIR, indexDir.getAbsolutePath());
spellchecker.add(AbstractLuceneSpellChecker.FIELD, "title");
spellchecker.add(AbstractLuceneSpellChecker.SPELLCHECKER_ARG_NAME, spellchecker);
spellchecker.add(AbstractLuceneSpellChecker.STRING_DISTANCE, JaroWinklerDistance.class.getName());
SolrCore core = h.getCore();
String dictName = checker.init(spellchecker, core);
assertTrue(dictName + " is not equal to " + SolrSpellChecker.DEFAULT_DICTIONARY_NAME,
dictName.equals(SolrSpellChecker.DEFAULT_DICTIONARY_NAME) == true);
RefCounted<SolrIndexSearcher> holder = core.getSearcher();
SolrIndexSearcher searcher = holder.get();
try {
checker.build(core, searcher);
SpellChecker sc = checker.getSpellChecker();
assertTrue("sc is null and it shouldn't be", sc != null);
StringDistance sd = sc.getStringDistance();
assertTrue("sd is null and it shouldn't be", sd != null);
assertTrue("sd is not an instance of " + JaroWinklerDistance.class.getName(), sd instanceof JaroWinklerDistance);
} finally {
holder.decref();
}
}
示例7: check
import org.apache.lucene.search.spell.StringDistance; //导入依赖的package包/类
private static void check() {
try {
Class.forName(JaroWinklerDistance.class.getName());
Class.forName(LevensteinDistance.class.getName());
Class.forName(StringDistance.class.getName());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
示例8: stringDistance
import org.apache.lucene.search.spell.StringDistance; //导入依赖的package包/类
public StringDistance stringDistance() {
return stringDistance;
}
示例9: toLucene
import org.apache.lucene.search.spell.StringDistance; //导入依赖的package包/类
@Override
public StringDistance toLucene() {
return DirectSpellChecker.INTERNAL_LEVENSHTEIN;
}
示例10: EngineConsistencyChecker
import org.apache.lucene.search.spell.StringDistance; //导入依赖的package包/类
public EngineConsistencyChecker( IEngine eng, boolean across, StringDistance dist ) {
this.engine = eng;
this.across = across;
this.strdist = dist;
}
示例11: getDistanceAlg
import org.apache.lucene.search.spell.StringDistance; //导入依赖的package包/类
public StringDistance getDistanceAlg() {
return algorithm.getItemAt( algorithm.getSelectedIndex() );
}
示例12: MemoryAwareSpellChecker
import org.apache.lucene.search.spell.StringDistance; //导入依赖的package包/类
private MemoryAwareSpellChecker(Directory spellIndex,
StringDistance sd) throws IOException {
super(spellIndex, sd);
_spellIndex = spellIndex;
}
示例13: getStringDistance
import org.apache.lucene.search.spell.StringDistance; //导入依赖的package包/类
/**
* Get the distance implementation used by this spellchecker, or NULL if not applicable.
*/
protected StringDistance getStringDistance() {
throw new UnsupportedOperationException();
}
示例14: getStringDistance
import org.apache.lucene.search.spell.StringDistance; //导入依赖的package包/类
@Override
public StringDistance getStringDistance() {
return checker.getDistance();
}
示例15: getStringDistance
import org.apache.lucene.search.spell.StringDistance; //导入依赖的package包/类
@Override
public StringDistance getStringDistance() {
return sd;
}