public void decode(
      DependencyInstance instance,
      int K,
      Parameters params,
      String[] formsNoRoot,
      String[] cposNoRoot,
      String[] posNoRoot,
      String[] labels,
      int[] heads,
      ConfidenceEstimator confEstimator,
      boolean writeOutput)
      throws IOException {

    String[] results = decode(instance, K, params);

    int i = 0;
    while (i < results.length && !results[i].equals("null")) {
      // write scores
      scoreWriter.write(scores[i] + " ");

      // System.out.println(results[i]);
      String[] res = results[i].split(" ");
      String[] forms = instance.forms;
      String[] cpos = instance.cpostags;
      String[] pos = instance.postags;

      for (int j = 0; j < forms.length - 1; j++) {
        formsNoRoot[j] = forms[j + 1];
        cposNoRoot[j] = cpos[j + 1];
        posNoRoot[j] = pos[j + 1];
        String[] trip = res[j].split("[\\|:]"); // System.out.println(res[j]);
        labels[j] = pipe.types[Integer.parseInt(trip[2])];
        heads[j] = Integer.parseInt(trip[0]);
      }

      DependencyInstance parsedInstance;
      if (confEstimator != null) {
        double[] confidenceScores = confEstimator.estimateConfidence(instance);
        parsedInstance =
            new DependencyInstance(
                formsNoRoot, cposNoRoot, posNoRoot, labels, heads, confidenceScores);
      } else {
        parsedInstance = new DependencyInstance(formsNoRoot, cposNoRoot, posNoRoot, labels, heads);
      }
      if (writeOutput) {
        pipe.outputInstance(parsedInstance);
      }

      i++;
    }
    scoreWriter.write("\n");
  }
  /**
   * Get the parses.
   *
   * @param allInstances a list to which all parse results are written. Can be {@code null}.
   * @param writeOutput write output to file and log some messages to screen.
   */
  protected void outputParses(List<DependencyInstance> allInstances, boolean writeOutput)
      throws IOException {

    String tFile = options.testfile;
    String file = null;
    if (writeOutput) {
      file = options.outfile;
    }

    ConfidenceEstimator confEstimator = null;
    if (options.confidenceEstimator != null) {
      confEstimator = ConfidenceEstimator.resolveByName(options.confidenceEstimator, this);
      System.out.println("Applying confidence estimation: " + options.confidenceEstimator);
    }

    long start = System.currentTimeMillis();

    pipe.initInputFile(tFile);
    if (writeOutput) {
      pipe.initOutputFile(file);
    }

    if (writeOutput) {
      System.out.print("Processing Sentence: ");
    }
    DependencyInstance instance = pipe.nextInstance();
    int cnt = 0;
    while (instance != null) {
      cnt++;
      if (writeOutput) {
        System.out.print(cnt + " ");
      }
      String[] forms = instance.forms;
      String[] formsNoRoot = new String[forms.length - 1];
      String[] posNoRoot = new String[formsNoRoot.length];
      String[] cposNoRoot = new String[formsNoRoot.length];
      String[] labels = new String[formsNoRoot.length];
      int[] heads = new int[formsNoRoot.length];

      decode(
          instance,
          options.testK,
          params,
          formsNoRoot,
          cposNoRoot,
          posNoRoot,
          labels,
          heads,
          confEstimator,
          writeOutput);
      /*
            DependencyInstance parsedInstance;
            if (confEstimator != null) {
              double[] confidenceScores = confEstimator.estimateConfidence(instance);
              parsedInstance = new DependencyInstance(formsNoRoot, posNoRoot, labels, heads,
                      confidenceScores);
            } else {
              parsedInstance = new DependencyInstance(formsNoRoot, posNoRoot, labels, heads);
            }
            if (writeOutput) {
              pipe.outputInstance(parsedInstance);
            }
            if (allInstances != null) {
              allInstances.add(parsedInstance);
            }
      */
      // String line1 = ""; String line2 = ""; String line3 = ""; String line4 = "";
      // for(int j = 1; j < pos.length; j++) {
      // String[] trip = res[j-1].split("[\\|:]");
      // line1+= sent[j] + "\t"; line2 += pos[j] + "\t";
      // line4 += trip[0] + "\t"; line3 += pipe.types[Integer.parseInt(trip[2])] + "\t";
      // }
      // pred.write(line1.trim() + "\n" + line2.trim() + "\n"
      // + (pipe.labeled ? line3.trim() + "\n" : "")
      // + line4.trim() + "\n\n");

      instance = pipe.nextInstance();
    }
    pipe.close();

    if (writeOutput) {
      long end = System.currentTimeMillis();
      System.out.println("Took: " + (end - start));
    }
  }