Java Word break analysis

简介: Created by Wang, Jerry, last modified on Dec 18, 2015

Created by Wang, Jerry, last modified on Dec 18, 2015

in getAllPossibleSentences, s: catsanddog pos: 9

Sub string: catsanddog

逐一遍历字典里的word,检查当前子串是否以word结尾。

Sub String ends with word in Dict!: dog - 字典里找到一个匹配。

current position: 9 word length: 3

first Seg end: 6 找到匹配后准备开始递归。

RECURSIVELY call, new position: 6

in getAllPossibleSentences, s: catsanddog pos: 6 - 传s还是传整个字符串进去,只是position变成前6个。此时执行流不会返回,仍然是在当前dog匹配的大前提下。

Sub string: catsand

Sub String ends with word in Dict!: sand

current position: 6 word length: 4

first Seg end: 2

RECURSIVELY call, new position: 2 又找到一个匹配,再递归。

in getAllPossibleSentences, s: catsanddog pos: 2

Sub string: cat

Sub String ends with word in Dict!: cat - 再次找到匹配 dog->sand->cat

current position: 2 word length: 3

first Seg end: -1

RECURSIVELY call, new position: -1

in getAllPossibleSentences, s: catsanddog pos: -1

pos is -1, we can return now and have a rest! return result size: 1 - 这个是默认的space

result from getAllPossible with position: -1 - 从最内层的递归返回了一层。

result list’s item is STRING.space, so I directly insert end word to solution list: cat - 将最内层的cat结果加到list里。

Possible solution FOUND:!cat

insert map with position: 2 possible list: 1

[-1, “”]

[2, cat]

result from getAllPossible with position: 2

item in result list: cat - 从前一个递归insert的。Current word in dic: sand - 当前递归frame的单词。

Possible solution FOUND:!cat sand

Sub String ends with word in Dict!: and (Sub string: catsand)

current position: 6 word length: 3

first Seg end: 3

RECURSIVELY call, new position: 3

in getAllPossibleSentences, s: catsanddog pos: 3

Sub string: cats

Sub String ends with word in Dict!: cats

current position: 3 word length: 4

first Seg end: -1

RECURSIVELY call, new position: -1

in getAllPossibleSentences, s: catsanddog pos: -1

pos is -1, we can return now and have a rest! return result size: 1

result from getAllPossible with position: -1

item in result list: Current word in dic: cats

result list’s item is STRING.space, so I directly insert end word to solution list: cats

Possible solution FOUND:!cats

insert map with position: 3 possible list: 1

result from getAllPossible with position: 3

item in result list: catsCurrent word in dic: and

Possible solution FOUND:!cats and

insert map with position: 6 possible list: 2

result from getAllPossible with position: 6

item in result list: cat sandCurrent word in dic: dog

Possible solution FOUND:!cat sand dog

item in result list: cats andCurrent word in dic: dog

Possible solution FOUND:!cats and dog

insert map with position: 9 possible list: 2

result: cat sand dog

result: cats and dog

image.pngimage.pngimage.pngimage.pngimage.pngimage.pngimage.pngimage.pngimage.pngimage.pngimage.pngimage.pngimage.png

image.png








image.png

相关文章
|
11天前
|
Java
java中break标记的使用
java中break标记的使用
|
6月前
|
Java 数据安全/隐私保护
使用java操作word
使用java操作word
60 0
|
2月前
|
Java
Java中break和continue语句的区别
Java中break和continue语句的区别
14 0
|
3月前
|
Java Linux 数据安全/隐私保护
Java【代码 16】将word、excel文件转换为pdf格式和将pdf文档转换为image格式工具类分享(Gitee源码)aspose转换中文乱码问题处理
【2月更文挑战第3天】Java 将word、excel文件转换为pdf格式和将pdf文档转换为image格式工具类分享(Gitee源码)aspose转换中文乱码问题处理
122 0
|
3月前
|
Java 程序员 数据安全/隐私保护
分享一个word转pdf的工具类Aspose[java]
分享一个word转pdf的工具类Aspose[java]
52 0
|
3月前
|
存储 Java 容器
Java break、continue 详解与数组深入解析:单维数组和多维数组详细教程
Java Break: break 语句用于跳出循环或 switch 语句。 在循环中使用 break 语句可以立即终止循环,并继续执行循环后面的代码。 在 switch 语句中使用 break 语句可以跳出当前 case,并继续执行下一个 case。
45 1
|
3月前
|
Java
Java中把word转换成图片
Java中把word转换成图片
93 0
|
9月前
|
Java
Java 中 return,continue,break的区别
Java 中 return,continue,break的区别
50 0
|
6月前
|
Java Apache
java word转html 报错org/apache/poi/xwpf/usermodel/IRunBody
java word转html 报错org/apache/poi/xwpf/usermodel/IRunBody
|
7月前
|
前端开发 Java 关系型数据库
【Java用法】使用Java导出word文档的解决方案(适用于从服务器上下载到本地电脑)
【Java用法】使用Java导出word文档的解决方案(适用于从服务器上下载到本地电脑)
210 0