File size: 2,851 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
package org.maltparser.parser;

import org.maltparser.core.exception.MaltChainedException;
import org.maltparser.core.symbol.SymbolTableHandler;
import org.maltparser.core.syntaxgraph.DependencyStructure;
import org.maltparser.parser.history.GuideUserHistory;
import org.maltparser.parser.history.History;
import org.maltparser.parser.history.HistoryList;
import org.maltparser.parser.history.HistoryStructure;
import org.maltparser.parser.history.action.GuideUserAction;
/**

 * @author Johan Hall

 *

 */
public class ParserState {
	private final AbstractParserFactory factory;
	private final GuideUserHistory history;
	private final TransitionSystem transitionSystem;
	private final HistoryStructure historyStructure;
	private final ParserConfiguration config;
	
	public ParserState(DependencyParserConfig manager, SymbolTableHandler symbolTableHandler, AbstractParserFactory factory) throws MaltChainedException {
		this.factory = factory;
		this.historyStructure = new HistoryList();
		this.transitionSystem = factory.makeTransitionSystem();
		String decisionSettings = manager.getOptionValue("guide", "decision_settings").toString().trim();
		getTransitionSystem().initTableHandlers(decisionSettings, symbolTableHandler);
		int kBestSize = ((Integer)manager.getOptionValue("guide", "kbest")).intValue();
		String classitem_separator = manager.getOptionValue("guide", "classitem_separator").toString();
		this.history = new History(decisionSettings, classitem_separator, getTransitionSystem().getTableHandlers(), kBestSize);
		getTransitionSystem().initTransitionSystem(history);
		this.config = factory.makeParserConfiguration();
	}
	
	
	public void clear() throws MaltChainedException {
		history.clear();
		historyStructure.clear();
	}
	
	public GuideUserHistory getHistory() {
		return history;
	}

	public TransitionSystem getTransitionSystem() {
		return transitionSystem;
	}
	
	public HistoryStructure getHistoryStructure() {
		return historyStructure;
	}
	
	public void initialize(DependencyStructure dependencyStructure) throws MaltChainedException {
		config.clear();
		config.setDependencyGraph(dependencyStructure);
		config.initialize();
	}
	
	public boolean isTerminalState() throws MaltChainedException {
		return config.isTerminalState();
	}
	
	public boolean permissible(GuideUserAction currentAction) throws MaltChainedException {
		return transitionSystem.permissible(currentAction, config); 
	}
	
	public void apply(GuideUserAction currentAction) throws MaltChainedException {
		transitionSystem.apply(currentAction, config);
	}
	
	public int nConfigurations() throws MaltChainedException {
		return 1;
	}
	
	public ParserConfiguration getConfiguration() {
		return config;
	}

	public AbstractParserFactory getFactory() {
		return factory;
	}
}