Ejemplo n.º 1
0
  public static InstanceList copy(InstanceList instances) {
    InstanceList ret = (InstanceList) instances.clone();
    // LabelAlphabet labelDict = (LabelAlphabet) ret.getTargetAlphabet();
    Alphabet featDict = ret.getDataAlphabet();

    for (int i = 0; i < ret.size(); i++) {
      Instance instance = ret.get(i);
      Instance clone = (Instance) instance.clone();
      FeatureVector fv = (FeatureVector) clone.getData();

      int[] indices = fv.getIndices();
      double[] values = fv.getValues();

      int[] newIndices = new int[indices.length];
      System.arraycopy(indices, 0, newIndices, 0, indices.length);

      double[] newValues = new double[indices.length];
      System.arraycopy(values, 0, newValues, 0, indices.length);

      FeatureVector newFv = new FeatureVector(featDict, newIndices, newValues);
      Instance newInstance =
          new Instance(newFv, instance.getTarget(), instance.getName(), instance.getSource());
      ret.set(i, newInstance);
    }

    return ret;
  }
 protected List<Double> serializeFv(FeatureVector fv) {
   List<Double> features = new ArrayList<>();
   int numLocations = fv.numLocations();
   int[] indices = fv.getIndices();
   for (int index = 0; index < numLocations; index++) {
     int featureIndex = indices[index];
     double value = fv.value(featureIndex);
     features.add(value);
   }
   return features;
 }
Ejemplo n.º 3
0
 public void addToken(FeatureVector fv) {
   int[] indices = fv.getIndices();
   Alphabet dictionary = fv.getAlphabet();
   int indicesLength = fv.numLocations();
   for (int i = 0; i < indicesLength; i++) {
     String key = dictionary.lookupObject(indices[i]).toString();
     // log.info( key );
     if (!contextOnly
         || (contextOnly
             && (key.endsWith("/+1")
                 || key.endsWith("/-1")
                 || key.endsWith("/-2")
                 || key.endsWith("/+2")))) {
       map.increment(key);
     }
   }
 }