• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java LevensteinDistance类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.lucene.search.spell.LevensteinDistance的典型用法代码示例。如果您正苦于以下问题:Java LevensteinDistance类的具体用法?Java LevensteinDistance怎么用?Java LevensteinDistance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



LevensteinDistance类属于org.apache.lucene.search.spell包,在下文中一共展示了LevensteinDistance类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: resolveDistance

import org.apache.lucene.search.spell.LevensteinDistance; //导入依赖的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);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:DirectCandidateGeneratorBuilder.java


示例2: validate

import org.apache.lucene.search.spell.LevensteinDistance; //导入依赖的package包/类
/**
 * Validates that the setting is valid
 */
public final void validate(String key, Settings settings) {
    Setting setting = get(key);
    if (setting == null) {
        LevensteinDistance ld = new LevensteinDistance();
        List<Tuple<Float, String>> scoredKeys = new ArrayList<>();
        for (String k : this.keySettings.keySet()) {
            float distance = ld.getDistance(key, k);
            if (distance > 0.7f) {
                scoredKeys.add(new Tuple<>(distance, k));
            }
        }
        CollectionUtil.timSort(scoredKeys, (a,b) -> b.v1().compareTo(a.v1()));
        String msgPrefix = "unknown setting";
        SecureSettings secureSettings = settings.getSecureSettings();
        if (secureSettings != null && settings.getSecureSettings().getSettingNames().contains(key)) {
            msgPrefix = "unknown secure setting";
        }
        String msg = msgPrefix + " [" + key + "]";
        List<String> keys = scoredKeys.stream().map((a) -> a.v2()).collect(Collectors.toList());
        if (keys.isEmpty() == false) {
            msg += " did you mean " + (keys.size() == 1 ? "[" + keys.get(0) + "]": "any of " + keys.toString()) + "?";
        } else {
            msg += " please check that any required plugins are installed, or check the breaking changes documentation for removed " +
                "settings";
        }
        throw new IllegalArgumentException(msg);
    }
    setting.get(settings);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:33,代码来源:AbstractScopedSettings.java


示例3: CheckConsistencyPanel

import org.apache.lucene.search.spell.LevensteinDistance; //导入依赖的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 );
	}
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:19,代码来源:CheckConsistencyPanel.java


示例4: main

import org.apache.lucene.search.spell.LevensteinDistance; //导入依赖的package包/类
public static void main(String[] args) throws IOException {

        if (args.length != 2) {
            LOGGER.info("Usage: java lia.tools.SpellCheckerTest SpellCheckerIndexDir wordToRespell");
            System.exit(1);
        }

        String spellCheckDir = args[0];
        String wordToRespell = args[1];

        Directory dir = FSDirectory.open(new File(spellCheckDir));
        if (!IndexReader.indexExists(dir)) {
            LOGGER.info("\nERROR: No spellchecker index at path \"" + spellCheckDir
                    + "\"; please run CreateSpellCheckerIndex first\n");
            System.exit(1);
        }
        SpellChecker spell = new SpellChecker(dir); // #A

        spell.setStringDistance(new LevensteinDistance()); // #B
        // spell.setStringDistance(new JaroWinklerDistance());

        String[] suggestions = spell.suggestSimilar(wordToRespell, 5); // #C
        LOGGER.info(suggestions.length + " suggestions for '" + wordToRespell + "':");
        for (String suggestion : suggestions)
            LOGGER.info("  " + suggestion);
    }
 
开发者ID:xuzhikethinker,项目名称:t4f-data,代码行数:27,代码来源:SpellCheckerExample.java


示例5: unrecognized

import org.apache.lucene.search.spell.LevensteinDistance; //导入依赖的package包/类
protected final String unrecognized(
    final RestRequest request,
    final Set<String> invalids,
    final Set<String> candidates,
    final String detail) {
    String message = String.format(
        Locale.ROOT,
        "request [%s] contains unrecognized %s%s: ",
        request.path(),
        detail,
        invalids.size() > 1 ? "s" : "");
    boolean first = true;
    for (final String invalid : invalids) {
        final LevensteinDistance ld = new LevensteinDistance();
        final List<Tuple<Float, String>> scoredParams = new ArrayList<>();
        for (final String candidate : candidates) {
            final float distance = ld.getDistance(invalid, candidate);
            if (distance > 0.5f) {
                scoredParams.add(new Tuple<>(distance, candidate));
            }
        }
        CollectionUtil.timSort(scoredParams, (a, b) -> {
            // sort by distance in reverse order, then parameter name for equal distances
            int compare = a.v1().compareTo(b.v1());
            if (compare != 0) return -compare;
            else return a.v2().compareTo(b.v2());
        });
        if (first == false) {
            message += ", ";
        }
        message += "[" + invalid + "]";
        final List<String> keys = scoredParams.stream().map(Tuple::v2).collect(Collectors.toList());
        if (keys.isEmpty() == false) {
            message += " -> did you mean " + (keys.size() == 1 ? "[" + keys.get(0) + "]" : "any of " + keys.toString()) + "?";
        }
        first = false;
    }

    return message;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:41,代码来源:BaseRestHandler.java


示例6: checkMisspelledPlugin

import org.apache.lucene.search.spell.LevensteinDistance; //导入依赖的package包/类
/** Returns all the official plugin names that look similar to pluginId. **/
private List<String> checkMisspelledPlugin(String pluginId) {
    LevensteinDistance ld = new LevensteinDistance();
    List<Tuple<Float, String>> scoredKeys = new ArrayList<>();
    for (String officialPlugin : OFFICIAL_PLUGINS) {
        float distance = ld.getDistance(pluginId, officialPlugin);
        if (distance > 0.7f) {
            scoredKeys.add(new Tuple<>(distance, officialPlugin));
        }
    }
    CollectionUtil.timSort(scoredKeys, (a, b) -> b.v1().compareTo(a.v1()));
    return scoredKeys.stream().map((a) -> a.v2()).collect(Collectors.toList());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:InstallPluginCommand.java


示例7: check

import org.apache.lucene.search.spell.LevensteinDistance; //导入依赖的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);
    }
}
 
开发者ID:brightgenerous,项目名称:brigen-base,代码行数:10,代码来源:LuceneDelegaterImpl.java


示例8: toLucene

import org.apache.lucene.search.spell.LevensteinDistance; //导入依赖的package包/类
@Override
public StringDistance toLucene() {
    return new LevensteinDistance();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:TermSuggestionBuilder.java


示例9: setUp

import org.apache.lucene.search.spell.LevensteinDistance; //导入依赖的package包/类
@Before
public void setUp() {
	ecc = new EngineConsistencyChecker( engine, false, new LevensteinDistance() );
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:5,代码来源:EngineConsistencyCheckerTest.java


示例10: main

import org.apache.lucene.search.spell.LevensteinDistance; //导入依赖的package包/类
/**
 * Main class.
 * 
 * @param args
 *          arguments
 * @throws IOException
 *           throw when error occurs
 */
public static void main(String[] args) throws IOException {
  if (args.length != 11 && args.length != 12) {
    System.err.println("Usage:");
    System.err.println("java -jar RelatedQueries.jar <redis_port> <redis_port> <time_between_queries> "
        + "<suggestion_threshold> <similarity_threshold> <more_similar> <distance_boost> "
        + "<timebased_boost> <non_zero_hits_only> <query_log> <output_file>");
    System.err.println("java -jar RelatedQueries.jar <redis_port> <redis_port> <time_between_queries> "
        + "<suggestion_threshold> <similarity_threshold> <more_similar> <distance_boost> "
        + "<timebased_boost> <non_zero_hits_only> <query_log> <es_host> <es_index>");
    System.exit(-1);
  }

  String redisHost = args[0];
  int redisPort = Integer.parseInt(args[1]);
  int timeBetweenQueries = Integer.parseInt(args[2]);
  double suggestionThreshold = Double.parseDouble(args[3]);
  float similarityThreshold = Float.parseFloat(args[4]);
  boolean moreSimilar = Boolean.parseBoolean(args[5]);
  float distanceBoost = Float.parseFloat(args[6]);
  float timebasedBoost = Float.parseFloat(args[7]);
  boolean nonZeroHitsOnly = Boolean.parseBoolean(args[8]);
  String queryLogPath = args[9];
  String outputFile = args[10];
  String esIndex = null;
  if (args.length == 12) {
    esIndex = args[11];
  }

  List<Float> boosts = new ArrayList<Float>();
  boosts.add(distanceBoost);
  boosts.add(timebasedBoost);

  List<String> prefixes = new ArrayList<String>();
  prefixes.add(Settings.STRING_DISTANCE_PREFIX);
  prefixes.add(Settings.TIME_CLICK_PREFIX);

  LookBackTrigger lookBackTrigger = null;

  SegmentProcessorQueriesEvaluator stringDistanceApproach = new SegmentProcessorQueriesEvaluator(redisHost, redisPort,
      queryLogPath, new TimeBasedLookBackStrategy(60 * 1000), lookBackTrigger,
      new SimilarityCond(new LevensteinDistance(), similarityThreshold, moreSimilar), suggestionThreshold,
      Settings.STRING_DISTANCE_PREFIX, nonZeroHitsOnly);

  SegmentProcessorQueriesEvaluator timeBasedApproach = new SegmentProcessorQueriesEvaluator(redisHost, redisPort,
      queryLogPath, new TimeBasedLookBackStrategy(timeBetweenQueries * 1000), lookBackTrigger,
      new SimilarityCond(new LevensteinDistance(), 0.1f, true), suggestionThreshold, Settings.TIME_CLICK_PREFIX,
      nonZeroHitsOnly);

  List<SegmentProcessorQueriesEvaluator> approachesList = new ArrayList<SegmentProcessorQueriesEvaluator>();
  approachesList.add(stringDistanceApproach);
  approachesList.add(timeBasedApproach);

  OutputWriter writer = null;
  boolean isEsEnabled = Boolean.parseBoolean(System.getProperty(Settings.ES_OUTPUT_ENABLED) != null
      ? System.getProperty(Settings.ES_OUTPUT_ENABLED) : "false");
  if (isEsEnabled) {
    writer = new CombinedQueriesEvaluatorESWriter(outputFile, esIndex, boosts, prefixes, 2, nonZeroHitsOnly);
  } else {
    writer = new CombinedQueriesEvaluatorFileWriter(outputFile, boosts, prefixes, 2, nonZeroHitsOnly);
  }

  writer.write(approachesList);
  writer.close();
}
 
开发者ID:sematext,项目名称:related-searches,代码行数:73,代码来源:TimeClickAndDistanceEvaluation.java


示例11: main

import org.apache.lucene.search.spell.LevensteinDistance; //导入依赖的package包/类
/**
 * Main class.
 * 
 * @param args
 *          arguments
 * @throws IOException
 *           throw when error occurs
 */
public static void main(String[] args) throws IOException {
  if (args.length < 7 || args.length > 9) {
    System.err.println("Usage:");
    System.err.println("java -jar RelatedQueries.jar <redis_port> <redis_port> <time_between_queries> "
        + "<suggestion_threshold> <similarity_threshold> <more_similar> <query_log>");
    System.err.println("java -jar RelatedQueries.jar <redis_port> <redis_port> <time_between_queries> "
        + "<suggestion_threshold> <similarity_threshold> <more_similar> <query_log> <output_file>");
    System.err.println("java -jar RelatedQueries.jar <redis_port> <redis_port> <time_between_queries> "
        + "<suggestion_threshold> <similarity_threshold> <more_similar> <query_log> <elasticsearch_address> <index_name>");
    System.exit(-1);
  }

  String redisHost = args[0];
  int redisPort = Integer.parseInt(args[1]);
  int timeBetweenQueries = Integer.parseInt(args[2]);
  double suggestionThreshold = Double.parseDouble(args[3]);
  float similarityThreshold = Float.parseFloat(args[4]);
  boolean moreSimilar = Boolean.parseBoolean(args[5]);
  String queryLogPath = args[6];
  String outputFile = null;
  String host = null;
  String index = null;
  if (args.length == 8) {
    outputFile = args[7];
  } else if (args.length == 9) {
    host = args[7];
    index = args[8];
  }

  List<SegmentProcessorQueriesEvaluator> sys = new LinkedList<SegmentProcessorQueriesEvaluator>();

  EntryAcceptCond conds[] = { new SimilarityCond(new LevensteinDistance(), similarityThreshold, moreSimilar) };

  // FIXME: extract to configuration
  LookBackStrategy strategies[] = { new TimeBasedLookBackStrategy(timeBetweenQueries * 1000) };

  // FIXME: extract to configuration
  LookBackTrigger triggers[] = { null };

  // initialize
  for (int i = 0; i < triggers.length; i++) {
    for (int j = 0; j < strategies.length; j++) {
      for (int k = 0; k < conds.length; k++) {
        sys.add(new SegmentProcessorQueriesEvaluator(redisHost, redisPort, queryLogPath, strategies[j], triggers[i],
            conds[k], suggestionThreshold, Settings.REDIS_PREFIX, false));
      }
    }
  }

  OutputWriter outputWriter;
  if (outputFile != null) {
    outputWriter = new SingleFileOutputWriter(outputFile, Settings.REDIS_PREFIX);
  } else if (host != null && index != null) {
    outputWriter = new ElasticsearchHTTPOutputWriter(host, index, Settings.REDIS_PREFIX);
  } else {
    outputWriter = new PerEvaluationFileOutputWriter(Settings.REDIS_PREFIX);
  }
  outputWriter.write(sys);
  outputWriter.close();
}
 
开发者ID:sematext,项目名称:related-searches,代码行数:69,代码来源:BasicRelatedSearchesEvaluator.java



注:本文中的org.apache.lucene.search.spell.LevensteinDistance类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RuleTemplate类代码示例发布时间:2022-05-22
下一篇:
Java TokenType类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap