Package edu.stanford.nlp.io

Examples of edu.stanford.nlp.io.PrintFile


      fAssociations = Generics.newArrayList();
      for (int i = 0; i < extractors.size() + extractorsRare.size(); ++i) {
        fAssociations.add(Generics.<String, int[]>newHashMap());
      }
      if (VERBOSE) System.err.printf("Reading %d feature keys...%n",sizeAssoc);
      PrintFile pfVP = null;
      if (VERBOSE) {
        pfVP = new PrintFile("pairs.txt");
      }
      for (int i = 0; i < sizeAssoc; i++) {
        int numF = rf.readInt();
        FeatureKey fK = new FeatureKey();
        fK.read(rf);
View Full Code Here


    System.err.println("## tagger training invoked at " + now + " with arguments:");
    config.dump();
    Timing tim = new Timing();

    PrintFile log = new PrintFile(config.getModel() + ".props");
    log.println("## tagger training invoked at " + now + " with arguments:");
    config.dump(log);
    log.close();

    trainAndSaveModel(config);
    tim.done("Training POS tagger");
  }
View Full Code Here

    }

    test();

    if (writeConfusionMatrix) {
      PrintFile pf = new PrintFile(saveRoot + ".confusion");
      pf.print(confusionMatrix.toString());
      pf.close();
    }
  }
View Full Code Here

    throws IOException
  {
    numSentences = 0;
    confusionMatrix = new ConfusionMatrix<String>();

    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");

    boolean verboseResults = config.getVerboseResults();

    if (config.getNThreads() != 1) {
      MulticoreWrapper<List<TaggedWord>, TestSentence> wrapper = new MulticoreWrapper<List<TaggedWord>, TestSentence>(config.getNThreads(), new TestSentenceProcessor(maxentTagger));
      for (List<TaggedWord> taggedSentence : fileRecord.reader()) {
        wrapper.put(taggedSentence);
        while (wrapper.peek()) {
          processResults(wrapper.poll(), pf, pf1, pf3, verboseResults);
        }
      }
      wrapper.join();
      while (wrapper.peek()) {
        processResults(wrapper.poll(), pf, pf1, pf3, verboseResults);
      }
    } else{
      for (List<TaggedWord> taggedSentence : fileRecord.reader()) {
        TestSentence testS = new TestSentence(maxentTagger);
        testS.setCorrectTags(taggedSentence);
        testS.tagSentence(taggedSentence, false);
        processResults(testS, pf, pf1, pf3, verboseResults);
      }
    }

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

    }
  }

  public void print(String filename) {
    try {
      PrintFile pf = new PrintFile(filename);
      pf.println(" Problem printing ");
      data.print(pf);
      pf.println(" Function printing ");
      for (int i = 0; i < fSize; i++) {
        functions.get(i).print(pf);
      }
    } catch (Exception e) {
      System.out.println("Exception in Problem.print()");
View Full Code Here

    dict.setAmbClasses();

    int[] numFA = new int[extractors.getSize() + extractorsRare.getSize()];
    int sizeAssoc = rf.readInt();
    PrintFile pfVP = null;
    if (VERBOSE) {
      pfVP = new PrintFile("pairs.txt");
    }
    for (int i = 0; i < sizeAssoc; i++) {
      int numF = rf.readInt();
      FeatureKey fK = new FeatureKey();
      fK.read(rf);
      numFA[fK.num]++;
      fAssociations.put(fK, numF);
    }

    if (VERBOSE) {
      pfVP.close();
    }
    if (VERBOSE) {
      for (int k = 0; k < numFA.length; k++) {
        System.err.println(" Number of features of kind " + k + ' ' + numFA[k]);
      }
View Full Code Here

    // sizeAssoc as argument defines an initial size.
    // Unless load factor is >= 1, fAssociations is guaranteed to resize at least once.
    //fAssociations = new HashMap<FeatureKey,Integer>(sizeAssoc);
    fAssociations = new HashMap<FeatureKey,Integer>(sizeAssoc*2);
    if (VERBOSE) System.err.printf("Reading %d feature keys...\n",sizeAssoc);
    PrintFile pfVP = null;
    if (VERBOSE) {
      pfVP = new PrintFile("pairs.txt");
    }
    for (int i = 0; i < sizeAssoc; i++) {
      int numF = rf.readInt();
      FeatureKey fK = new FeatureKey();
      fK.read(rf);
      numFA[fK.num]++;
      fAssociations.put(fK, numF);
    }
    if (VERBOSE) {
      pfVP.close();
    }
    if (VERBOSE) {
      for (int k = 0; k < numFA.length; k++) {
        System.err.println(" Number of features of kind " + k + ' ' + numFA[k]);
      }
View Full Code Here

    }
  }

  public void print(String filename) {
    try {
      PrintFile pf = new PrintFile(filename);
      pf.println(" Problem printing ");
      data.print(pf);
      pf.println(" Function printing ");
      for (int i = 0; i < fSize; i++) {
        functions.get(i).print(pf);
      }
    } catch (Exception e) {
      System.out.println("Exception in Problem.print()");
View Full Code Here

   * like reducing the memory requirements
   */

  void save_problem(String filename) {
    try {
      PrintFile pf = new PrintFile(filename);
      int N = Experiments.xSize;
      int M = Experiments.ySize;
      int F = p.fSize;
      // byte[] nl = "\n".getBytes();
      // byte[] dotsp = ". ".getBytes();
      // int space = (int) ' ';
      // write the sizes of X, Y, and F( number of features );
      pf.println(N);
      pf.println(M);
      pf.println(F);
      // save the objective vector like 1.c0, ... ,N*M. cN*M-1
      for (int i = 0; i < N * M; i++) {
        pf.print(i + 1);
        pf.print(". ");
        pf.println(p.data.ptildeX(i / M));
      }// for i

      // save the constraints matrix B
      // for each feature , save its row
      for (int i = 0; i < p.fSize; i++) {
        int[] values = p.functions.get(i).indexedValues;
        for (int k = 0; k < values.length; k++) {
          pf.print(i + 1);
          pf.print(". ");
          pf.print(values[k]);
          pf.print(" ");
          pf.println(1);
        }// k

      }// i

      // save the constraints vector
      // for each feature, save its empirical expectation

      for (int i = 0; i < p.fSize; i++) {
        pf.print(i + 1);
        pf.print(". ");
        pf.println(ftildeArr[i]);
      }// end
      pf.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
View Full Code Here

    System.err.println("## tagger training invoked at " + now + " with arguments:");
    config.dump();
    Timing tim = new Timing();
    try {
      PrintFile log = new PrintFile(config.getModel() + ".props");
      log.println("## tagger training invoked at " + now + " with arguments:");
      config.dump(log);
      log.close();

      TestClassifier.trainAndSaveModel(config);
      tim.done("Training POS tagger");
    } catch(Exception e) {
      System.err.println("An error occurred while training a new tagger.");
View Full Code Here

TOP

Related Classes of edu.stanford.nlp.io.PrintFile

Copyright © 2018 www.massapicom. 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.