~loic-grobol/cteslo/trunk

« back to all changes in this revision

Viewing changes to cteslo/external_tools/lgtools/src/fr/upemlv/lgtools/wfst/Node.java

  • Committer: Loïc Grobol
  • Date: 2012-09-11 20:48:16 UTC
  • Revision ID: loic.grobol@gmail.com-20120911204816-fvl8me0w3lsb0cnf
makefiles for lgtools

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package fr.upemlv.lgtools.wfst;
 
2
 
 
3
import java.util.ArrayList;
 
4
import java.util.List;
 
5
 
 
6
import fr.upemlv.lgtools.tagging.impl.Utils;
 
7
 
 
8
public class Node {
 
9
        final private String word;
 
10
        final private String tag;
 
11
        final private double cost;
 
12
        private double alpha = 0.0;
 
13
        final private int position;
 
14
        private double bestCost;
 
15
        private Node bestPrev;
 
16
        private final List<Arc> arcs = new ArrayList<Arc>();
 
17
        private final List<Arc> rarcs = new ArrayList<Arc>();
 
18
        
 
19
        public Node(String tag,String word,int position,double cost) {
 
20
                this.word = word;
 
21
                this.tag = tag;
 
22
            this.cost = cost;
 
23
            this.position = position;
 
24
            this.bestCost = Double.MIN_VALUE;
 
25
            this.bestPrev = null;
 
26
        }
 
27
        
 
28
        public void addArc(Arc a){
 
29
                arcs.add(a);
 
30
                a.getDest().rarcs.add(new Arc(a.getDest(),a.getSrc(),a.getCost()));
 
31
        }
 
32
 
 
33
                
 
34
        public List<Arc> getArcs() {
 
35
                return arcs;
 
36
        }
 
37
 
 
38
        public List<Arc> getReverseArcs() {
 
39
                return rarcs;
 
40
        }
 
41
        
 
42
        public double getBestCost() {
 
43
                return bestCost;
 
44
        }
 
45
 
 
46
        public void setBestCost(double bestCost) {
 
47
                this.bestCost = bestCost;
 
48
        }
 
49
 
 
50
        public Node getBestPrev() {
 
51
                return bestPrev;
 
52
        }
 
53
 
 
54
        public void setBestPrev(Node bestPrev) {
 
55
                this.bestPrev = bestPrev;
 
56
        }
 
57
 
 
58
        public String getWord() {
 
59
                return word;
 
60
        }
 
61
 
 
62
        public String getTag() {
 
63
                return tag;
 
64
        }
 
65
 
 
66
        public double getCost() {
 
67
                return cost;
 
68
        }
 
69
 
 
70
        public int getPosition() {
 
71
                return position;
 
72
        }
 
73
        
 
74
        public double getAlpha(){
 
75
                return alpha;
 
76
        }
 
77
        
 
78
        public void calcAlpha(){
 
79
                          alpha = 0.0;
 
80
                          boolean flg = true;
 
81
                          for(Arc a:rarcs){
 
82
                                  Node n = a.getSrc();
 
83
                              alpha = Utils.logsumexp(alpha,
 
84
                                              n.getCost() +n.getAlpha(),
 
85
                                              flg);
 
86
                              if(flg){
 
87
                                  flg = false;
 
88
                              }
 
89
                          }
 
90
                          alpha+=cost;
 
91
        }
 
92
        
 
93
}