Java 类org.apache.lucene.search.spell.StringDistance 实例源码

项目:elasticsearch_my    文件:DirectCandidateGeneratorBuilder.java   
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);
    }
}
项目:semtool    文件:EngineConsistencyChecker.java   
/**
 * 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 ) );
            }
        }
    }
}
项目:semtool    文件:CheckConsistencyPanel.java   
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 );
    }
}
项目:search    文件:ConjunctionSolrSpellChecker.java   
@Override
protected StringDistance getStringDistance() {
  if (stringDistance == null) {
    return super.getStringDistance();
  }
  return stringDistance;
}
项目:search    文件:IndexBasedSpellCheckerTest.java   
@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();
  }
}
项目:NYBC    文件:ConjunctionSolrSpellChecker.java   
@Override
protected StringDistance getStringDistance() {
  if (stringDistance == null) {
    return super.getStringDistance();
  }
  return stringDistance;
}
项目:NYBC    文件:IndexBasedSpellCheckerTest.java   
@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();
  }
}
项目:search-core    文件:ConjunctionSolrSpellChecker.java   
@Override
protected StringDistance getStringDistance() {
  if (stringDistance == null) {
    return super.getStringDistance();
  }
  return stringDistance;
}
项目:search-core    文件:IndexBasedSpellCheckerTest.java   
@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();
  }
}
项目:read-open-source-code    文件:ConjunctionSolrSpellChecker.java   
@Override
protected StringDistance getStringDistance() {
  if (stringDistance == null) {
    return super.getStringDistance();
  }
  return stringDistance;
}
项目:read-open-source-code    文件:ConjunctionSolrSpellChecker.java   
@Override
protected StringDistance getStringDistance() {
  if (stringDistance == null) {
    return super.getStringDistance();
  }
  return stringDistance;
}
项目:brigen-base    文件:LuceneDelegaterImpl.java   
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);
    }
}
项目:elasticsearch_my    文件:DirectSpellcheckerSettings.java   
public StringDistance stringDistance() {
    return stringDistance;
}
项目:elasticsearch_my    文件:DirectSpellcheckerSettings.java   
public void stringDistance(StringDistance distance) {
    this.stringDistance = distance;
}
项目:elasticsearch_my    文件:TermSuggestionBuilder.java   
@Override
public StringDistance toLucene() {
    return DirectSpellChecker.INTERNAL_LEVENSHTEIN;
}
项目:elasticsearch_my    文件:TermSuggestionBuilder.java   
@Override
public StringDistance toLucene() {
    return new LuceneLevenshteinDistance();
}
项目:elasticsearch_my    文件:TermSuggestionBuilder.java   
@Override
public StringDistance toLucene() {
    return new LevensteinDistance();
}
项目:elasticsearch_my    文件:TermSuggestionBuilder.java   
@Override
public StringDistance toLucene() {
    return new JaroWinklerDistance();
}
项目:elasticsearch_my    文件:TermSuggestionBuilder.java   
@Override
public StringDistance toLucene() {
    return new NGramDistance();
}
项目:Elasticsearch    文件:DirectSpellcheckerSettings.java   
public StringDistance stringDistance() {
    return stringDistance;
}
项目:Elasticsearch    文件:DirectSpellcheckerSettings.java   
public void stringDistance(StringDistance distance) {
    this.stringDistance = distance;
}
项目:semtool    文件:EngineConsistencyChecker.java   
public EngineConsistencyChecker( IEngine eng, boolean across, StringDistance dist ) {
    this.engine = eng;
    this.across = across;
    this.strdist = dist;
}
项目:semtool    文件:CheckConsistencyPanel.java   
public StringDistance getDistanceAlg() {
    return algorithm.getItemAt( algorithm.getSelectedIndex() );
}
项目:jspellchecker    文件:LuceneSpellCheckerServlet.java   
private MemoryAwareSpellChecker(Directory spellIndex,
                       StringDistance sd) throws IOException {
    super(spellIndex, sd);
    _spellIndex = spellIndex;
}
项目:search    文件:SolrSpellChecker.java   
/**
 * Get the distance implementation used by this spellchecker, or NULL if not applicable.
 */
protected StringDistance getStringDistance()  {
  throw new UnsupportedOperationException();
}
项目:search    文件:DirectSolrSpellChecker.java   
@Override
public StringDistance getStringDistance() {
  return checker.getDistance();
}
项目:search    文件:AbstractLuceneSpellChecker.java   
@Override
public StringDistance getStringDistance() {
  return sd;
}
项目:NYBC    文件:SolrSpellChecker.java   
/**
 * Get the distance implementation used by this spellchecker, or NULL if not applicable.
 */
protected StringDistance getStringDistance()  {
  throw new UnsupportedOperationException();
}
项目:NYBC    文件:DirectSolrSpellChecker.java   
@Override
public StringDistance getStringDistance() {
  return checker.getDistance();
}
项目:NYBC    文件:AbstractLuceneSpellChecker.java   
@Override
public StringDistance getStringDistance() {
  return sd;
}
项目:search-core    文件:SolrSpellChecker.java   
/**
 * Get the distance implementation used by this spellchecker, or NULL if not applicable.
 */
protected StringDistance getStringDistance()  {
  throw new UnsupportedOperationException();
}
项目:search-core    文件:DirectSolrSpellChecker.java   
@Override
public StringDistance getStringDistance() {
  return checker.getDistance();
}
项目:search-core    文件:AbstractLuceneSpellChecker.java   
@Override
public StringDistance getStringDistance() {
  return sd;
}
项目:read-open-source-code    文件:SolrSpellChecker.java   
/**
 * Get the distance implementation used by this spellchecker, or NULL if not applicable.
 */
protected StringDistance getStringDistance()  {
  throw new UnsupportedOperationException();
}
项目:read-open-source-code    文件:DirectSolrSpellChecker.java   
@Override
public StringDistance getStringDistance() {
  return checker.getDistance();
}
项目:read-open-source-code    文件:AbstractLuceneSpellChecker.java   
@Override
public StringDistance getStringDistance() {
  return sd;
}
项目:read-open-source-code    文件:SolrSpellChecker.java   
/**
 * Get the distance implementation used by this spellchecker, or NULL if not applicable.
 */
protected StringDistance getStringDistance()  {
  throw new UnsupportedOperationException();
}
项目:read-open-source-code    文件:DirectSolrSpellChecker.java   
@Override
public StringDistance getStringDistance() {
  return checker.getDistance();
}
项目:read-open-source-code    文件:AbstractLuceneSpellChecker.java   
@Override
public StringDistance getStringDistance() {
  return sd;
}
项目:search    文件:StringDistanceFunction.java   
public StringDistanceFunction(ValueSource str1, ValueSource str2, StringDistance measure) {
  this.str1 = str1;
  this.str2 = str2;
  dist = measure;


}