bmm.java
来自「java版的分词程序」· Java 代码 · 共 43 行
JAVA
43 行
/**
*
*/
import java.util.Vector;
/**
* @author Truman
*
*/
public class BMM 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 negPos = sentence.length();
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(negPos - targetLength, negPos);
if (dic.checkWord(tempStr) || targetLength == 1)
{
seged.add(0, tempStr);
negPos -= targetLength;
restLength -= targetLength;
targetLength = maxLength;
}
else
targetLength--;
}
return seged;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?