    001    package org.maltparser.parser;
    002
    003    import org.maltparser.core.exception.MaltChainedException;
    004    import org.maltparser.core.symbol.SymbolTableHandler;
    005    import org.maltparser.core.syntaxgraph.DependencyStructure;
    006    import org.maltparser.parser.history.GuideUserHistory;
    007    import org.maltparser.parser.history.History;
    008    import org.maltparser.parser.history.HistoryList;
    009    import org.maltparser.parser.history.HistoryStructure;
    010    import org.maltparser.parser.history.action.GuideUserAction;
    011    /**
    012     * @author Johan Hall
    013     *
    014     */
    015    public class ParserState {
    016            private AbstractParserFactory factory;
    017            private Algorithm algorithm;
    018            private SymbolTableHandler symboltables;
    019            private GuideUserHistory history;
    020            private TransitionSystem transitionSystem;
    021            private HistoryStructure historyStructure;
    022            private ParserConfiguration config;
    023
    024            public ParserState(Algorithm algorithm, AbstractParserFactory factory) throws MaltChainedException {
    025                    this(algorithm, factory, 1);
    026            }
    027
    028            public ParserState(Algorithm algorithm, AbstractParserFactory factory, int k) throws MaltChainedException {
    029                    setAlgorithm(algorithm);
    030                    setFactory(factory);
    031                    setSymboltables(algorithm.getManager().getSymbolTables());
    032                    setHistoryStructure(new HistoryList());
    033                    setTransitionSystem(factory.makeTransitionSystem());
    034                    String decisionSettings = algorithm.getManager().getOptionValue("guide", "decision_settings").toString().trim();
    035                    getTransitionSystem().initTableHandlers(decisionSettings, symboltables);
    036                    setHistory(new History(decisionSettings, algorithm.getManager().getOptionValue("guide", "classitem_separator").toString(), getTransitionSystem().getTableHandlers()));
    037                    getTransitionSystem().initTransitionSystem(history);
    038                    config = getFactory().makeParserConfiguration();
    039            }
    040
    041
    042            public void clear() throws MaltChainedException {
    043                    history.clear();
    044                    historyStructure.clear();
    045            }
    046
    047            public Algorithm getAlgorithm() {
    048                    return algorithm;
    049            }
    050
    051            public void setAlgorithm(Algorithm algorithm) {
    052                    this.algorithm = algorithm;
    053            }
    054
    055            public SymbolTableHandler getSymboltables() {
    056                    return symboltables;
    057            }
    058
    059            protected void setSymboltables(SymbolTableHandler symboltables) {
    060                    this.symboltables = symboltables;
    061            }
    062
    063            public GuideUserHistory getHistory() {
    064                    return history;
    065            }
    066
    067            protected void setHistory(GuideUserHistory history) {
    068                    this.history = history;
    069            }
    070
    071            public TransitionSystem getTransitionSystem() {
    072                    return transitionSystem;
    073            }
    074
    075            protected void setTransitionSystem(TransitionSystem transitionSystem) {
    076                    this.transitionSystem = transitionSystem;
    077            }
    078
    079            public HistoryStructure getHistoryStructure() {
    080                    return historyStructure;
    081            }
    082
    083            protected void setHistoryStructure(HistoryStructure historyStructure) {
    084                    this.historyStructure = historyStructure;
    085            }
    086
    087            public void initialize(DependencyStructure dependencyStructure) throws MaltChainedException {
    088                    config.clear();
    089                    config.setDependencyGraph(dependencyStructure);
    090                    config.initialize(null);
    091            }
    092
    093            public boolean isTerminalState() throws MaltChainedException {
    094                    return config.isTerminalState();
    095            }
    096
    097            public boolean permissible(GuideUserAction currentAction) throws MaltChainedException {
    098                    return transitionSystem.permissible(currentAction, config);
    099            }
    100
    101            public void apply(GuideUserAction currentAction) throws MaltChainedException {
    102                    transitionSystem.apply(currentAction, config);
    103            }
    104
    105            public int nConfigurations() throws MaltChainedException {
    106                    return 1;
    107            }
    108
    109            public ParserConfiguration getConfiguration() {
    110                    return config;
    111            }
    112
    113            public AbstractParserFactory getFactory() {
    114                    return factory;
    115            }
    116
    117            public void setFactory(AbstractParserFactory factory) {
    118                    this.factory = factory;
    119            }
    120    }