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 final AbstractParserFactory factory; 017 private final 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 this.algorithm = algorithm; 030 this.factory = 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 SymbolTableHandler getSymboltables() { 052 return symboltables; 053 } 054 055 protected void setSymboltables(SymbolTableHandler symboltables) { 056 this.symboltables = symboltables; 057 } 058 059 public GuideUserHistory getHistory() { 060 return history; 061 } 062 063 protected void setHistory(GuideUserHistory history) { 064 this.history = history; 065 } 066 067 public TransitionSystem getTransitionSystem() { 068 return transitionSystem; 069 } 070 071 protected void setTransitionSystem(TransitionSystem transitionSystem) { 072 this.transitionSystem = transitionSystem; 073 } 074 075 public HistoryStructure getHistoryStructure() { 076 return historyStructure; 077 } 078 079 protected void setHistoryStructure(HistoryStructure historyStructure) { 080 this.historyStructure = historyStructure; 081 } 082 083 public void initialize(DependencyStructure dependencyStructure) throws MaltChainedException { 084 config.clear(); 085 config.setDependencyGraph(dependencyStructure); 086 config.initialize(null); 087 } 088 089 public boolean isTerminalState() throws MaltChainedException { 090 return config.isTerminalState(); 091 } 092 093 public boolean permissible(GuideUserAction currentAction) throws MaltChainedException { 094 return transitionSystem.permissible(currentAction, config); 095 } 096 097 public void apply(GuideUserAction currentAction) throws MaltChainedException { 098 transitionSystem.apply(currentAction, config); 099 } 100 101 public int nConfigurations() throws MaltChainedException { 102 return 1; 103 } 104 105 public ParserConfiguration getConfiguration() { 106 return config; 107 } 108 109 public AbstractParserFactory getFactory() { 110 return factory; 111 } 112 }