• R/O
  • SSH
  • HTTPS

igo: コミット


コミットメタ情報

リビジョン102 (tree)
日時2011-06-18 09:06:05
作者phjgt

ログメッセージ

単語コスト算出箇所のコードを若干変更(Gomokuに合わせる)

変更サマリ

差分

--- trunk/igo/src/net/reduls/igo/dictionary/ViterbiNode.java (revision 101)
+++ trunk/igo/src/net/reduls/igo/dictionary/ViterbiNode.java (revision 102)
@@ -4,7 +4,7 @@
44 * Viterbiアルゴリズムで使用されるノード
55 */
66 public final class ViterbiNode {
7- public int cost = 0; // 始点からノードまでの総コスト
7+ public int cost; // 始点からノードまでの総コスト
88 public ViterbiNode prev = null; // コスト最小の前方のノードへのリンク
99
1010 public final int wordId; // 単語ID
@@ -15,16 +15,17 @@
1515
1616 public final boolean isSpace; // 形態素の文字種(文字カテゴリ)が空白文字かどうか
1717
18- public ViterbiNode(int wid, int beg, short len, short l, short r, boolean space) {
18+ public ViterbiNode(int wid, int beg, short len, short wordCost, short l, short r, boolean space) {
1919 wordId = wid;
2020 leftId = l;
2121 rightId =r;
2222 length = len;
23+ cost = wordCost;
2324 isSpace = space;
2425 start = beg;
2526 }
2627
2728 public static ViterbiNode makeBOSEOS() {
28- return new ViterbiNode(0,0,(short)0,(short)0,(short)0,false);
29+ return new ViterbiNode(0,0,(short)0,(short)0,(short)0,(short)0,false);
2930 }
3031 }
\ No newline at end of file
--- trunk/igo/src/net/reduls/igo/dictionary/WordDic.java (revision 101)
+++ trunk/igo/src/net/reduls/igo/dictionary/WordDic.java (revision 102)
@@ -35,8 +35,6 @@
3535 }
3636 }
3737
38- public short cost(int wordId) { return costs[wordId]; }
39-
4038 public void search(CharSequence text, int start, List<ViterbiNode> result) {
4139 trie.eachCommonPrefix(text, start, new Collect(result));
4240 }
@@ -44,7 +42,7 @@
4442 public void searchFromTrieId(int trieId, int start, int wordLength, boolean isSpace, List<ViterbiNode> result) {
4543 final int end = indices[trieId+1];
4644 for(int i=indices[trieId]; i < end; i++)
47- result.add(new ViterbiNode(i, start, (short)wordLength, leftIds[i], rightIds[i], isSpace));
45+ result.add(new ViterbiNode(i, start, (short)wordLength, costs[i], leftIds[i], rightIds[i], isSpace));
4846 }
4947
5048 public String wordData(int wordId){
@@ -58,7 +56,12 @@
5856 public void call(int start, int offset, int trieId) {
5957 final int end = indices[trieId+1];
6058 for(int i=indices[trieId]; i < end; i++)
61- ms.add(new ViterbiNode(i, start, (short)offset, leftIds[i], rightIds[i], false));
59+ ms.add(new ViterbiNode(i, start, (short)offset, costs[i], leftIds[i], rightIds[i], false));
6260 }
6361 }
62+
63+ public static interface Callback {
64+ public void call(ViterbiNode vn);
65+ public boolean isEmpty();
66+ }
6467 }
\ No newline at end of file
--- trunk/igo/src/net/reduls/igo/Tagger.java (revision 101)
+++ trunk/igo/src/net/reduls/igo/Tagger.java (revision 102)
@@ -124,17 +124,44 @@
124124
125125 private ViterbiNode setMincostNode(ViterbiNode vn, ArrayList<ViterbiNode> prevs) {
126126 final ViterbiNode f = vn.prev = prevs.get(0);
127- vn.cost = f.cost + mtx.linkCost(f.rightId, vn.leftId);
127+ int minCost = f.cost + mtx.linkCost(f.rightId, vn.leftId);
128128
129129 for(int i=1; i < prevs.size(); i++) {
130130 final ViterbiNode p = prevs.get(i);
131131 final int cost = p.cost + mtx.linkCost(p.rightId, vn.leftId);
132- if(cost < vn.cost) {
133- vn.cost = cost;
132+ if(cost < minCost) {
133+ minCost = cost;
134134 vn.prev = p;
135135 }
136136 }
137- vn.cost += wdc.cost(vn.wordId);
137+ vn.cost += minCost;
138138 return vn;
139139 }
140+
141+ private final class MakeLattice implements WordDic.Callback {
142+ private final ArrayList<ArrayList<ViterbiNode>> nodesAry;
143+ private int i;
144+ private ArrayList<ViterbiNode> prevs;
145+ private boolean empty=true;
146+
147+ public MakeLattice(ArrayList<ArrayList<ViterbiNode>> nodesAry) {
148+ this.nodesAry = nodesAry;
149+ }
150+
151+ public void set(int i) {
152+ this.i = i;
153+ prevs = nodesAry.get(i);
154+ empty = true;
155+ }
156+
157+ public void call(ViterbiNode vn) {
158+ empty=false;
159+ if(vn.isSpace)
160+ nodesAry.get(i+vn.length).addAll(prevs);
161+ else
162+ nodesAry.get(i+vn.length).add(setMincostNode(vn, prevs));
163+ }
164+
165+ public boolean isEmpty() { return empty; }
166+ }
140167 }
--- trunk/igo/build.xml (revision 101)
+++ trunk/igo/build.xml (revision 102)
@@ -1,7 +1,7 @@
11 <?xml version="1.0" encoding="UTF-8"?>
22
33 <project name="igo" default="jar" basedir=".">
4- <property name="version" value="0.4.2" />
4+ <property name="version" value="0.4.3" />
55 <property name="src.dir" value="src"/>
66 <property name="classes.dir" value="classes"/>
77 <property name="javadoc.dir" value="docs"/>
旧リポジトリブラウザで表示