⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tokensequenceparsefeaturestring.java

📁 这是一个matlab的java实现。里面有许多内容。请大家慢慢捉摸。
💻 JAVA
字号:
/* Copyright (C) 2002 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. *//**   @author Aron Culotta <a href="mailto:culotta@cs.umass.edu">culotta@cs.umass.edu</a>	 Convert the string in each field <code>Token.text</code> to a list	 of Strings (space delimited). Add each string as a feature to the	 token. If <code>realValued</code> is true, then treat the position	 in the list as the feature name and the value as a	 double. Otherwise, the feature name is the string itself and the	 value is 1.0.*/package edu.umass.cs.mallet.base.pipe;import edu.umass.cs.mallet.base.types.TokenSequence;import edu.umass.cs.mallet.base.types.Token;import edu.umass.cs.mallet.base.types.Instance;import edu.umass.cs.mallet.base.util.MalletLogger;import java.util.regex.Pattern;import java.util.regex.Matcher;import java.util.logging.*;import java.io.*;public class TokenSequenceParseFeatureString extends Pipe implements Serializable{	boolean realValued;		public TokenSequenceParseFeatureString (boolean _realValued) {		this.realValued = _realValued;			}	public Instance pipe (Instance carrier) {		TokenSequence ts = (TokenSequence) carrier.getData ();		for (int i=0; i < ts.size(); i++) {			Token t = ts.getToken (i);			String[] values = t.getText().split("\\s+");			for (int j=0; j < values.length; j++) {				if (realValued) 					t.setFeatureValue ("Feature#" + j, Double.parseDouble (values[j]));				else					t.setFeatureValue (values[j], 1.0);								}		}		carrier.setData (ts);		return carrier;	}	// Serialization 		private static final long serialVersionUID = 1;	private static final int CURRENT_SERIAL_VERSION = 0;		private void writeObject (ObjectOutputStream out) throws IOException {		out.writeInt (CURRENT_SERIAL_VERSION);		out.writeBoolean (realValued);	}		private void readObject (ObjectInputStream in) throws IOException, ClassNotFoundException {		int version = in.readInt ();		realValued = in.readBoolean ();	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -