Package org.maltparserx.parser

Source Code of org.maltparserx.parser.ParserState

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;
  }
}
TOP

Related Classes of org.maltparserx.parser.ParserState

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.