当前位置: 首页>>代码示例>>Java>>正文


Java StringUtils.editDistance方法代码示例

本文整理汇总了Java中edu.stanford.nlp.util.StringUtils.editDistance方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.editDistance方法的具体用法?Java StringUtils.editDistance怎么用?Java StringUtils.editDistance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.stanford.nlp.util.StringUtils的用法示例。


在下文中一共展示了StringUtils.editDistance方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: nearestFile

import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
public static String nearestFile(String name, String directory, String badSubstring) {
   name = name.toLowerCase();
   File dir = new File(directory);
   if( dir.isDirectory() ) {
     float best = Float.MAX_VALUE;
     String bestName = null;
     for( String file : getFiles(dir) ) {
       file = file.toLowerCase();
       // edit distance?
       float editscore = StringUtils.editDistance(name, file);
//        System.out.println("name=" + name + "\tsimilar file " + file + " score = " + editscore);
       if( editscore < best && (badSubstring == null || !file.contains(badSubstring)) ) {
         best = editscore;
         bestName = file;
       }
     }
     return bestName;
   } else {
     System.out.println("(Directory) Not a directory: " + dir);
     System.exit(-1);
   }
   return null;
 }
 
开发者ID:nchambers,项目名称:schemas,代码行数:24,代码来源:Directory.java

示例2: editDistance

import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
private int editDistance(String query, String name) {

    String[] queryTokens = FileUtils.omitPunct(query).split("\\s+");
    String[] nameTokens = FileUtils.omitPunct(name).split("\\s+");

    StringBuilder querySb = new StringBuilder();
    for (String queryToken : queryTokens)
      querySb.append(queryToken).append(" ");

    StringBuilder nameSb = new StringBuilder();
    for (String nameToken : nameTokens)
      nameSb.append(nameToken).append(" ");

    return StringUtils.editDistance(querySb.toString().trim(), nameSb.toString().trim());
  }
 
开发者ID:cgraywang,项目名称:TextHIN,代码行数:16,代码来源:EntityLexicon.java

示例3: computeEditDistance

import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
public static int computeEditDistance(String query, Set<String> descriptions) {

    int distance = Integer.MAX_VALUE;
    for (String description : descriptions) {
      int currDistance = StringUtils.editDistance(query, description.toLowerCase());
      if (currDistance < distance) {
        distance = currDistance;
      }
    }
    return Math.min(15, distance);
  }
 
开发者ID:cgraywang,项目名称:TextHIN,代码行数:12,代码来源:LexicalEntry.java

示例4: computeSimilarity

import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
@Override
public double computeSimilarity(Concept c1, Concept c2) {
	if (c1.name.toLowerCase().equals(c2.name.toLowerCase()))
		return 1;
	double dist = StringUtils.editDistance(c1.name.toLowerCase().trim(), c2.name.toLowerCase().trim());
	int len = Math.max(c1.name.trim().length(), c2.name.trim().length());
	return Math.max(0, 1 - dist / len);
}
 
开发者ID:UKPLab,项目名称:ijcnlp2017-cmaps,代码行数:9,代码来源:EditDistance.java

示例5: nearestFile

import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
public static String nearestFile(String name, String directory, String badSubstring) {
    name = name.toLowerCase();
    File dir = new File(directory);
    if( dir.isDirectory() ) {
      float best = Float.MAX_VALUE;
      String bestName = null;
      for( String file : getFiles(dir) ) {
        file = file.toLowerCase();
        // edit distance?
        float editscore = StringUtils.editDistance(name, file);
//        System.out.println("name=" + name + "\tsimilar file " + file + " score = " + editscore);
        if( editscore < best && (badSubstring == null || !file.contains(badSubstring)) ) {
          best = editscore;
          bestName = file;
        }
        // If tied with best, save this one if it ends with the desired name.
        else if( editscore == best && file.endsWith(name) && (badSubstring == null || !file.contains(badSubstring)) ) {
          best = editscore;
          bestName = file;
        }
      }
      return bestName;
    } else {
      System.out.println("(Directory) Not a directory: " + dir);
      System.exit(-1);
    }
    return null;
  }
 
开发者ID:nchambers,项目名称:probschemas,代码行数:29,代码来源:Directory.java

示例6: stringMatchToMUCEntity

import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
public static boolean stringMatchToMUCEntity(MUCEntity gold, String guess, boolean warnings) {
    guess = replaceParentheses(guess);
    guess = guess.toLowerCase();
    String guessRightmost = (guess.indexOf(' ') > -1 ? guess.substring(guess.lastIndexOf(' ')+1) : guess); 
    
    for( String mention : gold.getMentions() ) {
      mention = mention.toLowerCase();
      boolean ofmatch = false;
//      System.out.println("  -> " + mention + " vs " + guess);

      // Check if guess subsumes mention.
      int index = guess.indexOf(mention);
      if( index > -1 ) {
        //	System.out.println("  --> gold in guess");
        // Don't let "maid" == "aid"
        if( index == 0 || guess.charAt(index-1) == ' ' ) {
          // Don't let "Party of Ohio" == "Ohio"
          if( !guess.contains("of " + mention) )
            return true;
          else {
            if( warnings ) System.out.println("GOOD MATCH GONE BAD?? gold=" + gold + " guess=" + guess);
            ofmatch = true;
          }
        }
      }

      // Check the inverse (mention subsumes guess).
      index = mention.indexOf(guess);
      if( index > -1 ) {
        //	System.out.println("  --> guess in gold");
        if( index == 0 || mention.charAt(index-1) == ' ' ) {
          if( !mention.contains("of " + guess) )
            return true;
          else {
            if( warnings ) System.out.println("GOOD MATCH GONE BAD?? gold=" + gold + " guess=" + guess);
            ofmatch = true;
          }
        }
      }
      
      // Check if they are long strings, with very minimal edits (typographical errors).
      if( guess.length() > 15 && mention.length() > 15 ) {
        if( Math.abs(guess.length() - mention.length()) < 5 ) {
          if( StringUtils.editDistance(guess, mention) < (guess.length() / 6) ) {
            System.out.println("EDIT DISTANCE MATCH! " + guess + " with gold " + mention);
            return true;
          }
        }
      }
      
      // Finally, if the rightmost word matches, we win. This is probably too broad, but it is what everyone does
      // in this field. It does seem to give credit to a lot of things that should be given credit, but it also
      // makes mistakes.
      String mentionRightmost = (mention.indexOf(' ') > -1 ? mention.substring(mention.lastIndexOf(' ')+1) : mention);
      if( !ofmatch && mentionRightmost.equals(guessRightmost) ) {
        System.out.println("RIGHTMOST MATCH: " + guess + " with gold " + mention);
        return true;
      }
    }

    return false;
  }
 
开发者ID:nchambers,项目名称:probschemas,代码行数:63,代码来源:TemplateTester.java

示例7: setF_strSim

import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
public void setF_strSim() {
  // TODO Auto-generated method stub
  stringSim = StringUtils.editDistance(asciiName, originName);
  stringSim = 1.0d - stringSim / (double) Math.max(asciiName.length(), originName.length());
}
 
开发者ID:weizh,项目名称:geolocator-3.0,代码行数:6,代码来源:CandidateAndFeature.java


注:本文中的edu.stanford.nlp.util.StringUtils.editDistance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。