protected void loadDataFromYaml(File configFile) throws IOException {
String configFileName = configFile.getAbsolutePath();
String gazbinFileName = configFileName.replaceAll("\\.defyaml$", ".gazbin");
if(configFileName.equals(gazbinFileName)) {
throw new GateRuntimeException("Config file must have def or defyaml extension");
}
File gazbinFile = new File(gazbinFileName);
String gazbinDir = gazbinFile.getParent();
String gazbinName = gazbinFile.getName();
// Always read the yaml file so we can get any special location of the cache
// file or figure out that we should not try to load the cache file
Yaml yaml = new Yaml();
BufferedReader yamlReader =
new BomStrippingInputStreamReader((configFileURL).openStream(), encoding);
Object configObject = yaml.load(yamlReader);
List<Map> configListFiles = null;
if(configObject instanceof Map) {
Map<String,Object> configMap = (Map<String,Object>)configObject;
String configCacheDirName = (String)configMap.get("cacheDir");
if(configCacheDirName != null) {
gazbinDir = configCacheDirName;
}
String configCacheFileName = (String)configMap.get("chacheFile");
if(configCacheFileName != null) {
gazbinName = configCacheFileName;
}
gazbinFile = new File(new File(gazbinDir),gazbinName);
Integer configBackendNr = (Integer)configMap.get("backendNr");
if(configBackendNr != null) {
backendNr = configBackendNr;
}
configListFiles = (List<Map>)configMap.get("listFiles");
} else if(configObject instanceof List) {
configListFiles = (List<Map>)configObject;
} else {
throw new GateRuntimeException("Strange YAML format for the defyaml file "+configFileURL);
}
// if we want to load the cache and it exists, load it
if(backendNr == 3 && useCache && gazbinFile.exists()) {
gazStore = new GazStoreTrie3();
gazStore = gazStore.load(gazbinFile);
} else {
// otherwise process the files listed in the yaml file
if(backendNr == 1) {
gazStore = new GazStoreTrie1();
} else if (backendNr == 2) {
gazStore = new GazStoreTrie2();
} else if (backendNr == 3) {
gazStore = new GazStoreTrie3();
} else {
throw new GateRuntimeException("Invalid backend number: "+backendNr);
}
// go through all the list and tsv files to load and load them
for(Map configListFile : configListFiles) {
// TODO!!!