001    package org.maltparser.parser.algorithm.nivre;
002    
003    import org.maltparser.core.exception.MaltChainedException;
004    import org.maltparser.core.feature.function.Function;
005    import org.maltparser.parser.AbstractParserFactory;
006    import org.maltparser.parser.Algorithm;
007    import org.maltparser.parser.DependencyParserConfig;
008    import org.maltparser.parser.ParserConfiguration;
009    /**
010     * @author Johan Hall
011     *
012     */
013    public abstract class NivreFactory implements AbstractParserFactory {
014            protected Algorithm algorithm;
015            protected DependencyParserConfig manager;
016            
017            public NivreFactory(Algorithm algorithm) {
018                    setAlgorithm(algorithm);
019                    setManager(algorithm.getManager());
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                    if (manager.getConfigLogger().isInfoEnabled()) {
026                            manager.getConfigLogger().info("  Parser configuration : Nivre with with allow_root="+allowRoot+" and allow_reduce="+allowReduce+"\n");
027                    }
028                    return new NivreConfig(manager.getSymbolTables(), allowRoot, allowReduce);
029            }
030            
031            public Function makeFunction(String subFunctionName) throws MaltChainedException {
032                    return new NivreAddressFunction(subFunctionName, algorithm);
033            }
034    
035            public Algorithm getAlgorithm() {
036                    return algorithm;
037            }
038    
039            public void setAlgorithm(Algorithm algorithm) {
040                    this.algorithm = algorithm;
041            }
042    
043            public DependencyParserConfig getManager() {
044                    return manager;
045            }
046    
047            public void setManager(DependencyParserConfig manager) {
048                    this.manager = manager;
049            }
050    }