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


Java StringUtils.argsToMap方法代码示例

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


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

示例1: validateCommandLine

import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
private static boolean validateCommandLine(String[] args) {
  Map<String, String[]> argsMap = StringUtils.argsToMap(args,optionArgDefs);
  
  for(Map.Entry<String, String[]> opt : argsMap.entrySet()) {
    String key = opt.getKey();
    if(key == null) {
      continue;
    
    } else if(key.equals("-y")) {
      MAX_GOLD_YIELD = Integer.valueOf(opt.getValue()[0]);
    
    } else if(key.equals("-l")) {
      LANGUAGE = Language.valueOf(opt.getValue()[0]);
    
    } else if(key.equals("-v")) {
      VERBOSE = true;
    
    } else {
      return false;
    }
  }
  
  //Regular arguments
  String[] rest = argsMap.get(null);
  if(rest == null || rest.length != MIN_ARGS) {
    return false;
  } else {
    goldFile = new File(rest[0]);
    guessFile = new File(rest[1]);
  }
  
  return true;
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:34,代码来源:LeafAncestorEval.java

示例2: validateCommandLine

import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
private static boolean validateCommandLine(String[] args) {
  Map<String, String[]> argsMap = StringUtils.argsToMap(args,optionArgDefs);

  for(Map.Entry<String, String[]> opt : argsMap.entrySet()) {
    String key = opt.getKey();
    if(key == null) {
      continue;

    } else if(key.equals("-d")) {
      MAKE_DISTRIB = true;
      distribName = opt.getValue()[0];

    } else if(key.equals("-v")) {
      VERBOSE = true;

    } else if(key.equals("-p")) {
      outputPath = opt.getValue()[0];

    } else {
      return false;
    }
  }

  //Regular arguments
  String[] rest = argsMap.get(null);
  if(rest == null || rest.length != MIN_ARGS) {
    return false;
  } else {
    configFile = rest[0];
  }

  return true;
}
 
开发者ID:amark-india,项目名称:eventspotter,代码行数:34,代码来源:TreebankPreprocessor.java

示例3: main

import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
/**
  * The main method reads (segmented, whitespace delimited) words from a file
  * and prints them with their English translation(s).
  *
  * The path and filename of the CEDict Lexicon can be supplied via the
  * "-dictPath" flag; otherwise the default filename "cedict_ts.u8" in the
  * current directory is checked.
  *
  * By default, only the first translation is printed.  If the "-all" flag
  * is given, all translations are printed.
  *
  * The input and output encoding can be specified using the "-encoding" flag.
  * Otherwise UTF-8 is assumed.
  */
 public static void main(String[] args) throws IOException {
   Map<String, Integer> flagsToNumArgs = new HashMap<String, Integer>();
   flagsToNumArgs.put("-dictPath" , 1);
   flagsToNumArgs.put("-encoding" , 1);
   Map<String, String[]> argMap = StringUtils.argsToMap(args, flagsToNumArgs);
   String[] otherArgs = argMap.get(null);
   if (otherArgs.length < 1) {
     System.err.println("usage: ChineseEnglishWordMap [-all] [-dictPath path] [-encoding enc_string] inputFile");
     System.exit(1);
   }
   String filename = otherArgs[0];
   boolean allTranslations = argMap.containsKey("-all");
   String charset = defaultCharset;
   if (argMap.containsKey("-encoding")) {
     charset = argMap.get("-encoding")[0];
   }
   BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(filename), charset));

   TreebankLanguagePack tlp = new ChineseTreebankLanguagePack();
   String[] dpString = argMap.get("-dictPath");
   ChineseEnglishWordMap cewm = (dpString == null) ? new ChineseEnglishWordMap() : new ChineseEnglishWordMap(dpString[0]);
   int totalWords = 0, coveredWords = 0;

   PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out, charset), true);

   for (String line = r.readLine(); line != null; line = r.readLine()) {
     String[] words = line.split("\\s", 1000);
     for (String word : words) {
       totalWords++;
       if (word.length() == 0) continue;
       pw.print(StringUtils.pad(word + ':', 8));
       if (tlp.isPunctuationWord(word)) {
         totalWords--;
         pw.print(word);
} else if (isDigits(word)) {
  pw.print(word + " [NUMBER]");
       } else if (cewm.containsKey(word)) {
         coveredWords++;
         if (allTranslations) {
           List<String> trans = new ArrayList<String>(cewm.getAllTranslations(word));
           for (String s : trans) {
             pw.print((trans.indexOf(s) > 0 ? "|" : "") + s);
           }
         } else {
           pw.print(cewm.getFirstTranslation(word));
         }
       } else {
         pw.print("[UNK]");
       }
pw.println();
     }
     pw.println();
   }
   r.close();
   System.err.print("Finished translating " + totalWords + " words (");
   System.err.println(coveredWords + " were in dictionary).");
 }
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:72,代码来源:ChineseEnglishWordMap.java

示例4: main

import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
/**
  * The main method reads (segmented, whitespace delimited) words from a file
  * and prints them with their English translation(s).
  *
  * The path and filename of the CEDict Lexicon can be supplied via the
  * "-dictPath" flag; otherwise the default filename "cedict_ts.u8" in the
  * current directory is checked.
  *
  * By default, only the first translation is printed.  If the "-all" flag
  * is given, all translations are printed.
  *
  * The input and output encoding can be specified using the "-encoding" flag.
  * Otherwise UTF-8 is assumed.
  */
 public static void main(String[] args) throws IOException {
   Map<String, Integer> flagsToNumArgs = Generics.newHashMap();
   flagsToNumArgs.put("-dictPath" , 1);
   flagsToNumArgs.put("-encoding" , 1);
   Map<String, String[]> argMap = StringUtils.argsToMap(args, flagsToNumArgs);
   String[] otherArgs = argMap.get(null);
   if (otherArgs.length < 1) {
     System.err.println("usage: ChineseEnglishWordMap [-all] [-dictPath path] [-encoding enc_string] inputFile");
     System.exit(1);
   }
   String filename = otherArgs[0];
   boolean allTranslations = argMap.containsKey("-all");
   String charset = defaultCharset;
   if (argMap.containsKey("-encoding")) {
     charset = argMap.get("-encoding")[0];
   }
   BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(filename), charset));

   TreebankLanguagePack tlp = new ChineseTreebankLanguagePack();
   String[] dpString = argMap.get("-dictPath");
   ChineseEnglishWordMap cewm = (dpString == null) ? new ChineseEnglishWordMap() : new ChineseEnglishWordMap(dpString[0]);
   int totalWords = 0, coveredWords = 0;

   PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out, charset), true);

   for (String line = r.readLine(); line != null; line = r.readLine()) {
     String[] words = line.split("\\s", 1000);
     for (String word : words) {
       totalWords++;
       if (word.length() == 0) continue;
       pw.print(StringUtils.pad(word + ':', 8));
       if (tlp.isPunctuationWord(word)) {
         totalWords--;
         pw.print(word);
} else if (isDigits(word)) {
  pw.print(word + " [NUMBER]");
       } else if (cewm.containsKey(word)) {
         coveredWords++;
         if (allTranslations) {
           List<String> trans = new ArrayList<String>(cewm.getAllTranslations(word));
           for (String s : trans) {
             pw.print((trans.indexOf(s) > 0 ? "|" : "") + s);
           }
         } else {
           pw.print(cewm.getFirstTranslation(word));
         }
       } else {
         pw.print("[UNK]");
       }
pw.println();
     }
     pw.println();
   }
   r.close();
   System.err.print("Finished translating " + totalWords + " words (");
   System.err.println(coveredWords + " were in dictionary).");
 }
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:72,代码来源:ChineseEnglishWordMap.java


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