File size: 3,005 Bytes
6f3ebfa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package org.maltparser.parser.transition;

import java.util.SortedMap;
import java.util.TreeMap;

import org.maltparser.core.exception.MaltChainedException;
import org.maltparser.core.helper.HashMap;
import org.maltparser.core.symbol.Table;
import org.maltparser.parser.history.container.DecisionPropertyTable;
/**

*

* @author Johan Hall

**/
public class TransitionTable implements Table, DecisionPropertyTable {
	private final String name;
	private final SortedMap<Integer,Transition> code2transitionMap;
	private final HashMap<String,Transition> symbol2transitionMap;
	private final HashMap<Transition,TransitionTable> childrenTables;
	
	public TransitionTable(String tableName) {
		this.name = tableName;
		this.code2transitionMap = new TreeMap<Integer,Transition>();
		this.symbol2transitionMap = new HashMap<String,Transition>();
		this.childrenTables = new HashMap<Transition,TransitionTable>();
	}
	
	public void addTransition(int code, String symbol, boolean labeled, TransitionTable childrenTable) {
		final Transition transition = new Transition(code, symbol, labeled); 
		code2transitionMap.put(code,transition);
		symbol2transitionMap.put(symbol, transition);
		childrenTables.put(transition, childrenTable);
	}
	
	public boolean continueWithNextDecision(int code) throws MaltChainedException {
		if (code2transitionMap.containsKey(code)) {
			return code2transitionMap.get(code).isLabeled();
		}
		return true;
	}
	
	public boolean continueWithNextDecision(String symbol) throws MaltChainedException {
		if (symbol2transitionMap.containsKey(symbol)) {
			return symbol2transitionMap.get(symbol).isLabeled();
		}
		return true;
	}
	
	public Table getTableForNextDecision(int code) throws MaltChainedException {
		if (code2transitionMap.containsKey(code)) {
			return childrenTables.get(code2transitionMap.get(code));
		}
		return null;
	}
	
	public Table getTableForNextDecision(String symbol) throws MaltChainedException {
		if (symbol2transitionMap.containsKey(symbol)) {
			return childrenTables.get(symbol2transitionMap.get(symbol));
		}
		return null;
	}
	
	public Transition getTransition(String symbol) {
		return symbol2transitionMap.get(symbol);
	}
	
	public Transition getTransition(int code) {
		return code2transitionMap.get(code);
	}
	
	public int addSymbol(String symbol) throws MaltChainedException {
		return -1;
	}

	public String getName() {
		return name;
	}

	public String getSymbolCodeToString(int code) throws MaltChainedException {
		if (code < 0) {
			return null;
		}
		return code2transitionMap.get(code).getSymbol();
	}

	public int getSymbolStringToCode(String symbol) throws MaltChainedException {
		if (symbol == null) {
			return -1;
		}
		return symbol2transitionMap.get(symbol).getCode();
	}
	
	public double getSymbolStringToValue(String symbol) throws MaltChainedException {
		return 1.0;
	}
	
	public int size() {
		return code2transitionMap.size();
	}

}