fmm.java

来自「中文分词开源项目JAVA?形姆执士聪钅縅AVA?形姆执士聪钅縅AVA中文分词」· Java 代码 · 共 44 行

JAVA
44
字号
/**
 * 
 */
package WordSegment;

import java.util.Vector;

/**
 * @author Truman
 *
 */
public class FMM extends SegStrategy {

	/* (non-Javadoc)
	 * @see WordSegment.SegStrategy#Segment(java.lang.String, WordSegment.Dictionary)
	 */
	//@Override
	public Vector Segment(String sentence, Dictionary dic) {
		int maxLength = dic.getMaxLength();	//the length of the longest word in the dictionary
		int pos = 0;
		int targetLength = maxLength;
		int restLength = sentence.length();
		Vector<String> seged = new Vector<String>();

		while (restLength > 0)
		{
			if (targetLength > restLength)
				targetLength = restLength;
			String tempStr = sentence.substring(pos, pos + targetLength);
			if (dic.checkWord(tempStr) || targetLength == 1)
			{
				seged.add(tempStr);
				pos += targetLength;
				targetLength = maxLength;
				restLength = sentence.length() - pos;
			}
			else
				targetLength--;
		}
		return seged;
	}

}

⌨️ 快捷键说明

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