Пример #1
0
 public final void serializeURIs(Object array, XMLSerializer target) throws SAXException {
   if (xducer.useNamespace()) {
     int len = Array.getLength(array);
     for (int i = 0; i < len; i++) {
       Object item = Array.get(array, i);
       try {
         xducer.declareNamespace(item, target);
       } catch (AccessorException e) {
         target.reportError("arrayItem", e);
       }
     }
   }
 }
Пример #2
0
        @Override
        public void text(UnmarshallingContext.State state, CharSequence text) throws SAXException {
          List<Object> r = new FinalArrayList<Object>();

          int idx = 0;
          int len = text.length();

          while (true) {
            int p = idx;
            while (p < len && !WhiteSpaceProcessor.isWhiteSpace(text.charAt(p))) p++;

            CharSequence token = text.subSequence(idx, p);
            if (!token.equals(""))
              try {
                r.add(xducer.parse(token));
              } catch (AccessorException e) {
                handleGenericException(e, true);
                continue; // move on to next
              }

            if (p == len) break; // done

            while (p < len && WhiteSpaceProcessor.isWhiteSpace(text.charAt(p))) p++;
            if (p == len) break; // done

            idx = p;
          }

          state.target = toArray(r);
        }
Пример #3
0
 public void serializeBody(Object array, XMLSerializer target)
     throws SAXException, IOException, XMLStreamException {
   int len = Array.getLength(array);
   for (int i = 0; i < len; i++) {
     Object item = Array.get(array, i);
     try {
       xducer.writeText(target, item, "arrayItem");
     } catch (AccessorException e) {
       target.reportError("arrayItem", e);
     }
   }
 }
Пример #4
0
  /**
   * Apply a transducer to an input sequence to produce the k highest-scoring output sequences.
   *
   * @param model the <code>Transducer</code>
   * @param input the input sequence
   * @param k the number of answers to return
   * @return array of the k highest-scoring output sequences
   */
  public static Sequence[] apply(Transducer model, Sequence input, int k) {
    Sequence[] answers;
    if (k == 1) {
      answers = new Sequence[1];
      answers[0] = model.transduce(input);
    } else {
      MaxLatticeDefault lattice =
          new MaxLatticeDefault(model, input, null, cacheSizeOption.value());

      answers = lattice.bestOutputSequences(k).toArray(new Sequence[0]);
    }
    return answers;
  }