Examples of PrintFile


Examples of edu.stanford.nlp.io.PrintFile

  private void test(int format, String saveRoot, String tagSeparator, String encoding) throws IOException {
    if ((format == 1)) {
      test(saveRoot, tagSeparator, encoding); //the data is tagged
    } else {
      BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(filename), encoding));
      PrintFile pf = null;
      PrintFile pf1 = null;
      if (writeWords) pf = new PrintFile(saveRoot + ".words");
      if (writeUnknDict) pf1 = new PrintFile(saveRoot + ".un.dict");

      for (String s; (s = in.readLine()) != null; ) {
        Sentence<Word> sent = Sentence.toSentence(Arrays.asList(s.split("\\s+")));
        ts.tagSentence(sent);
        if (pf != null) {
          pf.println(ts.getTaggedNice());
        }
      }

      in.close();
      if (pf != null) pf.close();
      if (pf1 != null) pf1.close();
    }
  }
View Full Code Here

Examples of edu.stanford.nlp.io.PrintFile

   */
  private void test(TaggerConfig config, String saveRoot) throws IOException {
    numSentences = 0;
    String eosTag = "EOS";
    String eosWord = "EOS";
    PrintFile pf = null;
    PrintFile pf1 = null;
    PrintFile pf3 = null;

    if(writeWords) pf = new PrintFile(saveRoot + ".words");
    if(writeUnknDict) pf1 = new PrintFile(saveRoot + ".un.dict");
    if(writeTopWords) pf3 = new PrintFile(saveRoot + ".words.top");
    TreeReaderFactory trf = new LabeledScoredTreeReaderFactory();
    DiskTreebank treebank = new DiskTreebank(trf,config.getEncoding());
    TreeTransformer transformer = config.getTreeTransformer();
    TreeNormalizer normalizer = config.getTreeNormalizer();

    if (config.getTreeRange() != null) {
      treebank.loadPath(filename, new NumberRangesFileFilter(config.getTreeRange(), true));
    } else {
      treebank.loadPath(filename);
    }
    for (Tree t : treebank) {
      if (normalizer != null) {
        t = normalizer.normalizeWholeTree(t, t.treeFactory());
      }
      if (transformer != null) {
        t = t.transform(transformer);
      }

      List<String> sentence = new ArrayList<String>();
      List<String> tagsArr = new ArrayList<String>();

      for (TaggedWord cur : t.taggedYield()) {
        tagsArr.add(cur.tag());
        sentence.add(cur.word());
      }
      //the sentence is read already, add eos
      sentence.add(eosWord);
      tagsArr.add(eosTag);
      numSentences++;

      int len = sentence.size();
      String[] testSent = new String[len];
      String[] correctTags = new String[len];
      for (int i = 0; i < len; i++) {
        testSent[i] = sentence.get(i);
        correctTags[i] = tagsArr.get(i);
      }

      TestSentence testS = new TestSentence(GlobalHolder.getLambdaSolve(), testSent, correctTags, pf, wrongWords);
      if (writeUnknDict) testS.printUnknown(numSentences, pf1);
      if (writeTopWords) testS.printTop(pf3);

      numWrong = numWrong + testS.numWrong;
      numRight = numRight + testS.numRight;
      unknownWords = unknownWords + testS.numUnknown;
      numWrongUnknown = numWrongUnknown + testS.numWrongUnknown;
      if (testS.numWrong == 0) {
        numCorrectSentences++;
      }
      System.out.println("Sentence number: " + numSentences + "; length " + (len-1) + "; correct: " + testS.numRight + "; wrong: " + testS.numWrong + "; unknown wrong: " + testS.numWrongUnknown);
      System.out.println("  Total tags correct: " + numRight + "; wrong: " + numWrong + "; unknown wrong: " + numWrongUnknown);
    }

    if(pf != null) pf.close();
    if(pf1 != null) pf1.close();
    if(pf3 != null) pf3.close();
  }
View Full Code Here

Examples of edu.stanford.nlp.io.PrintFile

   */
  private void test(String saveRoot, String tagSeparator, String encoding) throws IOException {
    numSentences = 0;
    String eosTag = "EOS";
    String eosWord = "EOS";
    PrintFile pf = null;
    PrintFile pf1 = null;
    PrintFile pf3 = null;

    BufferedReader rf = new BufferedReader(new InputStreamReader(new FileInputStream(filename), encoding));
    if (writeWords) pf = new PrintFile(saveRoot + ".words");
    if (writeUnknDict) pf1 = new PrintFile(saveRoot + ".un.dict");
    if (writeTopWords) pf3 = new PrintFile(saveRoot + ".words.top");

    for (String s; (s = rf.readLine()) != null; ) {
      List<String> sentence = new ArrayList<String>();
      List<String> tagsArr = new ArrayList<String>();
      StringTokenizer st = new StringTokenizer(s);
      while (st.hasMoreTokens()) { // find the sentence there

        String token = st.nextToken();
        int index = token.lastIndexOf(tagSeparator);

        if (index == -1) {
          throw new RuntimeException("I was unable to find the delimiter '" + tagSeparator + "' in the token '" + token + "'. Consider using -delimiter.");
        }

        String w1 = token.substring(0, index);
        sentence.add(w1);
        String t1 = token.substring(index + 1);
        tagsArr.add(t1);
      }

      //the sentence is read already, add eos
      sentence.add(eosWord);
      tagsArr.add(eosTag);
      numSentences++;

      int len = sentence.size();
      String[] testSent = new String[len];
      String[] correctTags = new String[len];
      for (int i = 0; i < len; i++) {
        testSent[i] = sentence.get(i);
        correctTags[i] = tagsArr.get(i);
      }

      TestSentence testS = new TestSentence(GlobalHolder.getLambdaSolve(), testSent, correctTags, pf, wrongWords);
      if(writeUnknDict) testS.printUnknown(numSentences, pf1);
      if(writeTopWords) testS.printTop(pf3);

      numWrong = numWrong + testS.numWrong;
      numRight = numRight + testS.numRight;
      unknownWords = unknownWords + testS.numUnknown;
      numWrongUnknown = numWrongUnknown + testS.numWrongUnknown;
      if (testS.numWrong == 0) {
        numCorrectSentences++;
      }
      System.out.println("Sentence number: " + numSentences + "; length " + (len-1) + "; correct: " + testS.numRight + "; wrong: " + testS.numWrong + "; unknown wrong: " + testS.numWrongUnknown);
      System.out.println("  Total tags correct: " + numRight + "; wrong: " + numWrong + "; unknown wrong: " + numWrongUnknown);
    }

    rf.close();
    if (pf != null) pf.close();
    if (pf1 != null) pf1.close();
    if (pf3 != null) pf3.close();
  }
View Full Code Here

Examples of org.apache.accumulo.core.util.shell.Shell.PrintFile

  private Option optEndRowExclusive;
  private Option timeoutOption;
  private Option profileOpt;
 
  public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception {
    final PrintFile printFile = getOutputFile(cl);
   
    final String tableName = OptUtil.getTableOpt(cl, shellState);
   
    final Class<? extends Formatter> formatter = getFormatter(cl, tableName, shellState);
    final ScanInterpreter interpeter = getInterpreter(cl, tableName, shellState);
   
    // handle first argument, if present, the authorizations list to
    // scan with
    final Authorizations auths = getAuths(cl, shellState);
    final Scanner scanner = shellState.getConnector().createScanner(tableName, auths);
   
    // handle session-specific scan iterators
    addScanIterators(shellState, cl, scanner, tableName);
   
    // handle remaining optional arguments
    scanner.setRange(getRange(cl, interpeter));
   
    // handle columns
    fetchColumns(cl, scanner, interpeter);
   
    // set timeout
    scanner.setTimeout(getTimeout(cl), TimeUnit.MILLISECONDS);

    // output the records
    if (cl.hasOption(showFewOpt.getOpt())) {
      final String showLength = cl.getOptionValue(showFewOpt.getOpt());
      try {
        final int length = Integer.parseInt(showLength);
        if (length < 1) {
          throw new IllegalArgumentException();
        }
        BinaryFormatter.getlength(length);
        printBinaryRecords(cl, shellState, scanner, printFile);
      } catch (NumberFormatException nfe) {
        shellState.getReader().printString("Arg must be an integer. \n");
      } catch (IllegalArgumentException iae) {
        shellState.getReader().printString("Arg must be greater than one. \n");
      }
     
    } else {
      printRecords(cl, shellState, scanner, formatter, printFile);
    }
    if (printFile != null) {
      printFile.close();
    }
   
    return 0;
  }
View Full Code Here

Examples of org.apache.accumulo.core.util.shell.Shell.PrintFile

    return 0;
  }
 
  protected PrintFile getOutputFile(final CommandLine cl) throws FileNotFoundException {
    final String outputFile = cl.getOptionValue(outputFileOpt.getOpt());
    return (outputFile == null ? null : new PrintFile(outputFile));
  }
View Full Code Here

Examples of org.apache.accumulo.core.util.shell.Shell.PrintFile

    final String m = cl.getOptionValue(maxSplitsOpt.getOpt());
    final int maxSplits = m == null ? 0 : Integer.parseInt(m);
    final boolean encode = cl.hasOption(base64Opt.getOpt());
    final boolean verbose = cl.hasOption(verboseOpt.getOpt());
   
    final PrintLine p = outputFile == null ? new PrintShell(shellState.getReader()) : new PrintFile(outputFile);
   
    try {
      if (!verbose) {
        for (Text row : maxSplits > 0 ? shellState.getConnector().tableOperations().listSplits(tableName, maxSplits) : shellState.getConnector()
            .tableOperations().listSplits(tableName)) {
View Full Code Here

Examples of org.apache.accumulo.core.util.shell.Shell.PrintFile

 
  private Option numThreadsOpt;
 
  @Override
  public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception {
    final PrintFile printFile = getOutputFile(cl);
   
    final String tableName = OptUtil.getTableOpt(cl, shellState);
   
    if (cl.getArgList().isEmpty()) {
      throw new MissingArgumentException("No terms specified");
View Full Code Here

Examples of org.apache.accumulo.core.util.shell.Shell.PrintFile

      // display properties
      final TreeMap<String,String> systemConfig = new TreeMap<String,String>();
      systemConfig.putAll(shellState.getConnector().instanceOperations().getSystemConfiguration());
     
      final String outputFile = cl.getOptionValue(outputFileOpt.getOpt());
      final PrintFile printFile = outputFile == null ? null : new PrintFile(outputFile);
     
      final TreeMap<String,String> siteConfig = new TreeMap<String,String>();
      siteConfig.putAll(shellState.getConnector().instanceOperations().getSiteConfiguration());
     
      final TreeMap<String,String> defaults = new TreeMap<String,String>();
      for (Entry<String,String> defaultEntry : AccumuloConfiguration.getDefaultConfiguration()) {
        defaults.put(defaultEntry.getKey(), defaultEntry.getValue());
      }
      Iterable<Entry<String,String>> acuconf = shellState.getConnector().instanceOperations().getSystemConfiguration().entrySet();
      if (tableName != null) {
        acuconf = shellState.getConnector().tableOperations().getProperties(tableName);
      }
      final TreeMap<String,String> sortedConf = new TreeMap<String,String>();
      for (Entry<String,String> propEntry : acuconf) {
        sortedConf.put(propEntry.getKey(), propEntry.getValue());
      }
     
      for (Entry<String,String> propEntry : acuconf) {
        final String key = propEntry.getKey();
        // only show properties with similar names to that
        // specified, or all of them if none specified
        if (cl.hasOption(filterOpt.getOpt()) && !key.contains(cl.getOptionValue(filterOpt.getOpt()))) {
          continue;
        }
        if (tableName != null && !Property.isValidTablePropertyKey(key)) {
          continue;
        }
        COL2 = Math.max(COL2, propEntry.getKey().length() + 3);
      }
     
      final ArrayList<String> output = new ArrayList<String>();
      printConfHeader(output);
     
      for (Entry<String,String> propEntry : sortedConf.entrySet()) {
        final String key = propEntry.getKey();
       
        // only show properties with similar names to that
        // specified, or all of them if none specified
        if (cl.hasOption(filterOpt.getOpt()) && !key.contains(cl.getOptionValue(filterOpt.getOpt()))) {
          continue;
        }
        if (tableName != null && !Property.isValidTablePropertyKey(key)) {
          continue;
        }
        String siteVal = siteConfig.get(key);
        String sysVal = systemConfig.get(key);
        String curVal = propEntry.getValue();
        String dfault = defaults.get(key);
        boolean printed = false;
       
        if (dfault != null && key.toLowerCase().contains("password")) {
          siteVal = sysVal = dfault = curVal = curVal.replaceAll(".", "*");
        }
        if (sysVal != null) {
          if (defaults.containsKey(key)) {
            printConfLine(output, "default", key, dfault);
            printed = true;
          }
          if (!defaults.containsKey(key) || !defaults.get(key).equals(siteVal)) {
            printConfLine(output, "site", printed ? "   @override" : key, siteVal == null ? "" : siteVal);
            printed = true;
          }
          if (!siteConfig.containsKey(key) || !siteVal.equals(sysVal)) {
            printConfLine(output, "system", printed ? "   @override" : key, sysVal == null ? "" : sysVal);
            printed = true;
          }
        }
       
        // show per-table value only if it is different (overridden)
        if (tableName != null && !curVal.equals(sysVal)) {
          printConfLine(output, "table", printed ? "   @override" : key, curVal);
        }
      }
      printConfFooter(output);
      shellState.printLines(output.iterator(), !cl.hasOption(disablePaginationOpt.getOpt()), printFile);
      if (printFile != null) {
        printFile.close();
      }
    }
    return 0;
  }
View Full Code Here

Examples of org.apache.accumulo.core.util.shell.Shell.PrintFile

  private Option timeoutOption;
  private Option profileOpt;
 
  @Override
  public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception {
    final PrintFile printFile = getOutputFile(cl);
    final String tableName = OptUtil.getTableOpt(cl, shellState);
   
    final Class<? extends Formatter> formatter = getFormatter(cl, tableName, shellState);
    final ScanInterpreter interpeter = getInterpreter(cl, tableName, shellState);
   
    // handle first argument, if present, the authorizations list to
    // scan with
    final Authorizations auths = getAuths(cl, shellState);
    final Scanner scanner = shellState.getConnector().createScanner(tableName, auths);
   
    // handle session-specific scan iterators
    addScanIterators(shellState, cl, scanner, tableName);
   
    // handle remaining optional arguments
    scanner.setRange(getRange(cl, interpeter));
   
    // handle columns
    fetchColumns(cl, scanner, interpeter);
   
    // set timeout
    scanner.setTimeout(getTimeout(cl), TimeUnit.MILLISECONDS);
   
    // output the records
    if (cl.hasOption(showFewOpt.getOpt())) {
      final String showLength = cl.getOptionValue(showFewOpt.getOpt());
      try {
        final int length = Integer.parseInt(showLength);
        if (length < 1) {
          throw new IllegalArgumentException();
        }
        BinaryFormatter.getlength(length);
        printBinaryRecords(cl, shellState, scanner, printFile);
      } catch (NumberFormatException nfe) {
        shellState.getReader().println("Arg must be an integer.");
      } catch (IllegalArgumentException iae) {
        shellState.getReader().println("Arg must be greater than one.");
      }
     
    } else {
      printRecords(cl, shellState, scanner, formatter, printFile);
    }
    if (printFile != null) {
      printFile.close();
    }
   
    return 0;
  }
View Full Code Here

Examples of org.apache.accumulo.core.util.shell.Shell.PrintFile

    return 0;
  }
 
  protected PrintFile getOutputFile(final CommandLine cl) throws FileNotFoundException {
    final String outputFile = cl.getOptionValue(outputFileOpt.getOpt());
    return (outputFile == null ? null : new PrintFile(outputFile));
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.