All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.maltparserx.parser.ParserState Maven / Gradle / Ivy

package org.maltparserx.parser;

import org.maltparserx.core.exception.MaltChainedException;
import org.maltparserx.core.symbol.SymbolTableHandler;
import org.maltparserx.core.syntaxgraph.DependencyStructure;
import org.maltparserx.parser.history.GuideUserHistory;
import org.maltparserx.parser.history.History;
import org.maltparserx.parser.history.HistoryList;
import org.maltparserx.parser.history.HistoryStructure;
import org.maltparserx.parser.history.action.GuideUserAction;
/**
 * @author Johan Hall
 *
 */
public class ParserState {
	private final AbstractParserFactory factory;
	private final Algorithm algorithm;
	private SymbolTableHandler symboltables;
	private GuideUserHistory history;
	private TransitionSystem transitionSystem;
	private HistoryStructure historyStructure;
	private ParserConfiguration config;
	
	public ParserState(Algorithm algorithm, AbstractParserFactory factory) throws MaltChainedException {
		this(algorithm, factory, 1);
	}
	
	public ParserState(Algorithm algorithm, AbstractParserFactory factory, int k) throws MaltChainedException {
		this.algorithm = algorithm;
		this.factory = factory;
		setSymboltables(algorithm.getManager().getSymbolTables());
		setHistoryStructure(new HistoryList());
		setTransitionSystem(factory.makeTransitionSystem());
		String decisionSettings = algorithm.getManager().getOptionValue("guide", "decision_settings").toString().trim();
		getTransitionSystem().initTableHandlers(decisionSettings, symboltables);
		setHistory(new History(decisionSettings, algorithm.getManager().getOptionValue("guide", "classitem_separator").toString(), getTransitionSystem().getTableHandlers()));
		getTransitionSystem().initTransitionSystem(history);
		config = getFactory().makeParserConfiguration();
	}
	
	
	public void clear() throws MaltChainedException {
		history.clear();
		historyStructure.clear();
	}
	
	public Algorithm getAlgorithm() {
		return algorithm;
	}

	public SymbolTableHandler getSymboltables() {
		return symboltables;
	}

	protected void setSymboltables(SymbolTableHandler symboltables) {
		this.symboltables = symboltables;
	}
	
	public GuideUserHistory getHistory() {
		return history;
	}

	protected void setHistory(GuideUserHistory history) {
		this.history = history;
	}

	public TransitionSystem getTransitionSystem() {
		return transitionSystem;
	}

	protected void setTransitionSystem(TransitionSystem transitionSystem) {
		this.transitionSystem = transitionSystem;
	}
	
	public HistoryStructure getHistoryStructure() {
		return historyStructure;
	}

	protected void setHistoryStructure(HistoryStructure historyStructure) {
		this.historyStructure = historyStructure;
	}
	
	public void initialize(DependencyStructure dependencyStructure) throws MaltChainedException {
		config.clear();
		config.setDependencyGraph(dependencyStructure);
		config.initialize(null);
	}
	
	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;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy