• R/O
  • SSH
  • HTTPS

igo: コミット


コミットメタ情報

リビジョン103 (tree)
日時2011-06-18 09:24:58
作者phjgt

ログメッセージ

ラティス構造の構築方法を変更(Gomokuに合わせる)

変更サマリ

差分

--- trunk/igo/src/net/reduls/igo/dictionary/Unknown.java (revision 102)
+++ trunk/igo/src/net/reduls/igo/dictionary/Unknown.java (revision 103)
@@ -15,11 +15,11 @@
1515 spaceId = category.category(' ').id; // NOTE: ' 'の文字カテゴリはSPACEに予約されている
1616 }
1717
18- public void search(CharSequence text, int start, WordDic wdic, List<ViterbiNode> result) {
18+ public void search(CharSequence text, int start, WordDic wdic, WordDic.Callback fn) {
1919 final char ch = text.charAt(start);
2020 final CharCategory.Category ct = category.category(ch);
2121
22- if(result.isEmpty()==false && ct.invoke==false)
22+ if(fn.isEmpty()==false && ct.invoke==false)
2323 return;
2424
2525 final boolean isSpace = ct.id==spaceId;
@@ -26,7 +26,7 @@
2626 final int limit = Math.min(text.length(), ct.length+start);
2727 int i=start;
2828 for(; i < limit; i++) {
29- wdic.searchFromTrieId(ct.id, start, (i-start)+1, isSpace, result);
29+ wdic.searchFromTrieId(ct.id, start, (i-start)+1, isSpace, fn);
3030 if(i+1!=limit && category.isCompatible(ch, text.charAt(i+1)) == false)
3131 return;
3232 }
@@ -34,10 +34,10 @@
3434 if(ct.group && i < text.length()) {
3535 for(; i < text.length(); i++)
3636 if(category.isCompatible(ch, text.charAt(i)) == false) {
37- wdic.searchFromTrieId(ct.id, start, i-start, isSpace, result);
37+ wdic.searchFromTrieId(ct.id, start, i-start, isSpace, fn);
3838 return;
3939 }
40- wdic.searchFromTrieId(ct.id, start, text.length()-start, isSpace, result);
40+ wdic.searchFromTrieId(ct.id, start, text.length()-start, isSpace, fn);
4141 }
4242 }
4343 }
\ No newline at end of file
--- trunk/igo/src/net/reduls/igo/dictionary/WordDic.java (revision 102)
+++ trunk/igo/src/net/reduls/igo/dictionary/WordDic.java (revision 103)
@@ -35,14 +35,14 @@
3535 }
3636 }
3737
38- public void search(CharSequence text, int start, List<ViterbiNode> result) {
39- trie.eachCommonPrefix(text, start, new Collect(result));
38+ public void search(CharSequence text, int start, Callback fn) {
39+ trie.eachCommonPrefix(text, start, new WordDicCallbackCaller(fn));
4040 }
4141
42- public void searchFromTrieId(int trieId, int start, int wordLength, boolean isSpace, List<ViterbiNode> result) {
42+ public void searchFromTrieId(int trieId, int start, int wordLength, boolean isSpace, Callback fn) {
4343 final int end = indices[trieId+1];
4444 for(int i=indices[trieId]; i < end; i++)
45- result.add(new ViterbiNode(i, start, (short)wordLength, costs[i], leftIds[i], rightIds[i], isSpace));
45+ fn.call(new ViterbiNode(i, start, (short)wordLength, costs[i], leftIds[i], rightIds[i], isSpace));
4646 }
4747
4848 public String wordData(int wordId){
@@ -49,15 +49,16 @@
4949 return data.substring(dataOffsets[wordId], dataOffsets[wordId+1]);
5050 }
5151
52- private class Collect implements Searcher.Callback {
53- public final List<ViterbiNode> ms;
54- public Collect(List<ViterbiNode> result) { ms = result; }
52+ private class WordDicCallbackCaller implements Searcher.Callback {
53+ public WordDicCallbackCaller(Callback fn) { this.fn = fn; }
5554
5655 public void call(int start, int offset, int trieId) {
5756 final int end = indices[trieId+1];
5857 for(int i=indices[trieId]; i < end; i++)
59- ms.add(new ViterbiNode(i, start, (short)offset, costs[i], leftIds[i], rightIds[i], false));
58+ fn.call(new ViterbiNode(i, start, (short)offset, costs[i], leftIds[i], rightIds[i], false));
6059 }
60+
61+ private final Callback fn;
6162 }
6263
6364 public static interface Callback {
--- trunk/igo/src/net/reduls/igo/Tagger.java (revision 102)
+++ trunk/igo/src/net/reduls/igo/Tagger.java (revision 103)
@@ -87,28 +87,20 @@
8787 private ViterbiNode parseImpl(CharSequence text) {
8888 final int len = text.length();
8989 final ArrayList<ArrayList<ViterbiNode>> nodesAry = new ArrayList<ArrayList<ViterbiNode>>(len+1);
90- final ArrayList<ViterbiNode> perResult = new ArrayList<ViterbiNode>();
9190
9291 nodesAry.add(BOS_NODES);
9392 for(int i=1; i <= len; i++)
9493 nodesAry.add(new ArrayList<ViterbiNode>());
9594
96- for(int i=0; i < len; i++, perResult.clear()) {
97- if(nodesAry.get(i).isEmpty()==false) {
98- wdc.search(text, i, perResult); // 単語辞書から形態素を検索
99- unk.search(text, i, wdc, perResult); // 未知語辞書から形態素を検索
95+ MakeLattice fn = new MakeLattice(nodesAry);
96+ for(int i=0; i < len; i++) {
97+ if(nodesAry.get(i).isEmpty()==false) {
98+ fn.set(i);
99+ wdc.search(text, i, fn); // 単語辞書から形態素を検索
100+ unk.search(text, i, wdc, fn); // 未知語辞書から形態素を検索
101+ }
102+ }
100103
101- final ArrayList<ViterbiNode> prevs = nodesAry.get(i);
102- for(int j=0; j < perResult.size(); j++) {
103- final ViterbiNode vn = perResult.get(j);
104- if(vn.isSpace)
105- nodesAry.get(i+vn.length).addAll(prevs);
106- else
107- nodesAry.get(i+vn.length).add(setMincostNode(vn,prevs));
108- }
109- }
110- }
111-
112104 ViterbiNode cur = setMincostNode(ViterbiNode.makeBOSEOS(), nodesAry.get(len)).prev;
113105
114106 // reverse
旧リポジトリブラウザで表示