Java Word break analysis
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
總結
以上是生活随笔為你收集整理的Java Word break analysis的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java初始化陷阱
- 下一篇: 《我的世界》定时炸弹的制作方法 爆破鬼才