* {@inheritDoc}
*/
@Override
protected void loadHMMPool(boolean useCDUnits, InputStream inputStream, String path)
throws IOException {
ExtendedStreamTokenizer est = new ExtendedStreamTokenizer(inputStream, '#', false);
logger.info("Loading HMM file from: ");
logger.info(path);
est.expectString(MODEL_VERSION);
int numBase = est.getInt("numBase");
est.expectString("n_base");
int numTri = est.getInt("numTri");
est.expectString("n_tri");
est.getInt("numStateMap");
est.expectString("n_state_map");
int numTiedState = est.getInt("numTiedState");
est.expectString("n_tied_state");
int numContextIndependentTiedState = est.getInt("numContextIndependentTiedState");
est.expectString("n_tied_ci_state");
int numTiedTransitionMatrices = est.getInt("numTiedTransitionMatrices");
est.expectString("n_tied_tmat");
int[] maxStid = new int[maxModelSize];
HMMManager hmmManager = super.getHmmManager();
Pool<float[][]> matrixPool = super.getMatrixPool();
Pool<float[]> mixtureWeightsPool = super.getMixtureWeightsPool();
Map<String, Unit> contextIndependentUnits = super.getContextIndependentUnits();
assert numTiedState == mixtureWeightsPool.getFeature(NUM_SENONES, 0);
assert numTiedTransitionMatrices == matrixPool.size();
// Load the base phones
for (int i = 0; i < numBase; i++) {
String left = est.getString();
String right = est.getString();
String position = est.getString();
int tmat = est.getInt("tmat");
// Read all state ID in the line...
for (int j = 0; ; j++) {
String str = est.getString();
// ... until we reach a "N"
if (!str.equals("N")) {
int id = Integer.parseInt(str);
try {
maxStid[j] = id;
} catch (ArrayIndexOutOfBoundsException aie) {
throw new Error("Use a larger value for " +
"maxStatePerModel");
}
assert maxStid[j] >= 0 &&
maxStid[j] < numContextIndependentTiedState;
} else {
break;
}
}
assert left.equals("-");
assert right.equals("-");
assert position.equals("-");
assert tmat < numTiedTransitionMatrices;
// int[] stid = Arrays.copyOf(maxStid, numStates);
// Unit unit = Unit.getUnit(name, attribute.equals(FILLER));
// contextIndependentUnits.put(unit.getName(), unit);
//
// if (logger.isLoggable(Level.FINE)) {
// logger.fine("Loaded " + unit);
// }
// The first filler
// if (unit.isFiller() && unit.getName().equals(SILENCE_CIPHONE)) {
// unit = Unit.SILENCE;
// }
// float[][] transitionMatrix = matrixPool.get(tmat);
// SenoneSequence ss = getSenoneSequence(stid);
// HMM hmm = new SenoneHMM(unit, ss, transitionMatrix, HMMPosition.lookup(position));
// hmmManager.put(hmm);
}
// Load the context dependent phones. If the useCDUnits
// property is false, the CD phones will not be created, but
// the values still need to be read in from the file.
String lastUnitName = "";
Unit lastUnit = null;
int[] lastStid = null;
SenoneSequence lastSenoneSequence = null;
for (int i = 0; i < numTri; i++) {
String name = est.getString();
String left = est.getString();
String right = est.getString();
String position = est.getString();
String attribute = est.getString();
int tmat = est.getInt("tmat");
int numStates = 0;
// Read all state ID in the line...
for (int j = 0; ; j++) {
String str = est.getString();
// ... until we reach a "N"
if (!str.equals("N")) {
int id = Integer.parseInt(str);
maxStid[j] = id;
assert maxStid[j] >= numContextIndependentTiedState &&
maxStid[j] < numTiedState;
} else {
numStates = j;
break;
}
}
int[] stid = Arrays.copyOf(maxStid, numStates);
assert !left.equals("-");
assert !right.equals("-");
assert !position.equals("-");
assert attribute.equals("n/a");
assert tmat < numTiedTransitionMatrices;
if (useCDUnits) {
Unit unit = null;
String unitName = (name + ' ' + left + ' ' + right);
if (unitName.equals(lastUnitName)) {
unit = lastUnit;
} else {
Unit[] leftContext = new Unit[1];
leftContext[0] = contextIndependentUnits.get(left);
Unit[] rightContext = new Unit[1];
rightContext[0] = contextIndependentUnits.get(right);
//Context context = LeftRightContext.get(leftContext, rightContext);
//unit = Unit.getUnit(name, false, context);
}
lastUnitName = unitName;
lastUnit = unit;
if (logger.isLoggable(Level.FINE)) {
logger.fine("Loaded " + unit);
}
float[][] transitionMatrix = matrixPool.get(tmat);
SenoneSequence ss = lastSenoneSequence;
if (ss == null || !sameSenoneSequence(stid, lastStid)) {
ss = getSenoneSequence(stid);
}
lastSenoneSequence = ss;
lastStid = stid;
HMM hmm = new SenoneHMM(unit, ss, transitionMatrix, HMMPosition.lookup(position));
hmmManager.put(hmm);
}
}
est.close();
}