Beispiel #1
0
 public String message() {
   return msg.text();
 }
Beispiel #2
0
 public void setMessage(Quotation q) {
   msg = q;
   who.setText(q.author() + " " + q.year());
   txt.setText(q.text());
   ref.setText(q.reference());
 }
  /**
   * Parse the given string and load an example.
   *
   * @param buff a string that contains an example.
   * @return <code>true</code> if the given string is a valid example.
   * @throws DatasetException if there is some format problem with the given string.
   */
  public boolean parseExample(
      Collection<PQInput2> exampleInputs, Collection<PQOutput2> exampleOutputs, String buff)
      throws DatasetException {
    // Split quotations.
    String quotationsInput[] = buff.split("§");
    if (quotationsInput.length == 0) return false;

    // First field: document ID.
    if (quotationsInput[0].trim().length() == 0) return false;
    String docId = quotationsInput[0];

    LinkedList<LinkedList<LinkedList<Integer>>> exampleInputAsList =
        new LinkedList<LinkedList<LinkedList<Integer>>>();
    LinkedList<Integer> exampleOutputAsList = new LinkedList<Integer>();
    LinkedList<Quotation> quotationsAsList = new LinkedList<Quotation>();

    // Walk into the document quotations.
    for (int idxQuote = 1; idxQuote < quotationsInput.length; idxQuote++) {
      // Split candidate coreferences of the given quotation.
      String coreferences[] = quotationsInput[idxQuote].split("\\t");

      if (coreferences.length == 0) return false;

      // First field: quotation start index, quotation end index,
      // right coreference index.
      String firstField[] = coreferences[0].split("[ ]");
      if (firstField.length != 3) return false;

      // Quotation start index, quotation end index.
      if ((firstField[0].trim().length() == 0) || (firstField[1].trim().length() == 0))
        return false;

      Quotation quotation = new Quotation(coreferences.length - 1);
      quotation.setQuotationIndex(Integer.parseInt(firstField[0]), Integer.parseInt(firstField[1]));

      // Right coreference index.
      if (firstField[2].trim().length() == 0) return false;
      int rightCoref = Integer.parseInt(firstField[2]) + 1;

      // Walk into the coreference feature list.
      LinkedList<LinkedList<Integer>> corefFeatureList = new LinkedList<LinkedList<Integer>>();
      for (int idxCoref = 1; idxCoref < coreferences.length; ++idxCoref) {
        String coreference = coreferences[idxCoref];

        // Parse the given coreference features.
        String[] features = coreference.split("[ ]");
        if (firstField.length < 2) return false;

        // First field: coreference start index, coreference end index.
        if ((features[0].trim().length() == 0) || (features[1].trim().length() == 0)) return false;

        quotation.setCoreferenceIndex(
            idxCoref - 1, Integer.parseInt(features[0]), Integer.parseInt(features[1]));

        // Encode the features.
        LinkedList<Integer> featureList = new LinkedList<Integer>();
        for (int idxFtr = 2; idxFtr < features.length; ++idxFtr) {
          int code = featureEncoding.put(features[idxFtr]);
          if (code >= 0) featureList.add(code);
        }
        corefFeatureList.add(featureList);
      }

      // Example input.
      exampleInputAsList.add(corefFeatureList);

      // Example output.
      exampleOutputAsList.add(rightCoref);

      // Quotation index information.
      quotationsAsList.add(quotation);
    }

    // Store the loaded example.
    if (training) {
      /*
       * Training examples must store internally their indexes in the
       * array of training examples.
       */
      exampleInputs.add(new PQInput2(docId, exampleInputAsList, quotationsAsList));
      exampleOutputs.add(new PQOutput2(exampleOutputAsList));
    } else {
      exampleInputs.add(new PQInput2(docId, exampleInputAsList, quotationsAsList));
      exampleOutputs.add(new PQOutput2(exampleOutputAsList));
    }
    return true;
  }