    001    package org.maltparser.core.propagation;
    002
    003    import java.io.File;
    004    import java.net.MalformedURLException;
    005    import java.net.URL;
    006
    007    import org.maltparser.core.config.ConfigurationDir;
    008    import org.maltparser.core.exception.MaltChainedException;
    009    import org.maltparser.core.propagation.spec.PropagationSpecs;
    010    import org.maltparser.core.propagation.spec.PropagationSpecsReader;
    011    import org.maltparser.core.syntaxgraph.edge.Edge;
    012
    013    public class PropagationManager {
    014            private ConfigurationDir configDirectory;
    015            private PropagationSpecs propagationSpecs;
    016            private Propagations propagations;
    017
    018            public PropagationManager(ConfigurationDir configDirectory) {
    019                    setConfigDirectory(configDirectory);
    020                    propagationSpecs = new PropagationSpecs();
    021
    022            }
    023
    024            private URL findURL(String propagationSpecFileName) throws MaltChainedException {
    025                    URL url = null;
    026                    File specFile = configDirectory.getFile(propagationSpecFileName);
    027                    if (specFile.exists()) {
    028                            try {
    029                                    url = new URL("file:///"+specFile.getAbsolutePath());
    030                            } catch (MalformedURLException e) {
    031                                    throw new PropagationException("Malformed URL: "+specFile, e);
    032                            }
    033                    } else {
    034                            url = configDirectory.getConfigFileEntryURL(propagationSpecFileName);
    035                    }
    036                    return url;
    037            }
    038
    039            public void loadSpecification(String propagationSpecFileName) throws MaltChainedException {
    040                    PropagationSpecsReader reader = new PropagationSpecsReader();
    041                    reader.load(findURL(propagationSpecFileName), propagationSpecs);
    042                    propagations = new Propagations(propagationSpecs, configDirectory.getInputDataFormatInstance());
    043            }
    044
    045            public void propagate(Edge e) throws MaltChainedException {
    046                    if (propagations != null && e != null) {
    047                            propagations.propagate(e);
    048                    }
    049            }
    050
    051            public PropagationSpecs getPropagationSpecs() {
    052                    return propagationSpecs;
    053            }
    054
    055            public ConfigurationDir getConfigDirectory() {
    056                    return configDirectory;
    057            }
    058
    059            public void setConfigDirectory(ConfigurationDir configDirectory) {
    060                    this.configDirectory = configDirectory;
    061            }
    062
    063            public Propagations getPropagations() {
    064                    return propagations;
    065            }
    066
    067
    068    }