private void addSegs(List segs, Sequence output) {
    int segtype = -1;
    int startidx = -1;

    for (int j = 0; j < output.size(); j++) {
      //      System.out.println("addSegs j="+j);
      Object tag = output.get(j);
      segtype = ArrayUtils.indexOf(segmentTags, tag.toString());

      if (segtype > -1) {
        //        System.out.println("...found segment "+tag);
        // A new segment is starting
        startidx = j;
        while (j < output.size() - 1) {
          //          System.out.println("...inner addSegs j="+j);
          j++;
          Object nextTag = output.get(j);
          if (!nextTag.equals(tag)) {
            j--;
            segs.add(new Segment(segtype, startidx, j));
            segtype = startidx = -1;
            break;
          }
        }
      }
    }

    // Handle end-of-sequence
    if (startidx > -1) {
      segs.add(new Segment(segtype, startidx, output.size() - 1));
    }
  }
Ejemplo n.º 2
0
    @Override
    @SuppressWarnings("unchecked")
    public <E> E[] toArray(E[] a) {

      final long cursor = buffer.getCursor();
      long s = pollCursor.get() + 1L;
      final E[] array;
      final int n = (int) (cursor - s);

      if (n == 0) {
        return a;
      }

      if (a.length < n) {
        array = (E[]) new Object[n];
      } else {
        array = a;
      }

      int i = 0;
      while (s < cursor) {
        array[i++] = (E) buffer.get(cursor).value;
        s++;
      }
      return array;
    }
 @Override
 public void publish(final long sequence, final Sequence upperCursor) {
   final long expectedSequence = sequence - 1L;
   while (expectedSequence != upperCursor.get()) {
     // busy spin
   }
   upperCursor.set(sequence);
 }
 @Override
 public void publishInterruptibly(final long sequence, final Sequence upperCursor)
     throws InterruptedException {
   final long expectedSequence = sequence - 1L;
   while (expectedSequence != upperCursor.get()) {
     if (Thread.interrupted()) throw new InterruptedException();
     // busy spin
   }
   upperCursor.set(sequence);
 }
Ejemplo n.º 5
0
    @Override
    public T peek() {
      long current = buffer.getCursor();
      long cachedSequence = pollCursor.get() + 1L;

      if (cachedSequence <= current) {
        return buffer.get(cachedSequence).value;
      }
      return null;
    }
Ejemplo n.º 6
0
    @Override
    public T poll() {
      long current = buffer.getCursor();
      long cachedSequence = pollCursor.get() + 1L;

      if (cachedSequence <= current) {
        T v = buffer.get(cachedSequence).value;
        if (v != null) {
          pollCursor.set(cachedSequence);
        }
        return v;
      }
      return null;
    }
  public Instance pipe(Instance carrier) {
    Sequence data = (Sequence) carrier.getData();
    Sequence target = (Sequence) carrier.getTarget();

    if (data.size() != target.size())
      throw new IllegalArgumentException(
          "Trying to print into SimpleTagger format, where data and target lengths do not match\n"
              + "data.length = "
              + data.size()
              + ", target.length = "
              + target.size());

    int N = data.size();

    if (data instanceof TokenSequence) {
      throw new UnsupportedOperationException("Not yet implemented.");
    } else if (data instanceof FeatureVectorSequence) {

      FeatureVectorSequence fvs = (FeatureVectorSequence) data;
      Alphabet dict = (fvs.size() > 0) ? fvs.getFeatureVector(0).getAlphabet() : null;

      for (int i = 0; i < N; i++) {
        Object label = target.get(i);
        writer.print(label);

        FeatureVector fv = fvs.getFeatureVector(i);
        for (int loc = 0; loc < fv.numLocations(); loc++) {
          writer.print(' ');
          String fname = dict.lookupObject(fv.indexAtLocation(loc)).toString();
          double value = fv.valueAtLocation(loc);
          // if (!Maths.almostEquals(value, 1.0)) {
          //    throw new IllegalArgumentException ("Printing to SimpleTagger format: FeatureVector
          // not binary at time slice "+i+" fv:"+fv);
          // }
          writer.print(fname + String.valueOf(value));
        }
        writer.println();
      }
    } else {
      throw new IllegalArgumentException("Don't know how to print data of type " + data);
    }

    writer.println();
    // writer.print(getDataAlphabet());

    return carrier;
  }
 public EntityConfidence(double conf, boolean corr, Sequence input, int start, int end) {
   this.confidence = conf;
   this.correct = corr;
   StringBuffer buff = new StringBuffer();
   if (input != null) {
     for (int j = start; j <= end; j++) {
       FeatureVector fv = (FeatureVector) input.get(j);
       for (int k = 0; k < fv.numLocations(); k++) {
         String featureName = fv.getAlphabet().lookupObject(fv.indexAtLocation(k)).toString();
         if (featureName.startsWith("W=") && featureName.indexOf("@") == -1) {
           buff.append(featureName.substring(featureName.indexOf('=') + 1) + " ");
         }
       }
     }
   }
   this.entity = buff.toString();
 }
Ejemplo n.º 9
0
 @Override
 public boolean isEmpty() {
   return buffer.getCursor() == pollCursor.get();
 }
Ejemplo n.º 10
0
 @Override
 public int size() {
   return (int) (buffer.getCursor() - pollCursor.get());
 }