*/
}
/**
<<<<<<< HEAD
=======
* Retained to maintain backward compatibility Uses the lm lines in the Joshua config file which
* are not defined as feature functions to create new LMs
*
* @param args
* @throws IOException
*/
private void initializeLanguageModels() throws IOException {
if (joshuaConfiguration.lms.size() > 0) {
Decoder.LOG(1, "You seem to be using an old version of the Joshua config file");
Decoder.LOG(1, "Language models should be defined as regular feature functions.");
// Only initialize if necessary
if (this.languageModels == null) {
this.languageModels = new ArrayList();
}
// lm = kenlm 5 0 0 100 file
for (String lmLine : joshuaConfiguration.lms) {
String[] tokens = lmLine.trim().split("\\s+");
HashMap argMap = new HashMap();
argMap.put("lm_type", tokens[0]);
argMap.put("lm_order", tokens[1]);
argMap.put("minimizing", tokens[2]);
argMap.put("lm_file", tokens[5]);
initializeLanguageModel(argMap);
}
}
}
/**
* Initializes a language model and adds it as a feature
*
* @param argMap A map of arguments supplied top the lm feature function throught the Joshua
* config file
* @throws IOException
private void initializeLanguageModel(HashMap argMap) throws IOException {
if (this.languageModels == null) {
this.languageModels = new ArrayList();
}
String lm_type = argMap.get("lm_type");
int lm_order = Integer.parseInt(argMap.get("lm_order"));
boolean minimizing = Boolean.parseBoolean(argMap.get("minimizing"));
String lm_file = argMap.get("lm_file");
if (lm_type.equals("kenlm")) {
KenLM lm = new KenLM(lm_order, lm_file, minimizing);
this.languageModels.add(lm);
Vocabulary.registerLanguageModel(lm);
Vocabulary.id(joshuaConfiguration.default_non_terminal);
if (argMap.containsKey("lm_class") && argMap.containsKey("class_map")) {
// This is a Class LM
addLMFeature(lm, true, argMap.get("class_map"));
}
else {
addLMFeature(lm, false, null);
}
} else if (lm_type.equals("berkeleylm")) {
LMGrammarBerkeley lm = new LMGrammarBerkeley(lm_order, lm_file);
this.languageModels.add(lm);
Vocabulary.registerLanguageModel(lm);
Vocabulary.id(joshuaConfiguration.default_non_terminal);
addLMFeature(lm, false, null);
} else if (lm_type.equals("none")) {
; // do nothing
} else {
Decoder.LOG(1, "WARNING: using built-in language model; you probably didn't intend this");
Decoder.LOG(1, "Valid lm types are 'kenlm', 'berkeleylm', 'none'");
}
}
private void addLMFeature(NGramLanguageModel lm, boolean isClass, String classFile)
throws IOException {
if (lm instanceof KenLM && lm.isMinimizing()) {
KenLMFF newFeatureFunction = new KenLMFF(weights, (KenLM) lm, joshuaConfiguration, isClass);
newFeatureFunction.setClassMap(classFile);
this.featureFunctions.add(newFeatureFunction);
} else {
this.featureFunctions.add(new LanguageModelFF(weights, lm, joshuaConfiguration, false));
}
}
/**
>>>>>>> 3e38f504a22b9ef9a9f68301b6daf2cbd6da07db
* Initializes translation grammars Retained for backward compatibility
*
* @param ownersSeen Records which PhraseModelFF's have been instantiated (one is needed for each |