All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cc.mallet.pipe.tsf.SequencePrintingPipe Maven / Gradle / Ivy

Go to download

MALLET is a Java-based package for statistical natural language processing, document classification, clustering, topic modeling, information extraction, and other machine learning applications to text.

The newest version!
/* Copyright (C) 2003 Univ. of Massachusetts Amherst, Computer Science Dept.
   This file is part of "MALLET" (MAchine Learning for LanguagE Toolkit).
   http://www.cs.umass.edu/~mccallum/mallet
   This software is provided under the terms of the Common Public License,
   version 1.0, as published by http://www.opensource.org.  For further
   information, see the file `LICENSE' included with this distribution. */
package cc.mallet.pipe.tsf;


import java.io.PrintWriter;

import cc.mallet.pipe.Pipe;
import cc.mallet.types.*;
import cc.mallet.util.Maths;
import cc.mallet.util.PropertyList;

/**
 * Created: Jul 6, 2005
 *
 * @author  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);
        }
        writer.println ();
      }
    } else {
      throw new IllegalArgumentException ("Don't know how to print data of type "+data);
    }

    writer.println ();

    return carrier;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy