Package org.maltparserx.core.io.dataformat

Source Code of org.maltparserx.core.io.dataformat.DataFormatManager

package org.maltparserx.core.io.dataformat;

import java.net.URL;

import org.maltparserx.core.exception.MaltChainedException;
import org.maltparserx.core.helper.HashMap;
import org.maltparserx.core.helper.URLFinder;
import org.maltparserx.core.io.dataformat.DataFormatSpecification.Dependency;

public class DataFormatManager {
  private DataFormatSpecification inputDataFormatSpec;
  private DataFormatSpecification outputDataFormatSpec;
  private final HashMap<String, DataFormatSpecification> fileNameDataFormatSpecs;
  private final HashMap<String, DataFormatSpecification> nameDataFormatSpecs;
 
  public DataFormatManager(URL inputFormatUrl, URL outputFormatUrl) throws MaltChainedException {
    fileNameDataFormatSpecs = new HashMap<String, DataFormatSpecification>();
    nameDataFormatSpecs = new HashMap<String, DataFormatSpecification>();
    inputDataFormatSpec = loadDataFormat(inputFormatUrl);
    outputDataFormatSpec = loadDataFormat(outputFormatUrl);
  }

  public DataFormatSpecification loadDataFormat(URL dataFormatUrl) throws MaltChainedException {
    if (dataFormatUrl == null) {
      return null;
    }
    DataFormatSpecification dataFormat = fileNameDataFormatSpecs.get(dataFormatUrl.toString());
    if (dataFormat == null) {
      dataFormat = new DataFormatSpecification();
      dataFormat.parseDataFormatXMLfile(dataFormatUrl);
      fileNameDataFormatSpecs.put(dataFormatUrl.toString(), dataFormat);
      nameDataFormatSpecs.put(dataFormat.getDataFormatName(), dataFormat);
      final URLFinder f = new URLFinder();
     
      for (Dependency dep : dataFormat.getDependencies()) {
        loadDataFormat(f.findURLinJars(dep.getUrlString()));
      }
    }
    return dataFormat;
  }
 
  public DataFormatSpecification getInputDataFormatSpec() {
    return inputDataFormatSpec;
  }

  public DataFormatSpecification getOutputDataFormatSpec() {
    return outputDataFormatSpec;
  }
 
  public void setInputDataFormatSpec(DataFormatSpecification inputDataFormatSpec) {
    this.inputDataFormatSpec = inputDataFormatSpec;
  }

  public void setOutputDataFormatSpec(DataFormatSpecification outputDataFormatSpec) {
    this.outputDataFormatSpec = outputDataFormatSpec;
  }

  public DataFormatSpecification getDataFormatSpec(String name) {
    return nameDataFormatSpecs.get(name);
  }
}
TOP

Related Classes of org.maltparserx.core.io.dataformat.DataFormatManager

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.