本屌已经在创业公司打拼了四年,随着公司的发展,个人的技术局限性越来越明显,接下来打算重筑算法功底,好好的充充电,为下次突破做准备
分词算法是几年前刚开始接触搜索时接触到,打算先从这里切入,下班前整理了一下思路,小写了一番,记录如下,储备之:
分词有单字分词、字典分词、统计分词等,这里用最常用的字典分词
先定义一个词典,并初始化之:
private static Set<String> dict = new HashSet<String>();
static {
dict.add("百度");
dict.add("平台");
dict.add("架构");
dict.add("分享");
}
接下来就要用这个词典对给出的句子进行分词:
public static void main(String[] args) {
String str = "百度前端基础平台与架构分享";
fwdMax(str);
fwdMin_2(str);
backMax(str);
backMin_2(str);
}
1) 正向最大
private static void fwdMax(String str) {// 正向最大
int len = str.length();
int start = 0;
int end = len;
while (start < end) {
String word = str.substring(start, end);
// System.out.println(word);
if (dict.contains(word) || word.length() == 1) {
System.out.print(wo

博主分享了在创业公司工作四年后的感悟,决定重筑算法基础,从分词算法开始。文章介绍了字典分词方法,包括词典初始化和不同分词策略,如反向最大、反向最小,指出这些算法在处理长句子时效率不高,通常需要结合使用以消除歧义和提高效率。
最低0.47元/天 解锁文章
1199

被折叠的 条评论
为什么被折叠?



