001package org.maltparser.parser.algorithm.nivre;
002
003import org.maltparser.core.exception.MaltChainedException;
004import org.maltparser.core.feature.FeatureRegistry;
005import org.maltparser.core.feature.function.Function;
006import org.maltparser.parser.AbstractParserFactory;
007import org.maltparser.parser.AlgoritmInterface;
008import org.maltparser.parser.DependencyParserConfig;
009import org.maltparser.parser.ParserConfiguration;
010import org.maltparser.parser.ParserRegistry;
011/**
012 * @author Johan Hall
013 *
014 */
015public abstract class NivreFactory implements AbstractParserFactory {
016        protected final DependencyParserConfig manager;
017        
018        public NivreFactory(DependencyParserConfig _manager) {
019                this.manager = _manager;
020        }
021        
022        public ParserConfiguration makeParserConfiguration() throws MaltChainedException {
023                boolean allowRoot = (Boolean)manager.getOptionValue("nivre", "allow_root");
024                boolean allowReduce = (Boolean)manager.getOptionValue("nivre", "allow_reduce");
025                boolean enforceTree = (Boolean)manager.getOptionValue("nivre", "enforce_tree") && manager.getOptionValueString("config", "flowchart").equals("parse");
026                if (manager.isLoggerInfoEnabled()) {
027                        manager.logInfoMessage("  Parser configuration : Nivre with allow_root="+allowRoot+", allow_reduce="+allowReduce+" and enforce_tree="+enforceTree+"\n");
028                }
029                return new NivreConfig(allowRoot, allowReduce, enforceTree);
030        }
031        
032        public Function makeFunction(String subFunctionName, FeatureRegistry registry) throws MaltChainedException {
033                AlgoritmInterface algorithm = ((ParserRegistry)registry).getAlgorithm();
034                return new NivreAddressFunction(subFunctionName, algorithm);
035        }
036}
037
038