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.symbol.SymbolTableHandler; 012 import org.maltparser.core.syntaxgraph.edge.Edge; 013 014 public class PropagationManager { 015 private ConfigurationDir configDirectory; 016 private PropagationSpecs propagationSpecs; 017 private Propagations propagations; 018 private SymbolTableHandler symbolTables; 019 020 public PropagationManager(ConfigurationDir configDirectory, SymbolTableHandler symbolTables) { 021 setConfigDirectory(configDirectory); 022 setSymbolTables(symbolTables); 023 propagationSpecs = new PropagationSpecs(); 024 025 } 026 027 private URL findURL(String propagationSpecFileName) throws MaltChainedException { 028 URL url = null; 029 File specFile = configDirectory.getFile(propagationSpecFileName); 030 if (specFile.exists()) { 031 try { 032 url = new URL("file:///"+specFile.getAbsolutePath()); 033 } catch (MalformedURLException e) { 034 throw new PropagationException("Malformed URL: "+specFile, e); 035 } 036 } else { 037 url = configDirectory.getConfigFileEntryURL(propagationSpecFileName); 038 } 039 return url; 040 } 041 042 public void loadSpecification(String propagationSpecFileName) throws MaltChainedException { 043 PropagationSpecsReader reader = new PropagationSpecsReader(); 044 reader.load(findURL(propagationSpecFileName), propagationSpecs); 045 propagations = new Propagations(propagationSpecs, symbolTables); 046 } 047 048 public void propagate(Edge e) throws MaltChainedException { 049 if (propagations != null && e != null) { 050 propagations.propagate(e); 051 } 052 } 053 054 public PropagationSpecs getPropagationSpecs() { 055 return propagationSpecs; 056 } 057 058 public ConfigurationDir getConfigDirectory() { 059 return configDirectory; 060 } 061 062 public void setConfigDirectory(ConfigurationDir configDirectory) { 063 this.configDirectory = configDirectory; 064 } 065 066 public SymbolTableHandler getSymbolTables() { 067 return symbolTables; 068 } 069 070 public void setSymbolTables(SymbolTableHandler symbolTables) { 071 this.symbolTables = symbolTables; 072 } 073 074 public Propagations getPropagations() { 075 return propagations; 076 } 077 078 079 }