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

cc.mallet.pipe.TargetStringToFeatures 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!
package cc.mallet.pipe;

import cc.mallet.types.*;
import java.io.Serializable;
import java.util.Arrays;

public class TargetStringToFeatures extends Pipe implements Serializable {
	public TargetStringToFeatures () {
		super(null, new Alphabet());
	}

	public Instance pipe(Instance carrier) {
		if (! (carrier.getTarget() instanceof String)) {
			throw new IllegalArgumentException("Target must be of type String");
		}

		String featuresLine = (String) carrier.getTarget();

		String[] features = featuresLine.split(",?\\s+");

		double[] values = new double[ features.length ];
		Arrays.fill(values, 1.0);

		for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy